|
试问下坛子里python高人,帮如何capture鼠标点击event
最近碰到个小问题, 想capture global mouse event(win系统下)
用python 的ctype 写了下面的一小段,可以监听到键盘的 global key event了, 例子中 监听到键盘的ALT+F10,触发执行相应程序(hallo world),
原本以为把 ALT + F10的值换成鼠标中键的值(0x020A, 0x0001)就可以监听鼠标中键的点击event,以用来触发执行相应程序, 程序执行后, 系统反馈信息
显示键值(0x020A, 0x0001) 已经成功register了,没有任何错误信息, 但鼠标中键点击没任何反应...弄了半天也没搞懂,还请python高人指点一二.
谢谢!
PS 搜了下网上的说法都是要用python的,hook模块由于条件限制,不能调用这个模块,只能用python的ctype死磕...
import ctypes as cy
from ctypes.wintypes import MSG
def handle_win_f10 ():
print "hallo world"
def set_mouse_key():
byref = cy.byref
user32 = cy.windll.user32
WM_HOTKEY = 0x0312
HOTKEYS = {
1 : (121, 0x0001), #alt + F10
#1 : (0x020A, 0x0001), #alt + MWU
}
HOTKEY_ACTIONS = {
1 : handle_win_f10,
}
for id, (vk, modifiers) in HOTKEYS.items ():
if not user32.RegisterHotKey (None, id, modifiers, vk):
print "system key confliction,unable to register :", id, "\n"
try:
msg = MSG ()
while user32.GetMessageA (byref (msg), None, 0, 0) != 0:
if msg.message == WM_HOTKEY:
action_to_take = HOTKEY_ACTIONS.get (msg.wParam)
if action_to_take:
action_to_take ()
user32.TranslateMessage (byref (msg))
user32.DispatchMessageA (byref (msg))
finally:
for id in HOTKEYS.keys ():
user32.UnregisterHotKey (None, id) |
|