当前位置:   article > 正文

python监控键盘鼠标_python检测鼠标滚轮

python检测鼠标滚轮
  1. # -*- coding: utf-8 -*-
  2. import pythoncom
  3. import pyHook
  4. import time
  5. def onMouseEvent(event):
  6. "处理鼠标事件"
  7. fobj.writelines('-' * 20 + 'MouseEvent Begin' + '-' * 20 + '\n')
  8. fobj.writelines("Current Time:%s\n" % time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
  9. fobj.writelines("MessageName:%s\n" % str(event.MessageName))
  10. fobj.writelines("Message:%d\n" % event.Message)
  11. fobj.writelines("Time_sec:%d\n" % event.Time)
  12. fobj.writelines("Window:%s\n" % str(event.Window))
  13. fobj.writelines("WindowName:%s\n" % str(event.WindowName))
  14. fobj.writelines("Position:%s\n" % str(event.Position))
  15. fobj.writelines('-' * 20 + 'MouseEvent End' + '-' * 20 + '\n')
  16. return True
  17. def onKeyboardEvent(event):
  18. "处理键盘事件"
  19. fobj.writelines('-' * 20 + 'Keyboard Begin' + '-' * 20 + '\n')
  20. fobj.writelines("Current Time:%s\n" % time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
  21. fobj.writelines("MessageName:%s\n" % str(event.MessageName))
  22. fobj.writelines("Message:%d\n" % event.Message)
  23. fobj.writelines("Time:%d\n" % event.Time)
  24. fobj.writelines("Window:%s\n" % str(event.Window))
  25. fobj.writelines("WindowName:%s\n" % str(event.WindowName))
  26. fobj.writelines("Ascii_code: %d\n" % event.Ascii)
  27. fobj.writelines("Ascii_char:%s\n" % chr(event.Ascii))
  28. fobj.writelines("Key:%s\n" % str(event.Key))
  29. fobj.writelines('-' * 20 + 'Keyboard End' + '-' * 20 + '\n')
  30. return True
  31. #打开日志文件
  32. file_name = "E:\\hook_log.txt"
  33. fobj = open(file_name, 'w')
  34. #创建hook句柄
  35. hm = pyHook.HookManager()
  36. #监控键盘
  37. hm.KeyDown = onKeyboardEvent
  38. hm.HookKeyboard()
  39. #监控鼠标
  40. hm.MouseAll = onMouseEvent
  41. hm.HookMouse()
  42. #循环获取消息
  43. pythoncom.PumpMessages()
  44. #关闭日志文件
  45. fobj.close()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/839552
推荐阅读
相关标签
  

闽ICP备14008679号