Files
kvm/ui/src/keyboardMappings.ts
luckfox-eng29 9a4e604c61 Update App version to 0.1.1
Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2026-02-05 13:59:33 +08:00

258 lines
13 KiB
TypeScript

// Key codes and modifiers correspond to definitions in the
// [Linux USB HID gadget driver](https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt)
const delSvg = `<svg viewBox="0 0 21.2307 17" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="21.230713" height="17.000000" fill="none" customFrame="#000000">
\t<path id="Delete Button" d="M3.25716 4.19339C3.28743 4.16156 3.31486 4.13325 3.32883 4.1196C3.34741 4.09976 3.36617 4.0822 3.3837 4.06727L5.38399 1.92849L5.68475 1.60738C5.75681 1.53044 5.81494 1.46999 5.9457 1.33519C5.9457 1.33519 5.98065 1.29781 5.98845 1.2891C6.02078 1.25276 6.0403 1.2309 6.05307 1.21728C6.32543 0.926129 6.63825 0.681617 6.989 0.487769C7.33115 0.306015 7.69603 0.177816 8.08126 0.105528C8.42982 0.0458787 8.78202 0.0137774 9.11815 0.00994754C9.25148 0.00425352 9.35501 0.00314815 9.57418 0.00323558C9.72581 0.000537435 9.84611 0 10.1118 0L16.0355 0C16.1686 0 16.2276 6.60177e-05 16.3019 0.000399076C16.4005 0.000841628 16.4882 0.00172515 16.5633 0.00314815C16.7923 0.00314815 16.8958 0.00425352 17.0127 0.00949072C17.3663 0.0140679 17.7191 0.0461235 18.0785 0.107241C18.4533 0.178107 18.8165 0.306533 19.1603 0.490418C19.5063 0.678569 19.8221 0.924423 20.0939 1.21693C20.3667 1.50805 20.5951 1.84294 20.774 2.21602C20.9443 2.58132 21.0644 2.9709 21.1321 3.38269C21.1877 3.75455 21.2177 4.13025 21.2216 4.48928C21.2244 4.56512 21.2261 4.64128 21.2275 4.74278C21.2281 4.78339 21.2281 4.78339 21.2285 4.82327C21.2295 4.90074 21.23 4.93534 21.2309 4.98981L21.2308 11.9816C21.23 12.0244 21.2295 12.0591 21.2285 12.138C21.2265 12.3041 21.2251 12.3791 21.222 12.4576C21.2182 12.839 21.187 13.2196 21.1282 13.5988C21.0634 14.0045 20.9429 14.3978 20.7677 14.7724C20.5901 15.1413 20.3602 15.4788 20.0863 15.7724C19.8109 16.0679 19.4931 16.3148 19.1451 16.5035C18.7996 16.691 18.4296 16.8214 18.0449 16.8909C17.6939 16.9526 17.3392 16.9869 16.9847 16.9936C16.9195 16.9949 16.8685 16.9956 16.7549 16.9968C16.6451 16.998 16.5966 16.9986 16.525 17L9.57222 16.9999C9.51341 16.9986 9.46558 16.998 9.35697 16.9968C9.24443 16.9956 9.19398 16.9949 9.13323 16.9936C8.78017 16.9882 8.42797 16.955 8.07241 16.8929C7.69603 16.8222 7.33115 16.694 6.98049 16.5076C6.63825 16.3184 6.32543 16.0739 6.05332 15.783C6.0403 15.7691 6.02078 15.7472 5.98712 15.7094C5.98065 15.7022 5.95958 15.6793 5.9457 15.6648C5.81494 15.53 5.75681 15.4696 5.68475 15.3926C5.68475 15.3926 3.35144 12.903 3.34166 12.8937C3.28693 12.8387 3.23242 12.7807 3.18051 12.7223C3.1318 12.6727 3.08977 12.6283 3.00415 12.5369L1.17342 10.5791L0.999457 10.3934C0.952107 10.3428 0.917341 10.304 0.85862 10.2367C0.703532 10.0739 0.556882 9.9023 0.419324 9.72251C0.291227 9.57672 0.188303 9.40777 0.115405 9.22347L0.0976412 9.17253C-0.0349771 8.73535 -0.0349771 8.26465 0.113903 7.78036C0.186217 7.59412 0.289758 7.42364 0.419347 7.27727C0.556784 7.09616 0.703448 6.9246 0.842537 6.78088C0.917341 6.69602 0.952107 6.65719 0.999457 6.60664C1.08432 6.51603 1.12084 6.47655 1.17342 6.41775L3.1814 4.27386C3.21769 4.23511 3.23523 4.21646 3.25716 4.19339ZM16.2969 1.25965C16.2249 1.25932 16.167 1.25926 16.0355 1.25926L10.1118 1.25926C9.85265 1.25926 9.73674 1.25978 9.58401 1.26241C9.37072 1.26241 9.27768 1.2634 9.14844 1.26866C8.85348 1.27225 8.55918 1.29907 8.27677 1.34733C8.01191 1.39708 7.75514 1.48729 7.52288 1.61058C7.28843 1.74022 7.07414 1.90772 6.8873 2.10744C6.88578 2.10907 6.87753 2.1183 6.83998 2.16039C6.79574 2.20984 6.77593 2.23164 6.75315 2.25325C6.63567 2.37439 6.58219 2.43006 6.51873 2.49781L6.21828 2.8186L4.18346 4.99429C4.16188 5.01733 4.14006 5.03729 4.08485 5.09049C4.06571 5.11062 4.0506 5.12669 4.01539 5.16429L3.83847 5.35318L2.01796 7.29662C1.96662 7.35432 1.9255 7.39878 1.83344 7.49707C1.79725 7.53571 1.76813 7.56824 1.68326 7.66363C1.55485 7.79705 1.43425 7.93879 1.32214 8.08802L1.28194 8.13624C1.25331 8.16723 1.2297 8.20301 1.21202 8.24212C1.16631 8.40991 1.16614 8.58813 1.21151 8.756C1.23026 8.79675 1.25494 8.83412 1.28467 8.86673L1.32034 8.90959C1.43432 9.05981 1.55617 9.20301 1.7014 9.35607C1.76813 9.43176 1.79725 9.46429 1.83344 9.50293L2.00774 9.68903L3.83847 11.6468C3.92333 11.7374 3.96032 11.7764 4.02783 11.8463C4.0605 11.8833 4.09506 11.9206 4.13732 11.964C4.14624 11.9724 4.15916 11.985 4.18051 12.0057L6.51873 14.5022C6.58219 14.5699 6.63567 14.6256 6.75315 14.7468C6.77593 14.7684 6.79574 14.7902 6.84151 14.8413C6.87753 14.8817 6.88578 14.8909 6.88756 14.8928C7.07414 15.0923 7.28843 15.2598 7.51437 15.3848C7.75514 15.5127 8.01191 15.6029 8.26968 15.6514C8.56088 15.7022 8.85519 15.73 9.15352 15.7346C9.21233 15.7358 9.26016 15.7365 9.36876 15.7376C9.4813 15.7388 9.53175 15.7395 9.58401 15.7407L16.5134 15.7409C16.5786 15.7395 16.6296 15.7388 16.7432 15.7376C16.853 15.7365 16.9015 15.7358 16.9627 15.7345C17.2612 15.7289 17.5588 15.7001 17.8508 15.6488C18.1153 15.601 18.3716 15.5107 18.6109 15.3809C18.8473 15.2526 19.063 15.085 19.2503 14.884C19.4387 14.6821 19.5966 14.4503 19.7155 14.2033C19.836 13.9458 19.9202 13.6708 19.965 13.39C20.0136 13.0774 20.0395 12.7612 20.0431 12.4263C20.0461 12.3444 20.0473 12.2767 20.0492 12.1216C20.0502 12.0399 20.0507 12.0033 20.0515 11.9693L20.0516 5.0024C20.0507 4.95673 20.0502 4.92022 20.0492 4.83991C20.0487 4.80036 20.0487 4.80036 20.0482 4.76148C20.0469 4.66963 20.0455 4.60292 20.0427 4.5221C20.0391 4.20687 20.0139 3.89234 19.969 3.59095C19.9224 3.30816 19.8379 3.03402 19.7212 2.78352C19.6014 2.53389 19.4459 2.3058 19.2584 2.10572C19.0732 1.90644 18.8594 1.73995 18.6286 1.61444C18.3901 1.48689 18.1355 1.39687 17.8831 1.34904C17.5904 1.29936 17.2947 1.27249 16.982 1.2682C16.8696 1.2634 16.7766 1.26241 16.5535 1.26232C16.4739 1.2609 16.391 1.26007 16.2969 1.25965ZM15.7922 5.02058C15.5944 4.93336 15.3668 4.98211 15.2158 5.14407C15.1939 5.16773 15.1744 5.19292 15.1572 5.21933L12.838 7.69812L10.5404 5.24897C10.5188 5.21138 10.4928 5.17612 10.4627 5.14407C10.2556 4.92395 9.92083 4.92395 9.71375 5.14407C9.56147 5.30594 9.51564 5.54987 9.59765 5.76192C9.62416 5.83048 9.66235 5.89133 9.70915 5.94229L9.70195 5.95L12.0903 8.49728L9.80032 10.9449C9.76507 10.968 9.732 10.9957 9.70195 11.028C9.49578 11.2491 9.49578 11.6065 9.70195 11.8276C9.85356 11.9902 10.082 12.0391 10.2806 11.9515C10.3448 11.9232 10.4018 11.8825 10.4496 11.8325L10.4568 11.8402L12.8382 9.29491L15.2217 11.837L15.2274 11.831C15.3246 11.9344 15.4579 11.9956 15.6006 11.9956C15.8146 11.9956 16.0076 11.8578 16.0892 11.6466C16.1709 11.4353 16.1253 11.1923 15.9736 11.0311C15.9545 11.011 15.9343 10.9927 15.9133 10.9763L13.5861 8.49553L15.9706 5.94685L15.965 5.94077C16.0618 5.83697 16.1191 5.69465 16.1191 5.54231C16.1191 5.31378 15.9901 5.1078 15.7922 5.02058Z" fill="currentColor" fill-rule="evenodd" />
</svg>`;
export const keys = {
ArrowDown: 0x51,
ArrowLeft: 0x50,
ArrowRight: 0x4f,
ArrowUp: 0x52,
Backquote: 0x35,
Backslash: 0x31,
Backspace: 0x2a,
BracketLeft: 0x2f,
BracketRight: 0x30,
CapsLock: 0x39,
Comma: 0x36,
ContextMenu: 0,
Delete: 0x4c,
Digit0: 0x27,
Digit1: 0x1e,
Digit2: 0x1f,
Digit3: 0x20,
Digit4: 0x21,
Digit5: 0x22,
Digit6: 0x23,
Digit7: 0x24,
Digit8: 0x25,
Digit9: 0x26,
End: 0x4d,
Enter: 0x28,
Equal: 0x2e,
Escape: 0x29,
F1: 0x3a,
F2: 0x3b,
F3: 0x3c,
F4: 0x3d,
F5: 0x3e,
F6: 0x3f,
F7: 0x40,
F8: 0x41,
F9: 0x42,
F10: 0x43,
F11: 0x44,
F12: 0x45,
F13: 0x68,
Home: 0x4a,
Insert: 0x49,
IntlBackslash: 0x64,
KeyA: 0x04,
KeyB: 0x05,
KeyC: 0x06,
KeyD: 0x07,
KeyE: 0x08,
KeyF: 0x09,
KeyG: 0x0a,
KeyH: 0x0b,
KeyI: 0x0c,
KeyJ: 0x0d,
KeyK: 0x0e,
KeyL: 0x0f,
KeyM: 0x10,
KeyN: 0x11,
KeyO: 0x12,
KeyP: 0x13,
KeyQ: 0x14,
KeyR: 0x15,
KeyS: 0x16,
KeyT: 0x17,
KeyU: 0x18,
KeyV: 0x19,
KeyW: 0x1a,
KeyX: 0x1b,
KeyY: 0x1c,
KeyZ: 0x1d,
KeypadExclamation: 0xcf,
Minus: 0x2d,
NumLock: 0x53,
Numpad0: 0x62,
Numpad1: 0x59,
Numpad2: 0x5a,
Numpad3: 0x5b,
Numpad4: 0x5c,
Numpad5: 0x5d,
Numpad6: 0x5e,
Numpad7: 0x5f,
Numpad8: 0x60,
Numpad9: 0x61,
NumpadAdd: 0x57,
NumpadDivide: 0x54,
NumpadEnter: 0x58,
NumpadEqual: 0x67,
NumpadMultiply: 0x55,
NumpadSubtract: 0x56,
NumpadDecimal: 0x63,
PageDown: 0x4e,
PageUp: 0x4b,
Period: 0x37,
PrintScreen: 0x46,
Pause: 0x48,
Quote: 0x34,
ScrollLock: 0x47,
Semicolon: 0x33,
Slash: 0x38,
Space: 0x2c,
SystemRequest: 0x9a,
Tab: 0x2b,
} as Record<string, number>;
export const modifiers = {
ControlLeft: 0x01,
ControlRight: 0x10,
ShiftLeft: 0x02,
ShiftRight: 0x20,
AltLeft: 0x04,
AltRight: 0x40,
MetaLeft: 0x08,
MetaRight: 0x80,
} as Record<string, number>;
export const modifierDisplayMap: Record<string, string> = {
ControlLeft: "Left Ctrl",
ControlRight: "Right Ctrl",
ShiftLeft: "Left Shift",
ShiftRight: "Right Shift",
AltLeft: "Left Alt",
AltRight: "Right Alt",
MetaLeft: "Left Meta",
MetaRight: "Right Meta",
} as Record<string, string>;
export const keyDisplayMap: Record<string, string> = {
CtrlAltDelete: "Ctrl + Alt + Delete",
AltMetaEscape: "Alt + Meta + Escape",
CtrlAltBackspace: "Ctrl + Alt + Backspace",
Escape: "esc",
Tab: "tab",
Backspace: "backspace",
"(Backspace)": "backspace",
Enter: "enter",
CapsLock: "caps lock",
// ShiftLeft: "shift",
ShiftRight: "shift",
ControlLeft: "ctrl",
AltLeft: "alt",
AltRight: "alt",
MetaLeft: "meta",
MetaRight: "meta",
Space: " ",
Insert: "insert",
Home: "home",
PageUp: "page up",
Delete: "delete",
End: "end",
PageDown: "page down",
ArrowLeft: "←",
ArrowRight: "→",
ArrowUp: "↑",
ArrowDown: "↓",
// Letters
KeyA: "a", KeyB: "b", KeyC: "c", KeyD: "d", KeyE: "e",
KeyF: "f", KeyG: "g", KeyH: "h", KeyI: "i", KeyJ: "j",
KeyK: "k", KeyL: "l", KeyM: "m", KeyN: "n", KeyO: "o",
KeyP: "p", KeyQ: "q", KeyR: "r", KeyS: "s", KeyT: "t",
KeyU: "u", KeyV: "v", KeyW: "w", KeyX: "x", KeyY: "y",
KeyZ: "z",
// Capital letters
"(KeyA)": "A", "(KeyB)": "B", "(KeyC)": "C", "(KeyD)": "D", "(KeyE)": "E",
"(KeyF)": "F", "(KeyG)": "G", "(KeyH)": "H", "(KeyI)": "I", "(KeyJ)": "J",
"(KeyK)": "K", "(KeyL)": "L", "(KeyM)": "M", "(KeyN)": "N", "(KeyO)": "O",
"(KeyP)": "P", "(KeyQ)": "Q", "(KeyR)": "R", "(KeyS)": "S", "(KeyT)": "T",
"(KeyU)": "U", "(KeyV)": "V", "(KeyW)": "W", "(KeyX)": "X", "(KeyY)": "Y",
"(KeyZ)": "Z",
// Numbers
Digit1: "1", Digit2: "2", Digit3: "3", Digit4: "4", Digit5: "5",
Digit6: "6", Digit7: "7", Digit8: "8", Digit9: "9", Digit0: "0",
// Shifted Numbers
"(Digit1)": "!", "(Digit2)": "@", "(Digit3)": "#", "(Digit4)": "$", "(Digit5)": "%",
"(Digit6)": "^", "(Digit7)": "&", "(Digit8)": "*", "(Digit9)": "(", "(Digit0)": ")",
// Symbols
Minus: "-",
"(Minus)": "_",
Equal: "=",
"(Equal)": "+",
BracketLeft: "[",
"(BracketLeft)": "{",
BracketRight: "]",
"(BracketRight)": "}",
Backslash: "\\",
"(Backslash)": "|",
Semicolon: ";",
"(Semicolon)": ":",
Quote: "'",
"(Quote)": "\"",
Comma: ",",
"(Comma)": "<",
Period: ".",
"(Period)": ">",
Slash: "/",
"(Slash)": "?",
Backquote: "`",
"(Backquote)": "~",
IntlBackslash: "\\",
// Function keys
F1: "F1", F2: "F2", F3: "F3", F4: "F4",
F5: "F5", F6: "F6", F7: "F7", F8: "F8",
F9: "F9", F10: "F10", F11: "F11", F12: "F12",
// Numpad
Numpad0: "Num 0", Numpad1: "Num 1", Numpad2: "Num 2",
Numpad3: "Num 3", Numpad4: "Num 4", Numpad5: "Num 5",
Numpad6: "Num 6", Numpad7: "Num 7", Numpad8: "Num 8",
Numpad9: "Num 9", NumpadAdd: "Num +", NumpadSubtract: "Num -",
NumpadMultiply: "Num *", NumpadDivide: "Num /", NumpadDecimal: "Num .",
NumpadEqual: "Num =", NumpadEnter: "Num Enter",
NumLock: "Num Lock",
// Modals
PrintScreen: "prt sc", ScrollLock: "scr lk", Pause: "pause",
"(PrintScreen)": "sys rq", "(Pause)": "break",
SystemRequest: "sys rq", Break: "break",
};
export const keyDisplayMap2: Record<string, string> = {
...keyDisplayMap,
...{
"Backspace": delSvg,
"ShiftLeft": `<svg viewBox="0 0 20 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20.000000" height="16.000000" fill="none" customFrame="#000000">
\t<path id="Shift" d="M19.216 10.1742L14.77 10.1742L14.77 14.0332C14.77 14.111 14.77 14.1823 14.77 14.2568C14.77 14.3216 14.77 14.3832 14.7672 14.448C14.7652 14.5869 14.7521 14.7255 14.728 14.8627C14.7017 14.9989 14.6542 15.131 14.5868 15.2548C14.5178 15.3784 14.4277 15.491 14.3199 15.5885C14.2116 15.6859 14.0879 15.7678 13.9531 15.8315C13.8165 15.8925 13.6715 15.9361 13.522 15.9611C13.3722 15.9827 13.2208 15.9946 13.0691 15.9968C12.9985 15.9968 12.93 16 12.8608 16L7.14142 16C7.07081 16 7.00268 15.9968 6.93313 15.9968C6.78143 15.9946 6.63009 15.9827 6.4802 15.9611C6.33087 15.9361 6.18597 15.8925 6.04951 15.8315C5.91466 15.7678 5.79101 15.6859 5.68271 15.5885C5.57484 15.4911 5.48473 15.3784 5.41582 15.2548C5.34844 15.131 5.30088 14.9989 5.27461 14.8627C5.25033 14.7255 5.23711 14.5869 5.23507 14.448C5.23507 14.3832 5.23225 14.3216 5.23225 14.2568C5.23225 14.1823 5.23225 14.111 5.23225 14.0332L5.23225 10.1742L0.715969 10.1742C0.259151 10.1742 -0.326874 9.27015 0.22173 8.76792C0.68808 8.34346 8.01763 1.63629 9.55154 0.239773C9.66425 0.112636 9.82346 0.0274241 9.99953 0L10.0115 0C10.1638 0.00758178 10.3053 0.0748465 10.3999 0.18469C11.9338 1.58121 19.2884 8.34346 19.7551 8.76792C20.304 9.27015 19.8444 10.1742 19.216 10.1742Z" fill="currentColor" fill-rule="evenodd" />
</svg>
`,
Space: "Space",
},
};
export const sKeyDisplayMap: Record<string, string> = {
Escape: "Esc",
Tab: "Tab",
MetaLeft: "Meta",
PageUp: "PgUp",
ArrowUp: "↑",
PageDown: "PgDn",
Delete: "Del",
ShiftLeft: "Shift",
ControlLeft: "Ctrl",
AltLeft: "Alt",
ArrowLeft: "←",
ArrowDown: "↓",
ArrowRight: "→",
Back: "▼",
};