0

i want a getch/cin like function in python that wont interrupt the program from running (wanna make flappyBird) return pressed key ascii code if anything pressed or returns nothing or a default value if no key pressed

i am using getch but it waits till a key press

while (1):
    speed = speed - gravity
    pressed_key = getch.getch()
    if ( pressed_key == ' ' ):
        speed = speed + force
        pressed_key = 'x'
    elif ( pressed_key == 'q' ):
        sys.exit()
    print (speed)
    sleep(sleep_time)

this will be later a frame of the game xD

Akbar30bill
  • 354
  • 3
  • 11
  • Here you have an excelent post: [https://stackoverflow.com/questions/13207678/whats-the-simplest-way-of-detecting-keyboard-input-in-python-from-the-terminal?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa](https://stackoverflow.com/questions/13207678/whats-the-simplest-way-of-detecting-keyboard-input-in-python-from-the-terminal?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Joaquim De la Cruz Jun 10 '18 at 19:32
  • This may be the answer you need: https://rosettacode.org/wiki/Keyboard_input/Keypress_check#Python – gammazero Jun 10 '18 at 19:50
  • Possible duplicate of [What's the simplest way of detecting keyboard input in python from the terminal?](https://stackoverflow.com/questions/13207678/whats-the-simplest-way-of-detecting-keyboard-input-in-python-from-the-terminal) – AJNeufeld Jun 11 '18 at 14:16
  • @AJNeufeld the tutorial is just for windows ( probably unix part was not clear ) – Akbar30bill Jun 11 '18 at 20:05

0 Answers0