summaryrefslogtreecommitdiff
path: root/keyboardpython
diff options
context:
space:
mode:
authorWilliam Holland <william.holland@codethink.co.uk>2015-05-30 17:59:53 +0100
committerWilliam Holland <william.holland@codethink.co.uk>2015-05-30 18:01:46 +0100
commit8b05054950e269926f8394bd34a0a75617443635 (patch)
treeb54ac1793cdfac5b21d947096502aaa8432e7005 /keyboardpython
parente858e965416118f3917d1e65d3ef400f1bad7a3e (diff)
downloadkeyboard-python-8b05054950e269926f8394bd34a0a75617443635.tar.bz2
Remove obsolete methods from Key and add __hash__
Diffstat (limited to 'keyboardpython')
-rw-r--r--keyboardpython/key.py61
1 files changed, 6 insertions, 55 deletions
diff --git a/keyboardpython/key.py b/keyboardpython/key.py
index 2254602..43ab98c 100644
--- a/keyboardpython/key.py
+++ b/keyboardpython/key.py
@@ -75,74 +75,26 @@ class KeyCombination:
class Key:
''' a keyboard keypress object '''
- def __init__(self,name,*modifiers):
+ def __init__(self,name):
_assert_type(name,str)
- for m in modifiers:
- assert isinstance(m,Key), "Modifiers expected to be instances of Key"
self.name = name
- self.modifiers = list(modifiers)
- self.modifiers.sort()
def __eq__(self,other):
if not isinstance(other,Key): return False
return str(self) == str(other)
def __ne__(self,other):
- if isinstance(other,Key): return True
- return str(self) != str(other)
-
- def __str__(self):
- to_return = str()
- for m in self.modifiers:
- to_return += '%s ' % str(m)
- to_return += self.name
- return to_return
+ return not self.__eq__(self,other)
- def has_modifier(self,modifier):
- ''' does this object have the modifier? '''
- if modifier in self.modifiers:
- return True
- return False
+ def __hash__(self):
+ return hash(str(self))
- def modify(self,modifier):
- ''' add a modifier '''
- if modifier not in self.modifiers:
- self.modifiers.append(modifier)
- self.modifiers.sort()
- return self
+ def __str__(self):
+ return self.name
ALT = Key('Alt')
CTRL = Key('Control')
-_table = {
- ESC : Key('Escape'),
- '\t': Key('Tab'),
- ' ': Key('Space'),
- '\n': Key('Enter'),
- '\x7f' : Key('Backspace'),
- '%sOF' % ESC: Key('End'),
- '%sOH' % ESC: Key('Home'),
- '%s[3~' % ESC: Key('Del'),
- '%s[2~' % ESC: Key('Insert'),
- '%s[5~' % ESC: Key('PageUp'),
- '%s[6~' % ESC: Key('PageDown'),
- '%sOP' % ESC: Key('F1'),
- '%sOQ' % ESC: Key('F2'),
- '%sOR' % ESC: Key('F3'),
- '%sOS' % ESC: Key('F4'),
- '%s[15~' % ESC: Key('F5'),
- '%s[17~' % ESC: Key('F6'),
- '%s[18~' % ESC: Key('F7'),
- '%s[19~' % ESC: Key('F8'),
- '%s[20~' % ESC: Key('F9'),
- '%s[21~' % ESC: Key('F10'),
- '%s[23~' % ESC: Key('F11'),
- '%s[24~' % ESC: Key('F12'),
- '%s[A' % ESC: Key('Up'),
- '%s[B' % ESC: Key('Down'),
- '%s[D' % ESC: Key('Left'),
- '%s[C' % ESC: Key('Right'),
- }
_special_chars = {
' ': Key('Space'),
ESC : Key('Escape'),
@@ -214,7 +166,6 @@ def parse_code(code):
while _code:
if _code[0] == ESC:
if len(_code) == 1:
- # TODO call getkey and add esc
key = _special_chars[ESC]
to_return.add_key(key)
_code.pop(0)