summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-06-04 23:08:38 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-06-04 23:17:35 +0100
commite2c88ef0809376ecad840d41a7fb948bc1f18d58 (patch)
tree31f2579d7ee483c9a8b0b277886562e04e186235
parenta6024dc7c0c7793ba96c177f228b504704ad200d (diff)
downloadkeyboard-python-e2c88ef0809376ecad840d41a7fb948bc1f18d58.tar.bz2
Allow table formatter to parse Ctrl and Shift
-rw-r--r--keyboardpython/key.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index 6837044..1104945 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -103,17 +103,29 @@ class Key:
# define modifier Keys
ALT = Key('Alt')
CTRL = Key('Control')
+SHIFT = Key('Shift')
def _format_key_dict(in_dict):
+ ''' take the human readable table and format it for the parser '''
import copy
to_return = {}
for pair in in_dict.items():
for code in pair[1]:
- if 'Alt' in pair[0]: base = KeyCombination(ALT)
- else: base = KeyCombination()
- to_add = KeyCombination(pair[0])
- combination = copy.deepcopy(base)
- combination.add_keyCombination(to_add)
+ combination = KeyCombination()
+ comb_name = copy.copy(pair[0])
+ comb_name = comb_name.split()
+ if 'Alt' in comb_name:
+ comb_name.pop(comb_name.index('Alt'))
+ combination.add_key(ALT)
+ if 'Ctrl' in comb_name:
+ comb_name.pop(comb_name.index('Ctrl'))
+ combination.add_key(CTRL)
+ if 'Shift' in comb_name:
+ comb_name.pop(comb_name.index('Shift'))
+ combination.add_key(SHIFT)
+ assert len(comb_name) == 1, "unrecognised key given in %s" % pair[0]
+ to_add = Key(comb_name[0])
+ combination.add_key(to_add)
to_return[code] = combination
return to_return