Skip to content Skip to sidebar Skip to footer

Msvcrt.kbhit() Always Returns False . Unable To Detect Escape Key

I tried if (msvcrt.getch() == chr(27).encode()), it didn't work The msrcvt.getch() in my program always prints to b'\xff' in the debug-print statement. It simply didn't detects the

Solution 1:

Try: if msvcrt.getch()==b'\x1b'

Ex:

import msvcrt
whileTrue:
    if msvcrt.kbhit():
        key_stroke = msvcrt.getch()
        if key_stroke==b'\x1b':
            print ("Esc key pressed")
        else:
            print (str(key_stroke).split("'")[1],"key pressed")

Post a Comment for "Msvcrt.kbhit() Always Returns False . Unable To Detect Escape Key"