Error pressing Alt + Tab using pyHook

1

I'm working on a python script that captures user-entered keys. For that, I used the pyHook module. However, using the program, I noticed that every time the user presses Alt + Tab, an error occurs. The simplified version that synthesizes the part of my program in which the error occurs is as follows:

import pyHook,pythoncom
def teclado(event):
    print(event.Key)
    return True

hm=pyHook.HookManager()
hm.KeyDown=teclado
hm.HookKeyboard()
pythoncom.PumpMessages()

The code shows perfectly all the keys typed, however, pressing Alt + Tab causes the following error:

TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'

And the program closes. How can I avoid this error by preserving the Alt + Tab function in windows?

    
asked by anonymous 19.12.2016 / 23:26

1 answer

0

This is an error in the pyHook script itself. One solution to this problem is to install a modified pyHook here . To install, you need to download Swig here .

Installation:

  • Open cmd
  • Drop your current pyHook with the command: pip uninstall pyHook
  • From the cmd, browse to the downloaded pyHook extracted folder (pyhook_py3k-master)
  • Type the command: python setup.py build_ext --swig = path-to-swig.exe
  • After success, type: pip install.
  • Note: path-to-swig.exe is the path to the swig.exe file, found inside the folder downloaded by the Swig website.

        
    18.01.2017 / 19:49