diff options
author | Nufflee <zifcani@gmail.com> | 2019-10-13 23:32:26 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-17 23:39:24 +0200 |
commit | 0979f372a646f5030c7e2822120559a575e12666 (patch) | |
tree | a78ebd510f22c9c057b7c6330bf4a99e1e7b9ff5 /Kernel/Devices/KeyboardDevice.cpp | |
parent | 9d5792b73d4b3b2a876560837b8e40fcc9c74126 (diff) | |
download | serenity-0979f372a646f5030c7e2822120559a575e12666.zip |
KeyboardDevice: Support whole numpad and Num Lock.
We now support all numpad keys and the Num Lock key.
Diffstat (limited to 'Kernel/Devices/KeyboardDevice.cpp')
-rw-r--r-- | Kernel/Devices/KeyboardDevice.cpp | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index 3d8718ac45..602817bdcf 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -22,11 +22,11 @@ static char map[0x80] = { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', - 0, 0, 0, ' ', 0, 0, + 0, '*', 0, ' ', 0, 0, //60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //70 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, '-', 0, 0, 0, '+', 0, //80 0, 0, 0, 0, 0, 0, '\\', 0, 0, 0, }; @@ -36,15 +36,17 @@ static char shift_map[0x80] = { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', - 0, 0, 0, ' ', 0, 0, + 0, '*', 0, ' ', 0, 0, //60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //70 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, '-', 0, 0, 0, '+', 0, //80 0, 0, 0, 0, 0, 0, '|', 0, 0, 0, }; +static char numpad_map[13] = { '7', '8', '9', 0, '4', '5', '6', 0, '1', '2', '3', '0', ',' }; + static KeyCode unshifted_key_map[0x80] = { Key_Invalid, Key_Escape, @@ -101,7 +103,7 @@ static KeyCode unshifted_key_map[0x80] = { Key_Period, Key_Slash, Key_RightShift, // 54 - Key_Invalid, + Key_Asterisk, Key_Alt, // 56 Key_Space, // 57 Key_CapsLock, // 58 @@ -115,16 +117,16 @@ static KeyCode unshifted_key_map[0x80] = { Key_F8, Key_F9, Key_F10, - Key_Invalid, + Key_NumLock, Key_Invalid, // 70 Key_Home, Key_Up, Key_PageUp, - Key_Invalid, + Key_Minus, Key_Left, Key_Invalid, Key_Right, // 77 - Key_Invalid, + Key_Plus, Key_End, Key_Down, // 80 Key_PageDown, @@ -196,7 +198,7 @@ static KeyCode shifted_key_map[0x100] = { Key_GreaterThan, Key_QuestionMark, Key_RightShift, // 54 - Key_Invalid, + Key_Asterisk, Key_Alt, Key_Space, // 57 Key_CapsLock, // 58 @@ -210,16 +212,16 @@ static KeyCode shifted_key_map[0x100] = { Key_F8, Key_F9, Key_F10, - Key_Invalid, + Key_NumLock, Key_Invalid, // 70 Key_Home, Key_Up, Key_PageUp, - Key_Invalid, + Key_Minus, Key_Left, Key_Invalid, Key_Right, // 77 - Key_Invalid, + Key_Plus, Key_End, Key_Down, // 80 Key_PageDown, @@ -235,11 +237,31 @@ static KeyCode shifted_key_map[0x100] = { Key_Logo, }; +static KeyCode numpad_key_map[13] = { Key_7, Key_8, Key_9, Key_Invalid, Key_4, Key_5, Key_6, Key_Invalid, Key_1, Key_2, Key_3, Key_0, Key_Comma }; + void KeyboardDevice::key_state_changed(u8 raw, bool pressed) { KeyCode key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw]; char character = (m_modifiers & Mod_Shift) ? shift_map[raw] : map[raw]; + if (key == Key_NumLock && pressed) + m_num_lock_on = !m_num_lock_on; + + if (m_num_lock_on && m_is_numpad_key) + { + if (raw >= 0x47 && raw <= 0x53) + { + u8 index = raw - 0x47; + KeyCode newKey = numpad_key_map[index]; + + if (newKey != Key_Invalid) + { + key = newKey; + character = numpad_map[index]; + } + } + } + if (key == Key_CapsLock && pressed) m_caps_lock_on = !m_caps_lock_on; @@ -260,6 +282,8 @@ void KeyboardDevice::key_state_changed(u8 raw, bool pressed) if (m_client) m_client->on_key_pressed(event); m_queue.enqueue(event); + + m_is_numpad_key = true; } void KeyboardDevice::handle_irq() @@ -289,6 +313,10 @@ void KeyboardDevice::handle_irq() case 0x36: update_modifier(Mod_Shift, pressed); break; + case 0x60: + // This flag means next key pressed could be but is not a numpad key. + m_is_numpad_key = false; + return; } switch (ch) { case I8042_ACK: |