-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhooker.py
44 lines (36 loc) · 940 Bytes
/
hooker.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
#! python2
#coding=utf-8
import pyHook
import pythoncom
import multiprocessing
import const
def keydown(event):
keyqueue.put([True,event.Key])
return True
def keyup(event):
keyqueue.put([False,event.Key])
return True
def mousebtn(event):
try:
mousequeue.put(const.mouse_evt_name[event.MessageName])
except KeyError:
print 'unrecognized mouse event:',event.MessageName
finally:
return True
def mousewheel(event):
mousequeue.put([event.Wheel<0,-1])
return True
def run_forever(kq,mq):
global keyqueue,mousequeue
keyqueue=kq
mousequeue=mq
hm=pyHook.HookManager()
hm.SubscribeKeyDown(keydown)
hm.SubscribeKeyUp(keyup)
hm.SubscribeMouseAllButtonsDown(mousebtn)
hm.SubscribeMouseAllButtonsUp(mousebtn)
hm.SubscribeMouseWheel(mousewheel)
hm.HookKeyboard()
hm.HookMouse()
print 'hook start'
pythoncom.PumpMessages()