1.准备做鼠标和键盘监控,在网上找资料安装了额pyhook(whl包),然后发现有bug
2.准备安装pyhook3,然后各种swig,c++运行库等,劝退了
3安装步骤:
a.根据python版本下载对应的whl包:
?https://www.lfd.uci.edu/~gohlke/pythonlibs/
b.pip 安装whl包
c.运行测试脚本
import pyWinhook
import pythoncom
class KeyBoardManager():
keyIsPressed = False
def onKeyDown(self,event):
if self.keyIsPressed:
return True
print (str(event.Key) + ' is pressed')
self.keyIsPressed = True
return True
def onKeyUp(self,event):
self.keyIsPressed = False
print (str(event.Key) + ' is released')
return True
def mouseup(self,event):
print("mouse up",event)
return True
def mousedown(self,event):
print("mouse down",event)
return True
if __name__ == '__main__':
mykbmanager = KeyBoardManager()
hookmanager = pyWinhook.HookManager()
hookmanager.KeyDown = mykbmanager.onKeyDown
hookmanager.KeyUp = mykbmanager.onKeyUp
hookmanager.MouseLeftUp = mykbmanager.mouseup
hookmanager.MouseLeftDown = mykbmanager.mousedown
hookmanager.HookKeyboard()
hookmanager.HookMouse()
pythoncom.PumpMessages()
?没有bug,运行丝滑,也不用安装什么swig,什么C++运行库。
就这样!
|