feat: add keyboard layout support

This commit is contained in:
daniel committed 2026-08-13 17:57:44 +02:00
1 parent 86e3ebfe33
commit 821543238d
36 files changed
+1132 -125

No files matched your search

+21 -4
View File
@@ -179,7 +179,9 @@ namespace Drivers::PS2::Keyboard {
.Shift = g_Modifiers.LeftShift || g_Modifiers.RightShift,
.Ctrl = g_Modifiers.LeftCtrl || g_Modifiers.RightCtrl,
.Alt = g_Modifiers.LeftAlt || g_Modifiers.RightAlt,
.CapsLock = g_Modifiers.CapsLock
.CapsLock = g_Modifiers.CapsLock,
.AltGr = g_Modifiers.RightAlt,
.Extended = true
};
PushAndNotify(event);
@@ -237,7 +239,9 @@ namespace Drivers::PS2::Keyboard {
.Shift = g_Modifiers.LeftShift || g_Modifiers.RightShift,
.Ctrl = g_Modifiers.LeftCtrl || g_Modifiers.RightCtrl,
.Alt = g_Modifiers.LeftAlt || g_Modifiers.RightAlt,
.CapsLock = g_Modifiers.CapsLock
.CapsLock = g_Modifiers.CapsLock,
.AltGr = g_Modifiers.RightAlt,
.Extended = false
};
PushAndNotify(event);
return;
@@ -261,7 +265,9 @@ namespace Drivers::PS2::Keyboard {
.Shift = g_Modifiers.LeftShift || g_Modifiers.RightShift,
.Ctrl = g_Modifiers.LeftCtrl || g_Modifiers.RightCtrl,
.Alt = g_Modifiers.LeftAlt || g_Modifiers.RightAlt,
.CapsLock = g_Modifiers.CapsLock
.CapsLock = g_Modifiers.CapsLock,
.AltGr = g_Modifiers.RightAlt,
.Extended = false
};
PushAndNotify(event);
@@ -298,7 +304,18 @@ namespace Drivers::PS2::Keyboard {
}
void InjectKeyEvent(const KeyEvent& event) {
PushAndNotify(event);
// Caps Lock is owned here rather than by each injecting driver: USB HID
// reports the key as an ordinary usage and carries no lock state, so
// without this the lock would never toggle on a USB keyboard.
KeyEvent stamped = event;
if (stamped.Scancode == ScCapsLock && stamped.Pressed)
g_Modifiers.CapsLock = !g_Modifiers.CapsLock;
stamped.CapsLock = g_Modifiers.CapsLock;
PushAndNotify(stamped);
}
bool GetCapsLock() {
return g_Modifiers.CapsLock;
}
};
+11
View File
@@ -18,6 +18,13 @@ namespace Drivers::PS2::Keyboard {
bool Ctrl;
bool Alt;
bool CapsLock;
// Right Alt held. Reported separately from Alt so keyboard layouts can
// use it as AltGr without swallowing left-Alt shortcuts.
bool AltGr;
// Key came from an E0-prefixed (extended) scancode. The prefix is not
// part of Scancode, so without this flag keypad "/" is indistinguishable
// from the main "/" key and layout translation would rewrite it.
bool Extended;
};
// Modifier key state
@@ -52,4 +59,8 @@ namespace Drivers::PS2::Keyboard {
// Inject a key event from an external source (e.g., USB HID keyboard)
void InjectKeyEvent(const KeyEvent& event);
// Current Caps Lock state. Injecting drivers (USB HID) need this to
// compute ASCII, since the lock is toggled centrally here.
bool GetCapsLock();
};