summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-05-29 00:39:17 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-05-29 00:41:49 +0100
commit4478cee575a8d637489238466f86b6792a16ae3f (patch)
treeb2713af77c7a134b55b361ab748f1fdf360d42ed
parent9cde71b2dd45bd8f30991c03927adac47b2cd6e1 (diff)
downloadkeyboard-python-4478cee575a8d637489238466f86b6792a16ae3f.tar.bz2
Add reset_tty to reset set_to_read_key
-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.