aboutsummaryrefslogtreecommitdiffstats
path: root/src/interface
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-02-14 16:31:08 +0000
committerMichael Brown <mcb30@ipxe.org>2022-02-15 11:58:50 +0000
commitf2a59d5973da2041f93264609698b9b3f4ec101b (patch)
treed74210c67817a2bc8ddbf92514c18608566317ed /src/interface
parent871dd236d4aff66e871c25addcf522fe75a4ccd7 (diff)
downloadipxe-f2a59d5973da2041f93264609698b9b3f4ec101b.tar.gz
[console] Centralise handling of key modifiers
Handle Ctrl and CapsLock key modifiers within key_remap(), to provide consistent behaviour across different console types. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/efi/efi_console.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c
index 874f54b6c..9adce4a9b 100644
--- a/src/interface/efi/efi_console.c
+++ b/src/interface/efi/efi_console.c
@@ -55,8 +55,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define ATTR_DEFAULT ATTR_FCOL_WHITE
-#define CTRL_MASK 0x1f
-
/* Set default console usage if applicable */
#if ! ( defined ( CONSOLE_EFI ) && CONSOLE_EXPLICIT ( CONSOLE_EFI ) )
#undef CONSOLE_EFI
@@ -286,6 +284,9 @@ static int efi_getchar ( void ) {
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *conin_ex = efi_conin_ex;
const char *ansi_seq;
+ unsigned int character;
+ unsigned int shift;
+ unsigned int toggle;
EFI_KEY_DATA key;
EFI_STATUS efirc;
int rc;
@@ -318,23 +319,34 @@ static int efi_getchar ( void ) {
key.KeyState.KeyToggleState, key.Key.UnicodeChar,
key.Key.ScanCode );
- /* Remap key. There is unfortunately no way to avoid
- * remapping the numeric keypad, since EFI destroys the scan
- * code information that would allow us to differentiate
- * between main keyboard and numeric keypad.
+ /* If key has a Unicode representation, remap and return it.
+ * There is unfortunately no way to avoid remapping the
+ * numeric keypad, since EFI destroys the scan code
+ * information that would allow us to differentiate between
+ * main keyboard and numeric keypad.
*/
- key.Key.UnicodeChar = key_remap ( key.Key.UnicodeChar );
+ if ( ( character = key.Key.UnicodeChar ) != 0 ) {
+
+ /* Apply shift state */
+ shift = key.KeyState.KeyShiftState;
+ if ( shift & EFI_SHIFT_STATE_VALID ) {
+ if ( shift & ( EFI_LEFT_CONTROL_PRESSED |
+ EFI_RIGHT_CONTROL_PRESSED ) ) {
+ character |= KEYMAP_CTRL;
+ }
+ }
- /* Translate Ctrl-<key> */
- if ( ( key.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID ) &&
- ( key.KeyState.KeyShiftState & ( EFI_LEFT_CONTROL_PRESSED |
- EFI_RIGHT_CONTROL_PRESSED ) ) ) {
- key.Key.UnicodeChar &= CTRL_MASK;
- }
+ /* Apply toggle state */
+ toggle = key.KeyState.KeyToggleState;
+ if ( toggle & EFI_TOGGLE_STATE_VALID ) {
+ if ( toggle & EFI_CAPS_LOCK_ACTIVE ) {
+ character |= KEYMAP_CAPSLOCK_REDO;
+ }
+ }
- /* If key has a Unicode representation, return it */
- if ( key.Key.UnicodeChar )
- return key.Key.UnicodeChar;
+ /* Remap and return key */
+ return key_remap ( character );
+ }
/* Otherwise, check for a special key that we know about */
if ( ( ansi_seq = scancode_to_ansi_seq ( key.Key.ScanCode ) ) ) {