summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-05-30 18:47:03 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-05-30 18:47:03 +0100
commit11c6b4f8c36374e822dd055aa40d80b969a97f9c (patch)
tree29edea3292ff503f433842630b2dd7366c331f8f
parent3d45e42de2b4a8523dba29cb50b50feaa2941e0f (diff)
downloadkeyboard-python-11c6b4f8c36374e822dd055aa40d80b969a97f9c.tar.bz2
Make O codes use regex
This means all the codes can be put in the table and none are hidden
-rw-r--r--keyboardpython/key.py37
1 files changed, 20 insertions, 17 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index 0b6c36e..f952a56 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -125,12 +125,16 @@ _escape_brace_codes = {
'24~': Key('F12'),
}
_escape_O_codes = {
- 'F': Key('End'),
- 'H': Key('Home'),
- 'P': Key('F1'),
- 'Q': Key('F2'),
- 'R': Key('F3'),
- 'S': Key('F4'),
+ '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),
}
def _is_alt(code):
@@ -193,18 +197,17 @@ def parse_code(code):
_code = _code[len_match+2:]
break
elif _code[0] == 'O':
+ import re
_code.pop(0)
- char = _code.pop(0)
- # TODO HACK - remove
- if len(_code) > 1 and char == '1':
- # alt F1 - alt F4, alt Del and alt Insert
- key = _escape_O_codes[_code[3]]
- to_return.add_key(key)
- to_return.add_key(ALT)
- _code = _code[4:]
- else:
- key = _escape_O_codes[char]
- to_return.add_key(key)
+ code_str = ''.join(_code)
+ for c in _escape_O_codes.keys():
+ match = re.search('^%s' % c,code_str)
+ if match:
+ key_comb = _escape_O_codes[match.string]
+ to_return.add_keyCombination(key_comb)
+ len_match = len(match.string)
+ _code = _code[len_match:]
+ break
else:
to_return.add_key(ALT)
elif char.isalnum():