feat: switch text to UTF-8; add Unicode key events, dead keys & Czech layout; fix numpad navigation; add NumLock support
This commit is contained in:
1 parent
32660ddd1a
commit
2aa6360b3d
101 files changed
+3733
-1639
No files matched your search
@@ -139,6 +139,7 @@ namespace Drivers::PS2::Keyboard {
|
||||
ack = Drivers::PS2::ReadData();
|
||||
|
||||
g_Modifiers = {};
|
||||
g_Modifiers.NumLock = true; // keypad types digits, as on most PCs
|
||||
g_BufferHead = 0;
|
||||
g_BufferTail = 0;
|
||||
g_ExtendedScancode = false;
|
||||
@@ -257,6 +258,9 @@ namespace Drivers::PS2::Keyboard {
|
||||
ascii = g_ScancodeToAscii[keycode];
|
||||
}
|
||||
}
|
||||
// Num Lock off: the keypad is navigation keys, which type nothing.
|
||||
if (!g_Modifiers.NumLock && IsKeypadNavScancode(keycode))
|
||||
ascii = 0;
|
||||
|
||||
KeyEvent event = {
|
||||
.Scancode = scancode,
|
||||
@@ -310,6 +314,12 @@ namespace Drivers::PS2::Keyboard {
|
||||
KeyEvent stamped = event;
|
||||
if (stamped.Scancode == ScCapsLock && stamped.Pressed)
|
||||
g_Modifiers.CapsLock = !g_Modifiers.CapsLock;
|
||||
// Num Lock likewise. Like the PS/2 path, the lock key itself is not
|
||||
// delivered to apps.
|
||||
if (stamped.Scancode == ScNumLock) {
|
||||
if (stamped.Pressed) g_Modifiers.NumLock = !g_Modifiers.NumLock;
|
||||
return;
|
||||
}
|
||||
stamped.CapsLock = g_Modifiers.CapsLock;
|
||||
PushAndNotify(stamped);
|
||||
}
|
||||
@@ -318,4 +328,8 @@ namespace Drivers::PS2::Keyboard {
|
||||
return g_Modifiers.CapsLock;
|
||||
}
|
||||
|
||||
bool GetNumLock() {
|
||||
return g_Modifiers.NumLock;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -63,4 +63,14 @@ namespace Drivers::PS2::Keyboard {
|
||||
// compute ASCII, since the lock is toggled centrally here.
|
||||
bool GetCapsLock();
|
||||
|
||||
// Current Num Lock state, owned here like Caps Lock. On (the default), the
|
||||
// keypad types digits; off, it acts as the navigation keys printed on it.
|
||||
bool GetNumLock();
|
||||
|
||||
// Set-1 scancodes of the keypad keys that are a digit/'.' with Num Lock on
|
||||
// and Home/arrows/PgUp/End/PgDn/Ins/Del with it off (not '-' and '+').
|
||||
inline bool IsKeypadNavScancode(uint8_t keycode) {
|
||||
return keycode >= 0x47 && keycode <= 0x53 && keycode != 0x4A && keycode != 0x4E;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -223,6 +223,12 @@ namespace Drivers::USB::HidKeyboard {
|
||||
if (caps && base >= 'a' && base <= 'z') upper = !shift;
|
||||
ascii = upper ? g_ScancodeToAsciiShifted[scancode] : base;
|
||||
}
|
||||
// Num Lock off: the keypad is navigation keys, which type nothing.
|
||||
// (Only keypad usages get here with these scancodes: the dedicated
|
||||
// navigation keys are nonChar already.)
|
||||
if (!Drivers::PS2::Keyboard::GetNumLock() &&
|
||||
Drivers::PS2::Keyboard::IsKeypadNavScancode(scancode))
|
||||
ascii = 0;
|
||||
|
||||
Drivers::PS2::Keyboard::KeyEvent event = {
|
||||
.Scancode = scancode,
|
||||
@@ -367,10 +373,14 @@ namespace Drivers::USB::HidKeyboard {
|
||||
uint8_t scancode = g_HidToScancode[key];
|
||||
if (scancode != 0) {
|
||||
InjectKey(scancode, true, modifiers, IsNonCharKey(key), IsExtendedKey(key));
|
||||
g_RepeatKey = key;
|
||||
g_RepeatStartMs = now;
|
||||
g_LastRepeatMs = 0;
|
||||
newKeyPressed = true;
|
||||
// Lock keys toggle once per press; repeating them while
|
||||
// held would flip Caps/Num/Scroll Lock on and off.
|
||||
if (key != 0x39 && key != 0x53 && key != 0x47) {
|
||||
g_RepeatKey = key;
|
||||
g_RepeatStartMs = now;
|
||||
g_LastRepeatMs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user