Skip to content

Instantly share code, notes, and snippets.

@cvubrugier
Created April 22, 2015 13:15
Show Gist options
  • Select an option

  • Save cvubrugier/2868ab3bc66e9ba5cc14 to your computer and use it in GitHub Desktop.

Select an option

Save cvubrugier/2868ab3bc66e9ba5cc14 to your computer and use it in GitHub Desktop.

Revisions

  1. Christophe Vu-Brugier created this gist Apr 22, 2015.
    21 changes: 21 additions & 0 deletions keypress.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/usr/bin/python

    from __future__ import print_function
    import sys
    import termios
    import tty


    def main():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
    tty.setraw(sys.stdin.fileno())
    r = sys.stdin.read(5)
    finally:
    termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    print('r = %r' % r)


    if __name__ == '__main__':
    main()