From c7d78192919bfa62fde33650e1506e902816eec3 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 15 Feb 2022 11:28:57 +0000 Subject: [console] Treat dead keys as producing their ASCII equivalents Treat dead keys in target keymaps as producing the closest equivalent ASCII character, since many of these characters are otherwise unrepresented on the keyboard. Signed-off-by: Michael Brown --- src/util/genkeymap.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/genkeymap.py b/src/util/genkeymap.py index ff5ff0a87..42ccee175 100755 --- a/src/util/genkeymap.py +++ b/src/util/genkeymap.py @@ -54,6 +54,14 @@ class KeyType(IntEnum): UNKNOWN = 0xf0 +class DeadKey(IntEnum): + """Dead keys""" + + GRAVE = 0 + CIRCUMFLEX = 2 + TILDE = 3 + + class KeyModifiers(Flag): """Key modifiers""" @@ -96,6 +104,13 @@ class Key: KeyType.LETTER} """Key types with direct ASCII values""" + DEAD_KEYS: ClassVar[Mapping[int, str]] = { + DeadKey.GRAVE: '`', + DeadKey.CIRCUMFLEX: '^', + DeadKey.TILDE: '~', + } + """Dead key replacement ASCII values""" + @property def keytype(self) -> Optional[KeyType]: """Key type""" @@ -112,11 +127,14 @@ class Key: @property def ascii(self) -> Optional[str]: """ASCII character""" - if self.keytype in self.ASCII_TYPES: - value = self.value + keytype = self.keytype + value = self.value + if keytype in self.ASCII_TYPES: char = chr(value) if value and char.isascii(): return char + if keytype == KeyType.DEAD: + return self.DEAD_KEYS.get(value) return None -- cgit