Hotkey creating using keyboard library

47 views Asked by At

So i am currently running a pyautogui script that has an autoclicker, and i wanted to implement a hotkey that when pressed, will stop the code no matter if vsc is opened or closed, how can I do that using Keyboard library

1

There are 1 answers

0
5rod On

It's pretty simple:

import keyboard
import sys

keyboard.add_hotkey('s', lambda: sys.exit()) #adds hotkey so that whenever you press the key s, the program exits