-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListener.py
54 lines (46 loc) · 1.4 KB
/
Listener.py
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
import pyHook
import pythoncom
import time
class Listener(object):
def beforeafter(self):
after = time.time() - self.before
self.before = time.time()
return after
def onClick(self,event):
return self.genericAction(event)
def onKeyboardEvent(self,event):
return self.genericAction(event)
def genericAction(self,event):
button = None
if hasattr(event, "Ascii"):
button = event.Ascii
if button == 27:
self.go = False
return False
elif hasattr(event, "Position"):
value = "left"
if "right" in event.MessageName:
value = "right"
button = (value, event.Position)
after = self.beforeafter()
self.actionList.append({button:after})
return True
def listen(self):
self.go = True
self.actionList = []
hm = pyHook.HookManager()
hm.SubscribeMouseAllButtonsDown(self.onClick)
hm.KeyDown = self.onKeyboardEvent
hm.HookMouse()
hm.HookKeyboard()
self.before = time.time()
while self.go:
pythoncom.PumpWaitingMessages()
hm.UnhookMouse()
hm.UnhookKeyboard()
return self.actionList
# "This is the end my friend"
def main(self):
print self.listen()
if __name__ == "__main__":
Listener.main(Listener())