mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
KeyboardDevice: Implement Caps Lock handling.
This commit is contained in:
parent
437c919dda
commit
9d5792b73d
2 changed files with 19 additions and 4 deletions
|
@ -104,7 +104,7 @@ static KeyCode unshifted_key_map[0x80] = {
|
||||||
Key_Invalid,
|
Key_Invalid,
|
||||||
Key_Alt, // 56
|
Key_Alt, // 56
|
||||||
Key_Space, // 57
|
Key_Space, // 57
|
||||||
Key_Invalid, // 58
|
Key_CapsLock, // 58
|
||||||
Key_F1,
|
Key_F1,
|
||||||
Key_F2,
|
Key_F2,
|
||||||
Key_F3,
|
Key_F3,
|
||||||
|
@ -199,7 +199,7 @@ static KeyCode shifted_key_map[0x100] = {
|
||||||
Key_Invalid,
|
Key_Invalid,
|
||||||
Key_Alt,
|
Key_Alt,
|
||||||
Key_Space, // 57
|
Key_Space, // 57
|
||||||
Key_Invalid, // 58
|
Key_CapsLock, // 58
|
||||||
Key_F1,
|
Key_F1,
|
||||||
Key_F2,
|
Key_F2,
|
||||||
Key_F3,
|
Key_F3,
|
||||||
|
@ -237,9 +237,23 @@ static KeyCode shifted_key_map[0x100] = {
|
||||||
|
|
||||||
void KeyboardDevice::key_state_changed(u8 raw, bool pressed)
|
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_CapsLock && pressed)
|
||||||
|
m_caps_lock_on = !m_caps_lock_on;
|
||||||
|
|
||||||
|
if (m_caps_lock_on && (m_modifiers == 0 || m_modifiers == Mod_Shift))
|
||||||
|
{
|
||||||
|
if (character >= 'a' && character <= 'z')
|
||||||
|
character &= ~0x20;
|
||||||
|
else if (character >= 'A' && character <= 'Z')
|
||||||
|
character |= 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
Event event;
|
Event event;
|
||||||
event.key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw];
|
event.key = key;
|
||||||
event.character = (m_modifiers & Mod_Shift) ? shift_map[raw] : map[raw];
|
event.character = static_cast<u8>(character);
|
||||||
event.flags = m_modifiers;
|
event.flags = m_modifiers;
|
||||||
if (pressed)
|
if (pressed)
|
||||||
event.flags |= Is_Press;
|
event.flags |= Is_Press;
|
||||||
|
|
|
@ -47,6 +47,7 @@ private:
|
||||||
KeyboardClient* m_client { nullptr };
|
KeyboardClient* m_client { nullptr };
|
||||||
CircularQueue<Event, 16> m_queue;
|
CircularQueue<Event, 16> m_queue;
|
||||||
u8 m_modifiers { 0 };
|
u8 m_modifiers { 0 };
|
||||||
|
bool m_caps_lock_on { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeyboardClient {
|
class KeyboardClient {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue