From 36094c15cf49d0a210a817c6d2f729d99fdc9c3a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 15 Feb 2011 20:25:32 +0100 Subject: [PATCH] Keyboard can now read all shortcuts with Ctrl (e.g Ctrl+left) Any unicode character is accepted after the meta key The meta key can be concatened until a non-meta key is pressed (e.g M-M-M-M-M-M-M-M-e) --- src/keyboard.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/keyboard.py b/src/keyboard.py index 09652c4c..188e65eb 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -50,10 +50,12 @@ def read_char(s): if first <= 26: # transform Ctrl+* keys return "^"+chr(first + 64) if first == 27: - (first, c) = get_next_byte(s) - if not isinstance(first, int): - return None - return "M-"+chr(first) + second = read_char(s) + res = 'M-%s' % (second,) + if second == '[': + for i in range(4): + res += read_char(s) + return res if 194 <= first: (code, c) = get_next_byte(s) # 2 bytes char char += c @@ -71,6 +73,10 @@ def read_char(s): if __name__ == '__main__': import curses s = curses.initscr() + curses.curs_set(1) + curses.noecho() + curses.nonl() + s.keypad(True) curses.noecho() while True: s.addstr('%s\n' % read_char(s))