Note that there are some explanatory texts on larger screens.

plurals
  1. POPython win32api.mouse_event TypeError
    text
    copied!<pre><code>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() </code></pre> <p>The function CursorLeft works fine every other time. It also works fine without any negative numbers as parameters. I am completely lost as to why this is happening!</p> <p>First call, fine.</p> <p>Second call,</p> <blockquote> <p>TypeError: an integer is required</p> </blockquote> <p>Third call, fine.</p> <p>Fourth call,</p> <blockquote> <p>TypeError: an integer is required.</p> </blockquote> <p>so on and so on.</p> <p><br><br><br> <hr> <strike></p> <h2>Solved</h2> <pre><code>win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, -1, 0, 0, 0) </code></pre> <p>The last two parameters passed allow the function to behave properly. I am still not sure as to why and would <strong>still like to know</strong> but at least <strong>it is working now</strong>. </strike></p> <h2>Solved</h2> <pre><code>return True </code></pre> <p>Very important that the event functions return true.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload