import sys
import win32api, win32con
import pyHook
import pythoncom
def CursorLeft():
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, -1, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
def Quit():
print "Quitting"
sys.exit()
# create a keyboard hook
def OnKeyboardEvent(event):
print 'MessageName:', event.MessageName
print 'Key:', event.Key
if event.Key in ['Numpad2']:
CursorLeft()
elif event.Key in ['End']:
Quit()
return True
def OnMouseEvent(event):
print 'Position:', event.Position
return True
hm = pyHook.HookManager()
hm.MouseAll = OnMouseEvent
hm.HookMouse()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
CursorLeft函数每隔一段时间都能正常工作。它也可以正常工作,没有任何负数作为参数。我完全不知道为什么会发生这种情况!
第一次打电话,很好。
第二次电话,
TypeError:需要一个整数
第三次电话,很好。
第四次电话,
等等等等。TypeError:需要一个整数。
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, -1, 0, 0, 0)
传递的最后两个参数允许函数正常运行。我仍然不确定为什么,仍然想知道,但至少它现在正在运作。
击>
return True
非常重要的是事件函数返回true。