abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
getch.py
Go to the documentation of this file.
1 
2 class _Getch:
3  """Gets a single character from standard input. Does not echo to the screen."""
4  def __init__(self):
5  try:
6  self.impl = _GetchWindows()
7  except ImportError:
8  self.impl = _GetchUnix()
9 
10  def __call__(self): return self.impl()
11 
12 
13 class _GetchUnix:
14  def __init__(self):
15  import tty, sys
16 
17  def __call__(self):
18  import sys, tty, termios
19  fd = sys.stdin.fileno()
20  old_settings = termios.tcgetattr(fd)
21  try:
22  tty.setraw(sys.stdin.fileno())
23  ch = sys.stdin.read(1)
24  finally:
25  termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
26  return ch
27 
28 
30  def __init__(self):
31  import msvcrt
32 
33  def __call__(self):
34  import msvcrt
35  return msvcrt.getch()
36 
37 getch = _Getch()
def __init__
Definition: getch.py:14
def __call__
Definition: getch.py:10
def __call__
Definition: getch.py:17
def __init__
Definition: getch.py:4