zoukankan      html  css  js  c++  java
  • python监听鼠标和键盘

    import PyHook3
    
    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('---')
    
      # return True to pass the event to other handlers
      # return False to stop the event from propagating
      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 to pass the event to other handlers
      # return False to stop the event from propagating
      return True
    
    # create the hook mananger
    hm = PyHook3.HookManager()
    # register two callbacks
    hm.MouseAllButtonsDown = OnMouseEvent
    hm.KeyDown = OnKeyboardEvent
    
    # hook into the mouse and keyboard events
    hm.HookMouse()
    hm.HookKeyboard()
    
    if __name__ == '__main__':
      import pythoncom
      pythoncom.PumpMessages()
  • 相关阅读:
    Springboot 中AOP的使用
    ElasticSearch 聚合查询百分比
    ElasticSearch 入门
    elasticsearch 关联查询
    spring data elasticsearch多索引查询
    elasticsearch 拼音+ik分词,spring data elasticsearch 拼音分词
    es同步mysql同步-logstash
    jpa Specification复杂查询
    java Spring boot使用spring反射
    BeautifulSoup学习记录
  • 原文地址:https://www.cnblogs.com/gig886/p/7141853.html
Copyright © 2011-2022 走看看