找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3756|回复: 0

试问下坛子里python高人,帮如何capture鼠标点击event

1

主题

1

帖子

5

积分

贫民

积分
5
qweasdyxc 发表于 2014-1-8 06:24:48 | 显示全部楼层 |阅读模式
试问下坛子里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)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表