Add keyutils.is_modifier_key()

This commit is contained in:
Florian Bruhin 2018-02-28 12:52:19 +01:00
parent 1cd86d79d9
commit e26eaaddc2
2 changed files with 12 additions and 18 deletions

View File

@ -128,20 +128,10 @@ class BaseKeyParser(QObject):
txt = str(keyutils.KeyInfo.from_event(e))
self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt))
if not txt:
self._debug_log("Ignoring, no text char")
if keyutils.is_modifier_key(key):
self._debug_log("Ignoring, only modifier")
return QKeySequence.NoMatch
# if len(txt) == 1:
# category = unicodedata.category(txt)
# is_control_char = (category == 'Cc')
# else:
# is_control_char = False
# if (not txt) or is_control_char:
# self._debug_log("Ignoring, no text char")
# return QKeySequence.NoMatch
if (txt.isdigit() and self._supports_count and not
(not self._count and txt == '0')):
assert len(txt) == 1, txt

View File

@ -34,6 +34,14 @@ def is_printable(key):
return key <= 0xff
def is_modifier_key(key):
# FIXME docs
return key in (Qt.Key_Control, Qt.Key_Alt, Qt.Key_Shift, Qt.Key_Meta,
Qt.Key_AltGr, Qt.Key_Super_L, Qt.Key_Super_R,
Qt.Key_Hyper_L, Qt.Key_Hyper_R, Qt.Key_Direction_L,
Qt.Key_Direction_R)
def _key_to_string(key):
"""Convert a Qt::Key member to a meaningful name.
@ -216,13 +224,9 @@ class KeyInfo:
(Qt.ShiftModifier, 'Shift'),
])
modifier_keys = (Qt.Key_Control, Qt.Key_Alt, Qt.Key_Shift, Qt.Key_Meta,
Qt.Key_AltGr, Qt.Key_Super_L, Qt.Key_Super_R,
Qt.Key_Hyper_L, Qt.Key_Hyper_R, Qt.Key_Direction_L,
Qt.Key_Direction_R)
if self.key in modifier_keys:
# Only modifier pressed
if is_modifier_key(self.key):
return ''
parts = []
for (mask, s) in modmask2str.items():