summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboardpython/__init__.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/keyboardpython/__init__.py b/keyboardpython/__init__.py
index 3e42f08..216f08d 100644
--- a/keyboardpython/__init__.py
+++ b/keyboardpython/__init__.py
@@ -4,12 +4,20 @@ def set_to_read_key(fd='default'):
''' Set tty so that os.read gets one keypress at a time '''
import sys,termios
if fd == 'default': fd = sys.stdin.fileno()
+ global before_tty
+ before_tty = termios.tcgetattr(fd)
tty = termios.tcgetattr(fd)
tty[3] = tty[3] & ~termios.ICANON & ~termios.ECHO
tty[6][termios.VMIN] = 1
tty[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, tty)
+def reset_tty(fd='default'):
+ ''' set tty to how it was before set_to_read_key '''
+ import sys,termios
+ if fd == 'default': fd = sys.stdin.fileno()
+ termios.tcsetattr(fd, termios.TCSANOW, before_tty)
+
def getkey(fd='default',buffersize=6):
''' Read keypress and return Key object.