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: an integer is required
第三个电话,好的。在
第四次通话
TypeError: an integer is required.
等等等等。在
传递的最后两个参数允许函数正常运行。我还不知道为什么,我想知道这是为什么,但至少现在它正在工作。 在
return True
事件函数返回true非常重要。在
从评论中复制答案,以便从“未回答”筛选器中删除此问题:
~回答人Junkah
相关问题 更多 >
编程相关推荐