![]() |
Looping through functions - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Looping through functions (/thread-14754.html) |
Looping through functions - WantedStarling - Dec-15-2018 Hello, I have this code: import pythoncom, pyHook import msvcrt def main(): keyLogging(False) # call with False parameter means no old hooks to clean up pythoncom.PumpMessages() def keyLogging(cleanup): hm = pyHook.HookManager() # if you called this function before, uninstall old hook before installing new one! if cleanup: hm.UnhookKeyboard() key = msvcrt.getwche() # ask user for new hook as you did originaly # in the if block, only select what hook you want, clean up redundant code! if key == 'z': hm.KeyDown = test elif key == 'v': hm.KeyDown = test2 hm.HookKeyboard() # finally, install the new hook def test(event): key = msvcrt.getwche() if key == 'x': print("Worked") keyLogging(True) # call with True parameter means old hook needs cleanup def test2(): key = msvcrt.getwche() if key == 'x': print("Worked again") keyLogging(True) main()I am trying to make it do, is to call functions without stopping. When I run it I want to press a key and call either test or test2 and after I press again a key it will return back to keylogging to wait for a new option, something like an infinite loop that every time I will choose which function to call. With this code I get this error: It works for just one time but after going in the function it throws this error. As you can see I gave as an option z to call test function and then x to return back to keylogging but throwed this error.As a solution I found this around the internet: Quote:I found the solution. If you open HookManager.py and change all 'key_hook' words to 'keyboard_hook' no more error occurs I tried it, it doesn't give me this error but after going back to keylogging program doesn't accept any more inputs but no error is shown. Any answer would be appreciated. Thank you for your time |