[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 <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2022-02-15 11:28:57 +00:00
parent e1cedbc0d4
commit c7d7819291
15 changed files with 61 additions and 7 deletions

View File

@@ -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