check if back is pressed python 1

check if back is pressed python

import keyboard
while true:
    try:
        if keyboard.is_pressed('s'):
            print("stop")
        elif keyboard.is_pressed('p'):
            print("pause")
    except:
        pass

Here is what the above code is Doing:
1. It’s creating a while loop that will run forever.
2. It’s checking if the ‘s’ key is pressed.
3. If the ‘s’ key is pressed, it will print “stop”.
4. If the ‘s’ key is not pressed, it will check if the ‘p’ key is pressed.
5. If the ‘p’ key is pressed, it will print “pause”.
6. If the ‘p’ key is not pressed, it will do nothing.
7. If there is an error, it will do nothing.

Similar Posts