summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-05-30 19:39:25 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-05-30 19:39:25 +0100
commit7b501c6e1404226d8ed65c020088cf5d9cfd4552 (patch)
tree43a2439fcfa9eb04f87d53d1d9b20fe20108786f
parent0ee02ee1541da7cbd876b3167c8432fa885c47c2 (diff)
downloadkeyboard-python-7b501c6e1404226d8ed65c020088cf5d9cfd4552.tar.bz2
let KeyCombination take key as string
This makes the tables much neater
-rw-r--r--keyboardpython/key.py84
1 files changed, 44 insertions, 40 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index c4b7a2d..9205852 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -18,8 +18,12 @@ class KeyCombination:
''' multiple keyboard keys pressed in unison '''
def __init__(self,*keys):
- for k in keys:
- assert isinstance(k,Key)
+ keys = list(keys)
+ for i,k in enumerate(keys):
+ if type(k) is str:
+ keys[i] = Key(k)
+ else:
+ assert isinstance(k,Key)
self.keys = list(set(keys))
self.keys.sort(key=lambda x: x.name)
@@ -107,46 +111,46 @@ _special_chars = {
Backspace: Key('Backspace'),
}
_escape_brace_codes = {
- 'A': KeyCombination(Key('Up')),
- 'B': KeyCombination(Key('Down')),
- 'D': KeyCombination(Key('Left')),
- 'C': KeyCombination(Key('Right')),
- '3~': KeyCombination(Key('Del')),
- '2~': KeyCombination(Key('Insert')),
- '5~': KeyCombination(Key('PageUp')),
- '6~': KeyCombination(Key('PageDown')),
- '15~': KeyCombination(Key('F5')),
- '17~': KeyCombination(Key('F6')),
- '18~': KeyCombination(Key('F7')),
- '19~': KeyCombination(Key('F8')),
- '20~': KeyCombination(Key('F9')),
- '21~': KeyCombination(Key('F10')),
- '23~': KeyCombination(Key('F11')),
- '24~': KeyCombination(Key('F12')),
- '3;3~': KeyCombination(Key('Del'),ALT),
- '2;3~': KeyCombination(Key('Insert'),ALT),
- '5;3~': KeyCombination(Key('PageUp'),ALT),
- '6;3~': KeyCombination(Key('PageDown'),ALT),
- '15;3~': KeyCombination(Key('F5'),ALT),
- '17;3~': KeyCombination(Key('F6'),ALT),
- '18;3~': KeyCombination(Key('F7'),ALT),
- '19;3~': KeyCombination(Key('F8'),ALT),
- '20;3~': KeyCombination(Key('F9'),ALT),
- '21;3~': KeyCombination(Key('F10'),ALT),
- '23;3~': KeyCombination(Key('F11'),ALT),
- '24;3~': KeyCombination(Key('F12'),ALT),
+ 'A': KeyCombination('Up'),
+ 'B': KeyCombination('Down'),
+ 'D': KeyCombination('Left'),
+ 'C': KeyCombination('Right'),
+ '3~': KeyCombination('Del'),
+ '2~': KeyCombination('Insert'),
+ '5~': KeyCombination('PageUp'),
+ '6~': KeyCombination('PageDown'),
+ '15~': KeyCombination('F5'),
+ '17~': KeyCombination('F6'),
+ '18~': KeyCombination('F7'),
+ '19~': KeyCombination('F8'),
+ '20~': KeyCombination('F9'),
+ '21~': KeyCombination('F10'),
+ '23~': KeyCombination('F11'),
+ '24~': KeyCombination('F12'),
+ '3;3~': KeyCombination('Del',ALT),
+ '2;3~': KeyCombination('Insert',ALT),
+ '5;3~': KeyCombination('PageUp',ALT),
+ '6;3~': KeyCombination('PageDown',ALT),
+ '15;3~': KeyCombination('F5',ALT),
+ '17;3~': KeyCombination('F6',ALT),
+ '18;3~': KeyCombination('F7',ALT),
+ '19;3~': KeyCombination('F8',ALT),
+ '20;3~': KeyCombination('F9',ALT),
+ '21;3~': KeyCombination('F10',ALT),
+ '23;3~': KeyCombination('F11',ALT),
+ '24;3~': KeyCombination('F12',ALT),
}
_escape_O_codes = {
- 'F': KeyCombination(Key('End')),
- 'H': KeyCombination(Key('Home')),
- 'P': KeyCombination(Key('F1')),
- 'Q': KeyCombination(Key('F2')),
- 'R': KeyCombination(Key('F3')),
- 'S': KeyCombination(Key('F4')),
- '1;3P': KeyCombination(Key('F1'),ALT),
- '1;3Q': KeyCombination(Key('F2'),ALT),
- '1;3R': KeyCombination(Key('F3'),ALT),
- '1;3S': KeyCombination(Key('F4'),ALT),
+ 'F': KeyCombination('End'),
+ 'H': KeyCombination('Home'),
+ 'P': KeyCombination('F1'),
+ 'Q': KeyCombination('F2'),
+ 'R': KeyCombination('F3'),
+ 'S': KeyCombination('F4'),
+ '1;3P': KeyCombination('F1',ALT),
+ '1;3Q': KeyCombination('F2',ALT),
+ '1;3R': KeyCombination('F3',ALT),
+ '1;3S': KeyCombination('F4',ALT),
}
def _is_alt(code):