Python win32api.mouse_event TypeError

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() 

The CursorLeft function works great every time. It also works great without any negative numbers as parameters. I completely lost why this is happening!

First call, great.

Second challenge

TypeError: integer required

Third call, fine.

Fourth call

TypeError: integer required.

so on and so forth





solvable

 win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, -1, 0, 0, 0) 

The last two parameters passed allow the function to function correctly. I'm still not sure why and would still like to know , but at least now it works . Strike>

solvable

 return True 

It is very important that event functions return true.

+4
source share
1 answer

Copy the answer from the comments to remove this question from the "No Answer" filter:

return True

It is very important that event functions return true.

~ answer per Junkah

0
source

All Articles