From f798e43ea8f89af74214689d5f48ff195bf941b5 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 8 Jul 2023 15:59:51 -0400 Subject: [PATCH] Kernel: Add a key code modifier to detect the number pad This is analagous to how Qt exposes whether the number pad was used for a key press. --- Kernel/API/KeyCode.h | 4 +++- Kernel/Devices/HID/KeyboardDevice.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Kernel/API/KeyCode.h b/Kernel/API/KeyCode.h index 495ad7079e..0fd33a62b1 100644 --- a/Kernel/API/KeyCode.h +++ b/Kernel/API/KeyCode.h @@ -134,7 +134,8 @@ enum KeyModifier { Mod_Shift = (1 << 2), Mod_Super = (1 << 3), Mod_AltGr = (1 << 4), - Mod_Mask = Mod_Alt | Mod_Ctrl | Mod_Shift | Mod_Super | Mod_AltGr, + Mod_Keypad = (1 << 5), + Mod_Mask = Mod_Alt | Mod_Ctrl | Mod_Shift | Mod_Super | Mod_AltGr | Mod_Keypad, Is_Press = 0x80, }; @@ -151,6 +152,7 @@ struct KeyEvent { bool shift() const { return flags & Mod_Shift; } bool super() const { return flags & Mod_Super; } bool altgr() const { return flags & Mod_AltGr; } + bool keypad() const { return flags & Mod_Keypad; } unsigned modifiers() const { return flags & Mod_Mask; } bool is_press() const { return flags & Is_Press; } }; diff --git a/Kernel/Devices/HID/KeyboardDevice.cpp b/Kernel/Devices/HID/KeyboardDevice.cpp index 27e3938812..0e7fbb9a81 100644 --- a/Kernel/Devices/HID/KeyboardDevice.cpp +++ b/Kernel/Devices/HID/KeyboardDevice.cpp @@ -243,6 +243,24 @@ void KeyboardDevice::handle_scan_code_input_event(ScanCodeEvent event) m_right_shift_pressed = event.pressed; update_modifier(Mod_Shift, m_left_shift_pressed || m_right_shift_pressed); break; + case 0x35: + case 0x37: + case 0x47: + case 0x48: + case 0x49: + case 0x4a: + case 0x4b: + case 0x4c: + case 0x4d: + case 0x4e: + case 0x4f: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + // FIXME: This should also include the keypad "enter" key, but that has the same scan code as the return key (0x1c). + update_modifier(Mod_Keypad, event.pressed); + break; } KeyCode key = (m_modifiers & Mod_Shift) ? shifted_key_map[event.scan_code_value] : unshifted_key_map[event.scan_code_value];