mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
guh
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>webui</title>
|
<title>webui</title>
|
||||||
<script type="module" crossorigin src="/assets/index-BVmkkCJ8.js"></script>
|
<script type="module" crossorigin src="/assets/index-DlSe_rwF.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-BaCUS21F.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-BaCUS21F.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -28,6 +28,20 @@ const CODE_ALIASES = {
|
|||||||
Slash: '/',
|
Slash: '/',
|
||||||
Minus: '-',
|
Minus: '-',
|
||||||
Equal: '=',
|
Equal: '=',
|
||||||
|
Backquote: '`',
|
||||||
|
};
|
||||||
|
const SPECIAL_CODE_FROM_KEY = {
|
||||||
|
'[': 'BracketLeft',
|
||||||
|
']': 'BracketRight',
|
||||||
|
'\\': 'Backslash',
|
||||||
|
';': 'Semicolon',
|
||||||
|
"'": 'Quote',
|
||||||
|
',': 'Comma',
|
||||||
|
'.': 'Period',
|
||||||
|
'/': 'Slash',
|
||||||
|
'-': 'Minus',
|
||||||
|
'=': 'Equal',
|
||||||
|
'`': 'Backquote',
|
||||||
};
|
};
|
||||||
|
|
||||||
function shouldIgnoreEvent(event) {
|
function shouldIgnoreEvent(event) {
|
||||||
@@ -48,10 +62,33 @@ function canonicalizeBinding(value) {
|
|||||||
return KEY_ALIASES[lower] ?? lower;
|
return KEY_ALIASES[lower] ?? lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deriveCodeFromKey(key) {
|
||||||
|
if (!key) return null;
|
||||||
|
if (SPECIAL_CODE_FROM_KEY[key]) return SPECIAL_CODE_FROM_KEY[key];
|
||||||
|
if (key.length === 1) {
|
||||||
|
if (key >= 'a' && key <= 'z') {
|
||||||
|
return `Key${key.toUpperCase()}`;
|
||||||
|
}
|
||||||
|
if (key >= '0' && key <= '9') {
|
||||||
|
return `Digit${key}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key === 'shift') return null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeKeymap(keymap = {}) {
|
function normalizeKeymap(keymap = {}) {
|
||||||
const entries = Object.entries(keymap).map(([action, bindings]) => {
|
const entries = Object.entries(keymap).map(([action, bindings]) => {
|
||||||
const values = Array.isArray(bindings) ? bindings : [bindings];
|
const values = Array.isArray(bindings) ? bindings : [bindings];
|
||||||
const normalized = new Set(values.map((value) => canonicalizeBinding(String(value))));
|
const normalized = new Set();
|
||||||
|
values.forEach((value) => {
|
||||||
|
const canonical = canonicalizeBinding(String(value));
|
||||||
|
if (canonical) {
|
||||||
|
normalized.add(canonical);
|
||||||
|
const derivedCode = deriveCodeFromKey(canonical);
|
||||||
|
if (derivedCode) normalized.add(derivedCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
return [action, normalized];
|
return [action, normalized];
|
||||||
});
|
});
|
||||||
return Object.fromEntries(entries);
|
return Object.fromEntries(entries);
|
||||||
@@ -236,12 +273,14 @@ export default function KeyboardInputManager() {
|
|||||||
function handleKeyDown(event) {
|
function handleKeyDown(event) {
|
||||||
if (shouldIgnoreEvent(event)) return;
|
if (shouldIgnoreEvent(event)) return;
|
||||||
const key = canonicalizeEventKey(event);
|
const key = canonicalizeEventKey(event);
|
||||||
|
const codeToken = event.code;
|
||||||
if (!key) return;
|
if (!key) return;
|
||||||
if (actionKeys.has(key)) {
|
if (actionKeys.has(key) || (codeToken && actionKeys.has(codeToken))) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
if (!pressedKeysRef.current.has(key)) {
|
pressedKeysRef.current.add(key);
|
||||||
pressedKeysRef.current.add(key);
|
if (codeToken) {
|
||||||
|
pressedKeysRef.current.add(codeToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindingHas(keymap.driveMacro, key)) {
|
if (bindingHas(keymap.driveMacro, key)) {
|
||||||
@@ -263,23 +302,21 @@ export default function KeyboardInputManager() {
|
|||||||
|
|
||||||
function handleKeyUp(event) {
|
function handleKeyUp(event) {
|
||||||
const key = canonicalizeEventKey(event);
|
const key = canonicalizeEventKey(event);
|
||||||
if (!key || !pressedKeysRef.current.has(key)) {
|
const codeToken = event.code;
|
||||||
if (bindingHas(keymap.cameraUp, key)) {
|
if (key) {
|
||||||
cameraHoldRef.current.delete('up');
|
pressedKeysRef.current.delete(key);
|
||||||
updateServoHold();
|
}
|
||||||
} else if (bindingHas(keymap.cameraDown, key)) {
|
if (codeToken) {
|
||||||
cameraHoldRef.current.delete('down');
|
pressedKeysRef.current.delete(codeToken);
|
||||||
updateServoHold();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pressedKeysRef.current.delete(key);
|
if (bindingHas(keymap.cameraUp, key) || (codeToken && bindingHas(keymap.cameraUp, codeToken))) {
|
||||||
|
|
||||||
if (bindingHas(keymap.cameraUp, key)) {
|
|
||||||
cameraHoldRef.current.delete('up');
|
cameraHoldRef.current.delete('up');
|
||||||
updateServoHold();
|
updateServoHold();
|
||||||
} else if (bindingHas(keymap.cameraDown, key)) {
|
} else if (
|
||||||
|
bindingHas(keymap.cameraDown, key) ||
|
||||||
|
(codeToken && bindingHas(keymap.cameraDown, codeToken))
|
||||||
|
) {
|
||||||
cameraHoldRef.current.delete('down');
|
cameraHoldRef.current.delete('down');
|
||||||
updateServoHold();
|
updateServoHold();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user