Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture ctrl/meta/shift key modifiers in "data" event. #1884

Closed
brianjenkins94 opened this issue Jan 6, 2019 · 1 comment
Closed

Capture ctrl/meta/shift key modifiers in "data" event. #1884

brianjenkins94 opened this issue Jan 6, 2019 · 1 comment
Labels
type/question A question on how to use the library

Comments

@brianjenkins94
Copy link

brianjenkins94 commented Jan 6, 2019

As far as I can tell xterm.js does not offer a solution to detect key combinations with ctrl, meta or shift modifiers.

The Node.js process.stdin.on("keypress" event returns two variables: ch and key, per keypress:

ch: c
key: { sequence: 'c',
  name: 'c',
  ctrl: false,
  meta: false,
  shift: false }

for c

ch:
key{ sequence: '\u0003',
  name: 'c',
  ctrl: true,
  meta: false,
  shift: false }

for ctrl + c.

Is there a way to get the same sort of data from xterm.js? Is there a generally accepted workaround?

@Tyriar
Copy link
Member

Tyriar commented Jan 7, 2019

@brianjenkins94 you should be able to do this by recording the raw key events by hooking up this function and allowing all events to go through:

xterm.js/typings/xterm.d.ts

Lines 462 to 471 in 0b8c320

/**
* Attaches a custom key event handler which is run before keys are
* processed, giving consumers of xterm.js ultimate control as to what keys
* should be processed by the terminal and what keys should not.
* @param customKeyEventHandler The custom KeyboardEvent handler to attach.
* 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.
*/
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question A question on how to use the library
Projects
None yet
Development

No branches or pull requests

2 participants