pyHook及evnent的可用属性

pyHook安装:

pyHook采用pip install pyHook的方式暂无法安装成功,需官网下载.whl文件,然后手动安装。
下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook。打开该地址后会看到多个版本的.whl文件,如pyhook-1.5.1-cp37-cp37m-win_amd64.whl。cp37代表python版本,64代表64位操作系统,选择合适自己的版本。下载完成后,在.whl所以的文件夹下,在控制台输入 pip install XXX.whl即可安装成功。

pip install pyHook-1.5.1-cp37-cp37m-win_amd64.whl
Processing c:\users\administrator\downloads\pyhook-1.5.1-cp37-cp37m-win_amd64.whl
Installing collected packages: pyHook
Successfully installed pyHook-1.5.1

注:如果安装失败,说明下载的.whl版本不对。可通过以下方法检查。

python -V //查看python版本
>>> import platform
>>> platform.architecture()
('64bit', 'WindowsPE')  //查看32,还是64

键盘事件对象

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 “—”

示例

猜你喜欢

转载自blog.csdn.net/weixin_42129248/article/details/89682462
今日推荐