get_keystroke.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 class GetKeyStroke:
00004     """
00005     Gets a single character from standard input.  Does not echo to the screen.
00006 
00007     Original code was taken from 
00008     http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user
00009     Original author: Yuval Adam
00010     """
00011     def __init__(self):
00012         try:
00013             self.impl = _GetchWindows()
00014         except ImportError:
00015             self.impl = _GetchUnix()
00016 
00017     def __call__(self): 
00018         return self.impl()
00019 
00020 class _GetchUnix:
00021     def __init__(self):
00022         import tty, sys
00023 
00024     def __call__(self):
00025         import sys, tty, termios
00026         fd = sys.stdin.fileno()
00027         old_settings = termios.tcgetattr(fd)
00028         try:
00029             tty.setraw(sys.stdin.fileno())
00030             ch = sys.stdin.read(1)
00031         finally:
00032             termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
00033         return ch
00034 
00035 class _GetchWindows:
00036     def __init__(self):
00037         import msvcrt
00038 
00039     def __call__(self):
00040         import msvcrt
00041         return msvcrt.getch()


iri_common_smach
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 21:05:19