• PyHook3典型代码


    from ctypes import *
    import PyHook3 as pyHook
    import pythoncom



    def onKeyboardEvent1(event): print("onKeyboardEvent") pid = c_ulong(0) windowTitle = create_string_buffer(512) windll.user32.GetWindowTextA(event.Window, byref(windowTitle), 512) windll.user32.GetWindowThreadProcessId(event.Window, byref(pid)) windowName = windowTitle.value.decode('gbk') print("当前您处于%s窗口" % windowName) print("当前窗口所属进程id %d" % pid.value) print("当前刚刚按下了{}键, ascii值为{}, KeyID = {}, ScanCode = {}".format(chr(event.Ascii), str(event.Ascii), event.KeyID, event.ScanCode)) 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("---------") #返回 True 以便将事件传给其它处理程序, 这儿如果返回 False ,则事件将被全部拦截 return True 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 hm = pyHook.HookManager() #hm.KeyDown = onKeyboardEvent #hm.HookKeyboard() #hm.MouseAllButtons = onMouseEvent hm.MouseWheel = onMouseEvent hm.HookMouse() pythoncom.PumpMessages()

      

  • 相关阅读:
    透过WebGL 3D看动画Easing函数本质
    vmware虚拟机Windows 2003上网问题
    JAVA多态学习2
    h5播放音乐
    Unity3D:粒子系统Particle System
    文章标题
    【面试加分项】java自己定义注解之申明注解
    osgi实战学习之路:1. ant+bnd+felix搭建osgi之HelloWorld
    Android简单实现Socket通信,client连接server后,server向client发送文字数据
    句子开头
  • 原文地址:https://www.cnblogs.com/hushaojun/p/16547028.html
Copyright © 2020-2023  润新知