summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-06-07 14:01:09 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-06-07 14:01:09 +0100
commit499d575b42ce94a4d8f39fa6b5895b3b7c3daa30 (patch)
treec5032070fa5a62aa42866cef55932c751ef284b3
parentc90d8291194fb80a55c822554f67fb45ba6fc13f (diff)
downloadkeyboard-python-499d575b42ce94a4d8f39fa6b5895b3b7c3daa30.tar.bz2
Add some explanation to functions in __init__
-rw-r--r--keyboardpython/__init__.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/keyboardpython/__init__.py b/keyboardpython/__init__.py
index 8d230bf..92907cd 100644
--- a/keyboardpython/__init__.py
+++ b/keyboardpython/__init__.py
@@ -14,6 +14,7 @@ def get_repeat():
return repeat_delay,repeat_rate
def echo(on=True):
+ ''' set whether or not keypresses are echoed in terminal '''
import sys,termios
fd = sys.stdin.fileno()
t = termios.tcgetattr(fd)
@@ -22,9 +23,11 @@ def echo(on=True):
termios.tcsetattr(fd, termios.TCSANOW, t)
def noecho():
+ ''' set echoing keypresses in terminal off '''
echo(False)
def cbreak(on=True):
+ ''' set whether or not enter must be pressed for keypresses to be read '''
import sys,termios
fd = sys.stdin.fileno()
t = termios.tcgetattr(fd)
@@ -33,6 +36,7 @@ def cbreak(on=True):
termios.tcsetattr(fd, termios.TCSANOW, t)
def nocbreak():
+ ''' set so enter must be pressed before keypresses are read '''
cbreak(False)
def init(fd='default'):
@@ -63,16 +67,20 @@ def getkey(fd='default',timeout=49,buffersize=6):
''' Read keypress and return Key object.
- fd='default' will try and get this stdin.
- - timeout in miliseconds
+ - timeout is the time listening for escape codes
+ if this is not done sometimes multiple keypress escape codes
+ are read as sequential keypresses
- buffersize is passed to os.read, 6 is
- enough for alt+F12 for example.
+ enough for alt+F12 for example.
'''
import os,sys,time,termios
if fd == 'default': fd = sys.stdin.fileno()
to_return = str()
- timeout = float(timeout) / 1000
+ # read raw keypress from OS
c = os.read(fd,buffersize)
+ # if escape code wait for timeout
if key.ESC not in c: return key.parse_code(c)
+ timeout = float(timeout) / 1000
t = termios.tcgetattr(fd)
cc = t[-1]
cc[termios.VMIN] = 0