zoukankan      html  css  js  c++  java
  • python hook监听事件

    python hook监听事件

    作者:vpoet

    日期:夏季

    # -*- coding: utf-8 -*- # 
    # by oldj http://oldj.net/ #
    import pythoncom 
    import pyHook    
    def onMouseEvent(event): 
       # 监听鼠标事件     
       print "MessageName:",event.MessageName     
       print "Message:", event.Message     
       print "Time:", event.Time     
       print "Window:", event.Window     
       print "WindowName:", event.WindowName     
       print "Position:", event.Position     
       print "Wheel:", event.Wheel     
       print "Injected:", event.Injected           
       print"---"
      
       # 返回 True 以便将事件传给其他处理程序     
       # 注意。这儿假设返回 False ,则鼠标事件将被全部拦截     
       # 也就是说你的鼠标看起来会僵在那儿。似乎失去响应了     
       return True
     
    def onKeyboardEvent(event):
      # 监听键盘事件     
       print "MessageName:", event.MessageName     
       print "Message:", event.Message     
       print "Time:", event.Time     
       print "Window:", event.Window     
       print "WindowName:", event.WindowName     
       print "Ascii:", event.Ascii, chr(event.Ascii)     
       print "Key:", event.Key     
       print "KeyID:", event.KeyID     
       print "ScanCode:", event.ScanCode     
       print "Extended:", event.Extended     
       print "Injected:", event.Injected     
       print "Alt", event.Alt     
       print "Transition", event.Transition     
       print "---"      
       # 同鼠标事件监听函数的返回值     
       return True 
    
    def main():     
       # 创建一个“钩子”管理对象     
       hm = pyHook.HookManager()      
       # 监听全部键盘事件     
       hm.KeyDown = onKeyboardEvent     
       # 设置键盘“钩子”     
       hm.HookKeyboard()      
       # 监听全部鼠标事件     
       hm.MouseAll = onMouseEvent     
       # 设置鼠标“钩子”     
       hm.HookMouse()      
       # 进入循环。如不手动关闭,程序将一直处于监听状态     
       pythoncom.PumpMessages() 
    
    if __name__ == "__main__":     
       main()
    



    执行截图:



  • 相关阅读:
    (原创)xcode4的workspace里各lib工程与app工程联编之runscript简介
    使用textmate
    (转)DebuggingTechniques
    (转)ObjectiveC的单例模式(singleton)
    VIA = Via Inner Action
    Das Vergessmichnicht
    Resume
    Explore Subdivide Surface Algorithm Of Maya
    为什么我的文章总是没人回复
    Summer Dream Für Meines Leben
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/7242972.html
Copyright © 2011-2022 走看看