1
I am working on a python script that captures keystrokes typed by the user. For this, I used the pyHook module. However, using the program, I realized 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 perfectly shows all keystrokes typed, but when pressing Alt+Tab, the following error occurs:
TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'
And the program ends. How can I avoid this error by preserving the Alt+Tab function in windows?
I don’t know Pyhook. But looking at Stackoverflow in English I found information that could be an error directly in the original code. The existing answer suggests a possible solution involving modifying and recompiling Pyhook: http://stackoverflow.com/questions/26156633/pythoncom-crashes-on-keydown-when-used-hooked-to-certain-applications
– Luiz Vieira
I read everything, but I don’t understand what the guy proposed. However, I visited related links and discovered this link: https://github.com/Answeror/pyhook_py3k. In it, there is a supposed fix to the problem of pyHook. Only I couldn’t install because I don’t know what the "path-to-swig.exe" part of the installation is. If you figure out how to install, you can add a response with this link teaching you to install. If it works, I accept. @
– Benedito
About Swig: http://www.swig.org/. I’m sorry, mate, but I’m not in a position to pursue that. Besides, this installation difficulty would be another question, if it was part of the scope of the site (software installation is not part of the scope here - try on [su]).
– Luiz Vieira
I didn’t know that Swig was software. As you told me, I downloaded it and managed to install pyHook fixed. I tested and the problem disappeared. Thank you for your time. @Uiz
– Benedito
Ah, for nothing. : ) In this case, create yourself an answer.
– Luiz Vieira