I am writing a python script that has an infinite loop and for me to stop I use the usual Keyboard Interrupt key Ctrl+c but I was wondering if I can set one of my own like by pressing space once the program can stop I want it to have the same function as Ctrl+c So if it is possible how can I assign it?
from pynput.keyboard import Listener
while True:
if keyboard.is_pressed("space"):
exit()