0

Beginner in Python here. I'd like the option to pause at a line of code and wait for ANY button to be pressed (not just enter) and immediately continue to a new line.

I've looked everywhere online and all I can see is:

input('Press ENTER to continue...')

which is NOT what I want to do.

I'd like a line that says:

Press any key to continue...

and if i press solely the 'f' key (for example) then it proceeds to a new line.

Thanks.

MoonChild
  • 1
  • 2

1 Answers1

0

Python has a keyboard module. Install using:

pip install keyboard

The code you should use for the 'f' key is:

import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('f'):  # if key 'f' is pressed 
            print('You Pressed A Key!')
            break  # finishing the loop
    except:
        break  # if user pressed a key other than the given key the loop will break

Source question

Itamar Cohen
  • 340
  • 4
  • 15