diff options
author | William Holland <william.holland@codethink.co.uk> | 2015-06-04 22:07:22 +0100 |
---|---|---|
committer | William Holland <william.holland@codethink.co.uk> | 2015-06-04 22:08:07 +0100 |
commit | 0ecac2eeb897c9e4bf7913c964e1c8ce643ec629 (patch) | |
tree | 04986353f72ed9e0f301ce62040adb4185f75a55 /keyboardpython | |
parent | 7736e787807beeed3500ab411da11cedb0452b23 (diff) | |
download | keyboard-python-0ecac2eeb897c9e4bf7913c964e1c8ce643ec629.tar.bz2 |
Use new table when parsing
Diffstat (limited to 'keyboardpython')
-rw-r--r-- | keyboardpython/key.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py index 92ece3c..074becf 100644 --- a/keyboardpython/key.py +++ b/keyboardpython/key.py @@ -181,7 +181,8 @@ def _is_alt(code): def _is_ctrl_alpha(code): ''' is this the code of a combination modified by Ctrl? ''' _assert_type(code,str) - if code in _special_chars.keys(): return False + import key_codes + if code in key_codes.key_codes: return False elif code < '\x20': return True else: return False @@ -201,7 +202,9 @@ def _match_start_in_table(_code,table): ''' import re code_str = ''.join(_code) - for c in table.keys(): + for c in table: + c = c.replace('[','\[') + c = c.replace('^','\^') match = re.search('^%s' % c,code_str) if match: key_comb = table.get(match.string) @@ -213,26 +216,30 @@ def _match_start_in_table(_code,table): def parse_code(code): ''' get KeyCombination object from code ''' _assert_type(code,str) + import key_codes + key_codes_table = _format_key_dict(key_codes.key_codes) to_return = KeyCombination() _code = list(code) while _code: char = _code.pop(0) if char == ESC: if not _code: - return _special_chars[ESC] + return key_codes_table[ESC] char = _code.pop(0) if char == '[': - _code, key_comb = _match_start_in_table(_code, - _escape_brace_codes) + _code, key_comb = _match_start_in_table(['^[','[']+_code, + key_codes_table) if not key_comb: key_comb = KeyCombination('[',ALT) elif char == 'O': - _code, key_comb = _match_start_in_table(_code, - _escape_O_codes) + _code, key_comb = _match_start_in_table(['^[','O']+_code, + key_codes_table) if not key_comb: key_comb = KeyCombination('O',ALT) else: key_comb = KeyCombination(char,ALT) - elif char in _special_chars: - key_comb = _special_chars[char] elif _is_ctrl_alpha(char): key_comb = _get_ctrl_alpha(char) - else: key_comb = KeyCombination(char) + else: + try: + key_comb = key_codes_table[char] + except: + key_comb = KeyCombination(char) to_return.add_keyCombination(key_comb) return to_return |