Terminate a process when hotkey is pressed - 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: Terminate a process when hotkey is pressed (/thread-23361.html) |
Terminate a process when hotkey is pressed - 66Gramms - Dec-24-2019 Hello All! I want to make a simple program running in the background which when detects a certain hotkey being pressed, it terminates the currently focused window. I found 2 packages to do this and I thought I was able to do so with a few lines of code but I always get the same error and I can't see why, I believe it has to do something with the hotkey method in line 10. My code: import pygetwindow as gw import keyboard as kb def closeWindow(): focused = gw.getActiveWindow() title = focused.title() focused.close() print(title + " was closed") kb.add_hotkey('alt+f4', closeWindow) while True: continueThe errors I get all the time the momment i press the hotkey: Thank you for the help in advance!
|