Skip to content

Commit c9dd3cd

Browse files
authored
feat(ui): Enhance Virtual Keyboard for US (#449)
* feat(ui): Add Ctrl+Alt-Backspace combination key to Virtual Keyboard Fixes #445 (somewhat) * fix(ui): Correct virtual keyboard display when shift key is down. Somewhere along the way, the handling of the shift-key state for letters and numbers was lost and we stopped displaying the capital/symbol for the key. Also update page up and page down to have the space in the on-screen key. * feat(ui): Add missing keys for virtual keyboard Enable insert, delete, numpad equal, print scree, scroll lock, pause, system request, break keys.
1 parent 7ccb8e6 commit c9dd3cd

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

ui/src/components/VirtualKeyboard.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ function KeyboardWrapper() {
143143
return;
144144
}
145145

146+
if (key === "CtrlAltBackspace") {
147+
sendKeyboardEvent(
148+
[keys["Backspace"]],
149+
[modifiers["ControlLeft"], modifiers["AltLeft"]],
150+
);
151+
152+
setTimeout(resetKeyboardState, 100);
153+
return;
154+
}
155+
146156
if (isKeyShift || isKeyCaps) {
147157
toggleLayout();
148158

@@ -257,13 +267,13 @@ function KeyboardWrapper() {
257267
buttonTheme={[
258268
{
259269
class: "combination-key",
260-
buttons: "CtrlAltDelete AltMetaEscape",
270+
buttons: "CtrlAltDelete AltMetaEscape CtrlAltBackspace",
261271
},
262272
]}
263273
display={keyDisplayMap}
264274
layout={{
265275
default: [
266-
"CtrlAltDelete AltMetaEscape",
276+
"CtrlAltDelete AltMetaEscape CtrlAltBackspace",
267277
"Escape F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12",
268278
"Backquote Digit1 Digit2 Digit3 Digit4 Digit5 Digit6 Digit7 Digit8 Digit9 Digit0 Minus Equal Backspace",
269279
"Tab KeyQ KeyW KeyE KeyR KeyT KeyY KeyU KeyI KeyO KeyP BracketLeft BracketRight Backslash",
@@ -272,7 +282,7 @@ function KeyboardWrapper() {
272282
"ControlLeft AltLeft MetaLeft Space MetaRight AltRight",
273283
],
274284
shift: [
275-
"CtrlAltDelete AltMetaEscape",
285+
"CtrlAltDelete AltMetaEscape CtrlAltBackspace",
276286
"Escape F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12",
277287
"(Backquote) (Digit1) (Digit2) (Digit3) (Digit4) (Digit5) (Digit6) (Digit7) (Digit8) (Digit9) (Digit0) (Minus) (Equal) (Backspace)",
278288
"Tab (KeyQ) (KeyW) (KeyE) (KeyR) (KeyT) (KeyY) (KeyU) (KeyI) (KeyO) (KeyP) (BracketLeft) (BracketRight) (Backslash)",
@@ -282,42 +292,33 @@ function KeyboardWrapper() {
282292
],
283293
}}
284294
disableButtonHold={true}
285-
mergeDisplay={true}
295+
syncInstanceInputs={true}
286296
debug={false}
287297
/>
288298

289299
<div className="controlArrows">
290300
<Keyboard
291301
baseClass="simple-keyboard-control"
292302
theme="simple-keyboard hg-theme-default hg-layout-default"
303+
layoutName={layoutName}
304+
onKeyPress={onKeyDown}
305+
display={keyDisplayMap}
293306
layout={{
294-
default: ["Home Pageup", "Delete End Pagedown"],
295-
}}
296-
display={{
297-
Home: "home",
298-
Pageup: "pageup",
299-
Delete: "delete",
300-
End: "end",
301-
Pagedown: "pagedown",
307+
default: ["PrintScreen ScrollLock Pause", "Insert Home Pageup", "Delete End Pagedown"],
308+
shift: ["(PrintScreen) ScrollLock (Pause)", "Insert Home Pageup", "Delete End Pagedown"],
302309
}}
303310
syncInstanceInputs={true}
304-
onKeyPress={onKeyDown}
305-
mergeDisplay={true}
306311
debug={false}
307312
/>
308313
<Keyboard
309314
baseClass="simple-keyboard-arrows"
310315
theme="simple-keyboard hg-theme-default hg-layout-default"
311-
display={{
312-
ArrowLeft: "←",
313-
ArrowRight: "→",
314-
ArrowUp: "↑",
315-
ArrowDown: "↓",
316-
}}
316+
onKeyPress={onKeyDown}
317+
display={keyDisplayMap}
317318
layout={{
318319
default: ["ArrowUp", "ArrowLeft ArrowDown ArrowRight"],
319320
}}
320-
onKeyPress={onKeyDown}
321+
syncInstanceInputs={true}
321322
debug={false}
322323
/>
323324
</div>

ui/src/keyboardMappings.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,21 @@ export const keys = {
8686
NumpadAdd: 0x57,
8787
NumpadDivide: 0x54,
8888
NumpadEnter: 0x58,
89+
NumpadEqual: 0x67,
8990
NumpadMultiply: 0x55,
9091
NumpadSubtract: 0x56,
9192
NumpadDecimal: 0x63,
9293
PageDown: 0x4e,
9394
PageUp: 0x4b,
9495
Period: 0x37,
96+
PrintScreen: 0x46,
97+
Pause: 0x48,
9598
Quote: 0x34,
99+
ScrollLock: 0x47,
96100
Semicolon: 0x33,
97101
Slash: 0x38,
98102
Space: 0x2c,
103+
SystemRequest: 0x9a,
99104
Tab: 0x2b,
100105
} as Record<string, number>;
101106

@@ -200,6 +205,13 @@ export const chars = {
200205
"\n": { key: "Enter", shift: false },
201206
Enter: { key: "Enter", shift: false },
202207
Tab: { key: "Tab", shift: false },
208+
PrintScreen: { key: "Prt Sc", shift: false },
209+
SystemRequest: { key: "Prt Sc", shift: true },
210+
ScrollLock: { key: "ScrollLock", shift: false},
211+
Pause: { key: "Pause", shift: false },
212+
Break: { key: "Pause", shift: true },
213+
Insert: { key: "Insert", shift: false },
214+
Delete: { key: "Delete", shift: false },
203215
} as Record<string, { key: string | number; shift: boolean }>;
204216

205217
export const modifiers = {
@@ -227,6 +239,7 @@ export const modifierDisplayMap: Record<string, string> = {
227239
export const keyDisplayMap: Record<string, string> = {
228240
CtrlAltDelete: "Ctrl + Alt + Delete",
229241
AltMetaEscape: "Alt + Meta + Escape",
242+
CtrlAltBackspace: "Ctrl + Alt + Backspace",
230243
Escape: "esc",
231244
Tab: "tab",
232245
Backspace: "backspace",
@@ -240,11 +253,12 @@ export const keyDisplayMap: Record<string, string> = {
240253
MetaLeft: "meta",
241254
MetaRight: "meta",
242255
Space: " ",
256+
Insert: "insert",
243257
Home: "home",
244-
PageUp: "pageup",
258+
PageUp: "page up",
245259
Delete: "delete",
246260
End: "end",
247-
PageDown: "pagedown",
261+
PageDown: "page down",
248262
ArrowLeft: "←",
249263
ArrowRight: "→",
250264
ArrowUp: "↑",
@@ -258,22 +272,45 @@ export const keyDisplayMap: Record<string, string> = {
258272
KeyU: "u", KeyV: "v", KeyW: "w", KeyX: "x", KeyY: "y",
259273
KeyZ: "z",
260274

275+
// Capital letters
276+
"(KeyA)": "A", "(KeyB)": "B", "(KeyC)": "C", "(KeyD)": "D", "(KeyE)": "E",
277+
"(KeyF)": "F", "(KeyG)": "G", "(KeyH)": "H", "(KeyI)": "I", "(KeyJ)": "J",
278+
"(KeyK)": "K", "(KeyL)": "L", "(KeyM)": "M", "(KeyN)": "N", "(KeyO)": "O",
279+
"(KeyP)": "P", "(KeyQ)": "Q", "(KeyR)": "R", "(KeyS)": "S", "(KeyT)": "T",
280+
"(KeyU)": "U", "(KeyV)": "V", "(KeyW)": "W", "(KeyX)": "X", "(KeyY)": "Y",
281+
"(KeyZ)": "Z",
282+
261283
// Numbers
262284
Digit1: "1", Digit2: "2", Digit3: "3", Digit4: "4", Digit5: "5",
263285
Digit6: "6", Digit7: "7", Digit8: "8", Digit9: "9", Digit0: "0",
264286

287+
// Shifted Numbers
288+
"(Digit1)": "!", "(Digit2)": "@", "(Digit3)": "#", "(Digit4)": "$", "(Digit5)": "%",
289+
"(Digit6)": "^", "(Digit7)": "&", "(Digit8)": "*", "(Digit9)": "(", "(Digit0)": ")",
290+
265291
// Symbols
266292
Minus: "-",
293+
"(Minus)": "_",
267294
Equal: "=",
295+
"(Equal)": "+",
268296
BracketLeft: "[",
297+
"(BracketLeft)": "{",
269298
BracketRight: "]",
299+
"(BracketRight)": "}",
270300
Backslash: "\\",
301+
"(Backslash)": "|",
271302
Semicolon: ";",
303+
"(Semicolon)": ":",
272304
Quote: "'",
305+
"(Quote)": "\"",
273306
Comma: ",",
307+
"(Comma)": "<",
274308
Period: ".",
309+
"(Period)": ">",
275310
Slash: "/",
311+
"(Slash)": "?",
276312
Backquote: "`",
313+
"(Backquote)": "~",
277314
IntlBackslash: "\\",
278315

279316
// Function keys
@@ -287,5 +324,11 @@ export const keyDisplayMap: Record<string, string> = {
287324
Numpad6: "Num 6", Numpad7: "Num 7", Numpad8: "Num 8",
288325
Numpad9: "Num 9", NumpadAdd: "Num +", NumpadSubtract: "Num -",
289326
NumpadMultiply: "Num *", NumpadDivide: "Num /", NumpadDecimal: "Num .",
290-
NumpadEnter: "Num Enter"
327+
NumpadEqual: "Num =", NumpadEnter: "Num Enter",
328+
NumLock: "Num Lock",
329+
330+
// Modals
331+
PrintScreen: "prt sc", ScrollLock: "scr lk", Pause: "pause",
332+
"(PrintScreen)": "sys rq", "(Pause)": "break",
333+
SystemRequest: "sys rq", Break: "break"
291334
};

0 commit comments

Comments
 (0)