#1 TypeError in Switch function

open
nobody
None
5
2015-10-21
2010-04-12
Anonymous
No

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

Discussion

  • Matt Shaw

    Matt Shaw - 2010-08-08

    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

     
  • Matt Shaw

    Matt Shaw - 2010-08-08

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

     
  • nanotube

    nanotube - 2010-08-12

    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?

     
  • Nobody/Anonymous

    I can verify that when I got the error that "echo type(msg)" printed "<type 'int'>" and "echo msg" printed 256

     
  • Matt Shaw

    Matt Shaw - 2010-08-12

    And by echo I mean print.

     
  • nanotube

    nanotube - 2010-08-12

    hmm real weird...
    also, what if you do just int(msg) instead of int(str(msg)) - does that work?

     
  • Matt Shaw

    Matt Shaw - 2010-08-12

    Still throws the error if I try:

    func = self.keyboard_funcs.get( int(msg) )

     
  • nanotube

    nanotube - 2010-08-15

    Wow... bizarre...

     
  • Nobody/Anonymous

    come up with same issue.
    Windows 7 , 64

     
  • Zv_oDD

    Zv_oDD - 2014-02-26

    Same here on Win 7 x64

     
  • Stefano Borzoni

    Stefano Borzoni - 2015-10-21

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

    This fixed the bug for me, thanks Matt Shaw :P

     
    Last edit: Stefano Borzoni 2015-10-21

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks