""" KBHIT-test.py Shlomo Solomon program to demonstrate the use of kbhit and getch in LINUX """ import KBHIT kbd = KBHIT.KBHit() # define a keyboard object def get_input(): """ use kbhit and getch to get keyboard input """ key_code = 0 key_char = None if kbd.kbhit(): print "hit ", key_char = kbd.getch() key_code = ord(key_char) if key_code == KBHIT.ENTER: print "ENTER" elif key_code == KBHIT.TAB: print "TAB" elif key_code == KBHIT.BACKSPACE: print "BACKSPACE" elif key_code == KBHIT.ESC: print "ESCAPE" else: print key_char, "code=", key_code return key_code, key_char def main(): """ main runs until Escape is hit """ print "Starting test program - waiting for input" print "Hit ESC to end the test" key_code = 0 while key_code != KBHIT.ESC: key_code, key_char = get_input() print "End of test" if __name__ == "__main__": main()