MCPcopy Create free account
hub / github.com/Noumena-Network/code / keycodeToName

Function keycodeToName

src/ink/parse-keypress.ts:491–545  ·  view source on GitHub ↗

* Map keycode to key name for modifyOtherKeys/CSI u sequences. * Handles both ASCII keycodes and Kitty keyboard protocol functional keys. * * Numpad codepoints are from Unicode Private Use Area, defined at: * https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions

(keycode: number)

Source from the content-addressed store, hash-verified

489 * https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions
490 */
491function keycodeToName(keycode: number): string | undefined {
492 switch (keycode) {
493 case 9:
494 return 'tab'
495 case 13:
496 return 'return'
497 case 27:
498 return 'escape'
499 case 32:
500 return 'space'
501 case 127:
502 return 'backspace'
503 // Kitty keyboard protocol numpad keys (KP_0 through KP_9)
504 case 57399:
505 return '0'
506 case 57400:
507 return '1'
508 case 57401:
509 return '2'
510 case 57402:
511 return '3'
512 case 57403:
513 return '4'
514 case 57404:
515 return '5'
516 case 57405:
517 return '6'
518 case 57406:
519 return '7'
520 case 57407:
521 return '8'
522 case 57408:
523 return '9'
524 case 57409: // KP_DECIMAL
525 return '.'
526 case 57410: // KP_DIVIDE
527 return '/'
528 case 57411: // KP_MULTIPLY
529 return '*'
530 case 57412: // KP_SUBTRACT
531 return '-'
532 case 57413: // KP_ADD
533 return '+'
534 case 57414: // KP_ENTER
535 return 'return'
536 case 57415: // KP_EQUAL
537 return '='
538 default:
539 // Printable ASCII characters
540 if (keycode >= 32 && keycode <= 126) {
541 return String.fromCharCode(keycode).toLowerCase()
542 }
543 return undefined
544 }
545}
546
547export type ParsedKey = {
548 kind: 'key'

Callers 1

parseKeypressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected