keypress = False
while True:
if keypress and not keyboard.is_pressed('print screen'):
keypress = False
elif keyboard.is_pressed(key) and not keypress:
keypress = True
print(keyboard.read_key())
I want to use this code in a function something like below
keypress = False
def detect_key():
if keypress and not keyboard.is_pressed('print screen'):
keypress = False
elif keyboard.is_pressed(key) and not keypress:
keypress = True
return keyboard.read_key()
In my case I will be calling "detect_key()" function in another file where this function will be in a while loop so whenever the 'print screen' button is pressed this function should return the key string I want to print the key only once I press and release they but on long press. So now the issue is I want to declare the '
keypress
' as a global variable but I'm not able to because even if I declare it will be overrided any suggestions please ?