MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / keyToString

Function keyToString

packages/core/src/keybindings/parser.ts:276–307  ·  view source on GitHub ↗
(key: ParsedKey)

Source from the content-addressed store, hash-verified

274 * @returns String representation like "ctrl+a" or "escape"
275 */
276export function keyToString(key: ParsedKey): string {
277 const parts: string[] = [];
278
279 if (key.mods.ctrl) parts.push("ctrl");
280 if (key.mods.alt) parts.push("alt");
281 if (key.mods.shift) parts.push("shift");
282 if (key.mods.meta) parts.push("meta");
283
284 // Find key name
285 let keyName: string | undefined;
286
287 for (const [name, code] of KEY_NAME_TO_CODE) {
288 if (code === key.key) {
289 keyName = name;
290 break;
291 }
292 }
293
294 if (keyName === undefined) {
295 // Try to convert from ASCII
296 if (key.key >= 65 && key.key <= 90) {
297 keyName = String.fromCharCode(key.key).toLowerCase();
298 } else if (key.key >= 48 && key.key <= 57) {
299 keyName = String.fromCharCode(key.key);
300 } else {
301 keyName = `key${String(key.key)}`;
302 }
303 }
304
305 parts.push(keyName);
306 return parts.join("+");
307}
308
309/**
310 * Convert a KeySequence to a human-readable string (for debugging).

Callers 3

getPendingChordFunction · 0.85
parser.test.tsFile · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected