[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>
pull/591/head
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

@ -37,7 +37,9 @@ static struct keymap_key al_basic[] = {
/** "al" AltGr remapping */
static struct keymap_key al_altgr[] = {
{ 0x30, 0x7e }, /* '0' => '~' */
{ 0x31, 0x7e }, /* '1' => '~' */
{ 0x34, 0x7e }, /* '4' => '~' */
{ 0x37, 0x60 }, /* '7' => '`' */
{ 0, 0 }
};

View File

@ -12,13 +12,17 @@ FILE_LICENCE ( PUBLIC_DOMAIN );
/** "cf" basic remapping */
static struct keymap_key cf_basic[] = {
{ 0x22, 0x60 }, /* '"' => '`' */
{ 0x23, 0x2f }, /* '#' => '/' */
{ 0x27, 0x60 }, /* '\'' => '`' */
{ 0x3c, 0x27 }, /* '<' => '\'' */
{ 0x3e, 0x2e }, /* '>' => '.' */
{ 0x40, 0x22 }, /* '@' => '"' */
{ 0x5b, 0x5e }, /* '[' => '^' */
{ 0x5c, 0x3c }, /* '\\' => '<' */
{ 0x5e, 0x3f }, /* '^' => '?' */
{ 0x60, 0x23 }, /* '`' => '#' */
{ 0x7b, 0x5e }, /* '{' => '^' */
{ 0x7c, 0x3e }, /* '|' => '>' */
{ 0x7e, 0x7c }, /* '~' => '|' */
{ 0, 0 }
@ -26,6 +30,7 @@ static struct keymap_key cf_basic[] = {
/** "cf" AltGr remapping */
static struct keymap_key cf_altgr[] = {
{ 0x27, 0x7b }, /* '\'' => '{' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x3b, 0x7e }, /* ';' => '~' */
{ 0x60, 0x5c }, /* '`' => '\\' */

View File

@ -24,6 +24,7 @@ static struct keymap_key cz_basic[] = {
{ 0x28, 0x39 }, /* '(' => '9' */
{ 0x29, 0x30 }, /* ')' => '0' */
{ 0x2a, 0x38 }, /* '*' => '8' */
{ 0x2b, 0x5e }, /* '+' => '^' */
{ 0x2d, 0x3d }, /* '-' => '=' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x31, 0x2b }, /* '1' => '+' */
@ -43,6 +44,7 @@ static struct keymap_key cz_basic[] = {
{ 0x7b, 0x2f }, /* '{' => '/' */
{ 0x7c, 0x27 }, /* '|' => '\'' */
{ 0x7d, 0x28 }, /* '}' => '(' */
{ 0x7e, 0x60 }, /* '~' => '`' */
{ 0, 0 }
};
@ -55,16 +57,14 @@ static struct keymap_key cz_altgr[] = {
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x33, 0x23 }, /* '3' => '#' */
{ 0x34, 0x24 }, /* '4' => '$' */
{ 0x36, 0x5e }, /* '6' => '^' */
{ 0x37, 0x26 }, /* '7' => '&' */
{ 0x38, 0x2a }, /* '8' => '*' */
{ 0x39, 0x7b }, /* '9' => '{' */
{ 0x3b, 0x24 }, /* ';' => '$' */
{ 0x61, 0x7e }, /* 'a' => '~' */
{ 0x62, 0x7b }, /* 'b' => '{' */
{ 0x63, 0x26 }, /* 'c' => '&' */
{ 0x67, 0x5d }, /* 'g' => ']' */
{ 0x68, 0x60 }, /* 'h' => '`' */
{ 0x6d, 0x5e }, /* 'm' => '^' */
{ 0x6e, 0x7d }, /* 'n' => '}' */
{ 0x76, 0x40 }, /* 'v' => '@' */
{ 0x78, 0x23 }, /* 'x' => '#' */

View File

@ -21,6 +21,7 @@ static struct keymap_key de_basic[] = {
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3c, 0x3b }, /* '<' => ';' */
{ 0x3e, 0x3a }, /* '>' => ':' */
@ -32,6 +33,7 @@ static struct keymap_key de_basic[] = {
{ 0x5d, 0x2b }, /* ']' => '+' */
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x5e }, /* '`' => '^' */
{ 0x79, 0x7a }, /* 'y' => 'z' */
{ 0x7a, 0x79 }, /* 'z' => 'y' */
{ 0x7c, 0x27 }, /* '|' => '\'' */

View File

@ -18,6 +18,7 @@ static struct keymap_key dk_basic[] = {
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2d, 0x2b }, /* '-' => '+' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3c, 0x3b }, /* '<' => ';' */
@ -28,6 +29,7 @@ static struct keymap_key dk_basic[] = {
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x7c, 0x2a }, /* '|' => '*' */
{ 0x7d, 0x5e }, /* '}' => '^' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
{ 0, 0 }
@ -35,6 +37,7 @@ static struct keymap_key dk_basic[] = {
/** "dk" AltGr remapping */
static struct keymap_key dk_altgr[] = {
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x3d, 0x7c }, /* '=' => '|' */
{ 0x71, 0x40 }, /* 'q' => '@' */

View File

@ -24,9 +24,11 @@ static struct keymap_key es_basic[] = {
{ 0x3e, 0x3a }, /* '>' => ':' */
{ 0x3f, 0x5f }, /* '?' => '_' */
{ 0x40, 0x22 }, /* '@' => '"' */
{ 0x5b, 0x60 }, /* '[' => '`' */
{ 0x5d, 0x2b }, /* ']' => '+' */
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x7b, 0x5e }, /* '{' => '^' */
{ 0x7d, 0x2a }, /* '}' => '*' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
@ -35,8 +37,11 @@ static struct keymap_key es_basic[] = {
/** "es" AltGr remapping */
static struct keymap_key es_altgr[] = {
{ 0x27, 0x7b }, /* '\'' => '{' */
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x37, 0x7b }, /* '7' => '{' */
{ 0x38, 0x5b }, /* '8' => '[' */
{ 0x39, 0x5d }, /* '9' => ']' */
{ 0x5c, 0x7d }, /* '\\' => '}' */
{ 0x71, 0x40 }, /* 'q' => '@' */

View File

@ -16,6 +16,7 @@ static struct keymap_key et_basic[] = {
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2d, 0x2b }, /* '-' => '+' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3c, 0x3b }, /* '<' => ';' */
@ -25,6 +26,7 @@ static struct keymap_key et_basic[] = {
{ 0x5c, 0x27 }, /* '\\' => '\'' */
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x5e }, /* '`' => '^' */
{ 0x7c, 0x2a }, /* '|' => '*' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
@ -33,7 +35,6 @@ static struct keymap_key et_basic[] = {
/** "et" AltGr remapping */
static struct keymap_key et_altgr[] = {
{ 0x27, 0x5e }, /* '\'' => '^' */
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */

View File

@ -16,6 +16,7 @@ static struct keymap_key fi_basic[] = {
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2d, 0x2b }, /* '-' => '+' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3c, 0x3b }, /* '<' => ';' */
@ -26,6 +27,7 @@ static struct keymap_key fi_basic[] = {
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x7c, 0x2a }, /* '|' => '*' */
{ 0x7d, 0x5e }, /* '}' => '^' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
{ 0, 0 }
@ -34,6 +36,7 @@ static struct keymap_key fi_basic[] = {
/** "fi" AltGr remapping */
static struct keymap_key fi_altgr[] = {
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0xdc, 0x7c }, /* Pseudo-'\\' => '|' */
{ 0, 0 }

View File

@ -49,6 +49,7 @@ static struct keymap_key fr_basic[] = {
{ 0x51, 0x41 }, /* 'Q' => 'A' */
{ 0x57, 0x5a }, /* 'W' => 'Z' */
{ 0x5a, 0x57 }, /* 'Z' => 'W' */
{ 0x5b, 0x5e }, /* '[' => '^' */
{ 0x5c, 0x2a }, /* '\\' => '*' */
{ 0x5d, 0x24 }, /* ']' => '$' */
{ 0x5e, 0x36 }, /* '^' => '6' */
@ -67,8 +68,8 @@ static struct keymap_key fr_altgr[] = {
{ 0x2d, 0x5d }, /* '-' => ']' */
{ 0x30, 0x40 }, /* '0' => '@' */
{ 0x33, 0x23 }, /* '3' => '#' */
{ 0x35, 0x5b }, /* '5' => '[' */
{ 0x38, 0x5c }, /* '8' => '\\' */
{ 0x39, 0x5e }, /* '9' => '^' */
{ 0x61, 0x40 }, /* 'a' => '@' */
{ 0, 0 }
};

View File

@ -39,6 +39,7 @@ static struct keymap_key hu_basic[] = {
static struct keymap_key hu_altgr[] = {
{ 0x2e, 0x3e }, /* '.' => '>' */
{ 0x2f, 0x2a }, /* '/' => '*' */
{ 0x32, 0x5e }, /* '2' => '^' */
{ 0x33, 0x5e }, /* '3' => '^' */
{ 0x37, 0x60 }, /* '7' => '`' */
{ 0x3b, 0x24 }, /* ';' => '$' */

View File

@ -42,6 +42,7 @@ static struct keymap_key it_altgr[] = {
{ 0x39, 0x5d }, /* '9' => ']' */
{ 0x3b, 0x40 }, /* ';' => '@' */
{ 0x3d, 0x7e }, /* '=' => '~' */
{ 0x5c, 0x60 }, /* '\\' => '`' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }
};

View File

@ -15,10 +15,12 @@ static struct keymap_key nl_basic[] = {
{ 0x1c, 0x3c }, /* 0x1c => '<' */
{ 0x1d, 0x1c }, /* 0x1d => 0x1c */
{ 0x1e, 0x36 }, /* 0x1e => '6' */
{ 0x22, 0x60 }, /* '"' => '`' */
{ 0x26, 0x5f }, /* '&' => '_' */
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x27 }, /* ')' => '\'' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x7e }, /* '+' => '~' */
{ 0x2d, 0x2f }, /* '-' => '/' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3b, 0x2b }, /* ';' => '+' */
@ -31,6 +33,7 @@ static struct keymap_key nl_basic[] = {
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x40 }, /* '`' => '@' */
{ 0x7b, 0x5e }, /* '{' => '^' */
{ 0x7c, 0x3e }, /* '|' => '>' */
{ 0x7d, 0x7c }, /* '}' => '|' */
{ 0xdc, 0x5d }, /* Pseudo-'\\' => ']' */
@ -41,6 +44,7 @@ static struct keymap_key nl_basic[] = {
/** "nl" AltGr remapping */
static struct keymap_key nl_altgr[] = {
{ 0x2d, 0x5c }, /* '-' => '\\' */
{ 0x38, 0x7b }, /* '8' => '{' */
{ 0x39, 0x7d }, /* '9' => '}' */
{ 0, 0 }
};

View File

@ -18,6 +18,7 @@ static struct keymap_key no_basic[] = {
{ 0x28, 0x29 }, /* '(' => ')' */
{ 0x29, 0x3d }, /* ')' => '=' */
{ 0x2a, 0x28 }, /* '*' => '(' */
{ 0x2b, 0x60 }, /* '+' => '`' */
{ 0x2d, 0x2b }, /* '-' => '+' */
{ 0x2f, 0x2d }, /* '/' => '-' */
{ 0x3c, 0x3b }, /* '<' => ';' */
@ -30,6 +31,7 @@ static struct keymap_key no_basic[] = {
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x7c }, /* '`' => '|' */
{ 0x7c, 0x2a }, /* '|' => '*' */
{ 0x7d, 0x5e }, /* '}' => '^' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
{ 0, 0 }
@ -37,6 +39,7 @@ static struct keymap_key no_basic[] = {
/** "no" AltGr remapping */
static struct keymap_key no_altgr[] = {
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x71, 0x40 }, /* 'q' => '@' */
{ 0, 0 }

View File

@ -12,6 +12,7 @@ FILE_LICENCE ( PUBLIC_DOMAIN );
/** "pt" basic remapping */
static struct keymap_key pt_basic[] = {
{ 0x1c, 0x7e }, /* 0x1c => '~' */
{ 0x1e, 0x36 }, /* 0x1e => '6' */
{ 0x26, 0x2f }, /* '&' => '/' */
{ 0x28, 0x29 }, /* '(' => ')' */
@ -24,10 +25,13 @@ static struct keymap_key pt_basic[] = {
{ 0x3f, 0x5f }, /* '?' => '_' */
{ 0x40, 0x22 }, /* '@' => '"' */
{ 0x5b, 0x2b }, /* '[' => '+' */
{ 0x5c, 0x7e }, /* '\\' => '~' */
{ 0x5e, 0x26 }, /* '^' => '&' */
{ 0x5f, 0x3f }, /* '_' => '?' */
{ 0x60, 0x5c }, /* '`' => '\\' */
{ 0x7b, 0x2a }, /* '{' => '*' */
{ 0x7c, 0x5e }, /* '|' => '^' */
{ 0x7d, 0x60 }, /* '}' => '`' */
{ 0x7e, 0x7c }, /* '~' => '|' */
{ 0xdc, 0x3c }, /* Pseudo-'\\' => '<' */
{ 0xfc, 0x3e }, /* Pseudo-'|' => '>' */
@ -36,6 +40,7 @@ static struct keymap_key pt_basic[] = {
/** "pt" AltGr remapping */
static struct keymap_key pt_altgr[] = {
{ 0x30, 0x7d }, /* '0' => '}' */
{ 0x32, 0x40 }, /* '2' => '@' */
{ 0x37, 0x7b }, /* '7' => '{' */
{ 0x38, 0x5b }, /* '8' => '[' */

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