From 6b09c1b576609e6f2dc2f70b9e1a57b4ccea0467 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 30 Nov 2022 07:06:28 -0800 Subject: [PATCH] Add custom keymap example to attachCustomKeyEventHandler docs Fixes #4278 --- typings/xterm.d.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index aec0fdbc..926cc6b4 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -867,6 +867,24 @@ declare module 'xterm' { * This is a function that takes a KeyboardEvent, allowing consumers to stop * propagation and/or prevent the default action. The function returns * whether the event should be processed by xterm.js. + * + * @example A custom keymap that overrides the backspace key + * ```ts + * const keymap = [ + * { "key": "Backspace", "shiftKey": false, "mapCode": 8 }, + * { "key": "Backspace", "shiftKey": true, "mapCode": 127 } + * ]; + * term.attachCustomKeyEventHandler(ev => { + * if (ev.type === 'keydown') { + * for (let i in keymap) { + * if (keymap[i].key == ev.key && keymap[i].shiftKey == ev.shiftKey) { + * socket.send(String.fromCharCode(keymap[i].mapCode)); + * return false; + * } + * } + * } + * }); + * ``` */ attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;