Skip to content

Instantly share code, notes, and snippets.

@jasonrdsouza
Created February 24, 2012 15:54
Show Gist options
  • Select an option

  • Save jasonrdsouza/1901709 to your computer and use it in GitHub Desktop.

Select an option

Save jasonrdsouza/1901709 to your computer and use it in GitHub Desktop.

Revisions

  1. jasonrdsouza created this gist Feb 24, 2012.
    15 changes: 15 additions & 0 deletions key_detect.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    def getchar():
    #Returns a single character from standard input
    import tty, termios, sys
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
    tty.setraw(sys.stdin.fileno())
    ch = sys.stdin.read(1)
    finally:
    termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

    while 1:
    ch = getchar()
    print 'You pressed', ch