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)
This commit is contained in:
Florent Le Coz 2011-02-15 20:25:32 +01:00
parent 690d449560
commit 36094c15cf

View file

@ -50,10 +50,12 @@ def read_char(s):
if first <= 26: # transform Ctrl+* keys if first <= 26: # transform Ctrl+* keys
return "^"+chr(first + 64) return "^"+chr(first + 64)
if first == 27: if first == 27:
(first, c) = get_next_byte(s) second = read_char(s)
if not isinstance(first, int): res = 'M-%s' % (second,)
return None if second == '[':
return "M-"+chr(first) for i in range(4):
res += read_char(s)
return res
if 194 <= first: if 194 <= first:
(code, c) = get_next_byte(s) # 2 bytes char (code, c) = get_next_byte(s) # 2 bytes char
char += c char += c
@ -71,6 +73,10 @@ def read_char(s):
if __name__ == '__main__': if __name__ == '__main__':
import curses import curses
s = curses.initscr() s = curses.initscr()
curses.curs_set(1)
curses.noecho()
curses.nonl()
s.keypad(True)
curses.noecho() curses.noecho()
while True: while True:
s.addstr('%s\n' % read_char(s)) s.addstr('%s\n' % read_char(s))