When I have the Keyboard hooked, I notice that every other time I hit the ALT key I get this error:
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\pyHook\HookManager.py", line 351, in KeyboardSwitch
func = self.keyboard_funcs.get(msg)
TypeError: an integer is required
The same goes for the MouseSwitch function every other time I click the left mouse button (and I am only hooking MouseLeftDown):
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\pyHook\HookManager.py", line 324, in MouseSwitch
func = self.mouse_funcs.get(msg)
TypeError: an integer is required
I do not have this problem when I monitor KeyDown but I do have it when I monitor KeyUp. I'm on Vista x64.
Python2.6.2\lib\site-packages\pyHook\HookManager.py:350: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
func = self.keyboard_funcs.get(msg)
Traceback (most recent call last):
File "...\Python2.6.2\lib\site-packages\pyHook\HookManager.py", line 3
50, in KeyboardSwitch
func = self.keyboard_funcs.get(msg)
TypeError: an integer is required
msg is definitely an int according to type() but it's still throwing this error. My hunch is that the int is 64-bit, but this is a bit over my head. My hack was to change line 349 in HookManager:
func = self.keyboard_funcs.get(msg)
to:
func = self.keyboard_funcs.get( int(str(msg)) )
Hmm interesting... could be a 64bit only thing...
Out of curiosity... could you mod it to print out the type/content of msg and run it for a while, and verify that it is indeed an int, even in the instances where this error is thrown?
I can verify that when I got the error that "echo type(msg)" printed "<type 'int'>" and "echo msg" printed 256
And by echo I mean print.
hmm real weird...
also, what if you do just int(msg) instead of int(str(msg)) - does that work?
Still throws the error if I try:
func = self.keyboard_funcs.get( int(msg) )
Wow... bizarre...
come up with same issue.
Windows 7 , 64
Same here on Win 7 x64
This fixed the bug for me, thanks Matt Shaw :P
Last edit: Stefano Borzoni 2015-10-21