mirror of
https://github.com/siddharthvaddem/openscreen.git
synced 2026-08-29 03:08:30 +08:00
fix: convert special keys to valid Electron accelerators
Maps KeyboardEvent.key values (e.g., "ArrowDown", " ") to their Electron accelerator equivalents (e.g., "Down", "Space") to prevent global shortcut registration failures.
This commit is contained in:
@@ -5,12 +5,34 @@ import { SHORTCUTS_FILE } from "./ipc/handlers";
|
||||
|
||||
const DEFAULT_OPEN_APP_BINDING: ShortcutBinding = { key: "o", ctrl: true, shift: true };
|
||||
|
||||
// Maps KeyboardEvent.key values to Electron accelerator key names
|
||||
const KEY_TO_ACCELERATOR: Record<string, string> = {
|
||||
" ": "Space",
|
||||
"+": "Plus",
|
||||
"-": "numsub",
|
||||
"*": "nummult",
|
||||
"/": "numdiv",
|
||||
arrowup: "Up",
|
||||
arrowdown: "Down",
|
||||
arrowleft: "Left",
|
||||
arrowright: "Right",
|
||||
escape: "Escape",
|
||||
enter: "Return",
|
||||
backspace: "Backspace",
|
||||
delete: "Delete",
|
||||
tab: "Tab",
|
||||
};
|
||||
|
||||
function bindingToAccelerator(binding: ShortcutBinding): string {
|
||||
const parts: string[] = [];
|
||||
if (binding.ctrl) parts.push("CommandOrControl");
|
||||
if (binding.shift) parts.push("Shift");
|
||||
if (binding.alt) parts.push("Alt");
|
||||
parts.push(binding.key.toUpperCase());
|
||||
|
||||
const keyLower = binding.key.toLowerCase();
|
||||
const acceleratorKey = KEY_TO_ACCELERATOR[keyLower] ?? binding.key.toUpperCase();
|
||||
parts.push(acceleratorKey);
|
||||
|
||||
return parts.join("+");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user