Skip to content

feat: add configurable ignore_keys setting to filter key events - #2047

Open
tjasko wants to merge 2 commits into
novnc:masterfrom
tjasko:feat/ignore-keyboard-keys
Open

tjasko wants to merge 2 commits into
novnc:masterfrom
tjasko:feat/ignore-keyboard-keys

Conversation

@tjasko

@tjasko tjasko commented Mar 28, 2026

Copy link
Copy Markdown

Overview

Introduce a new ignore_keys setting that allows users to prevent specific keyboard inputs from being forwarded to the remote VNC host, while still allowing the browser to handle them locally.

This addresses common UX issues where browser level shortcuts (for example Escape to exit fullscreen) are also sent to the VM, potentially interrupting workflows or triggering unintended actions.

Key behavior:

  • Keys listed in ignore_keys are handled locally and never sent to the server
  • The default is empty, so no keys are ignored and existing behavior is unchanged
  • The value is a comma separated list, with surrounding whitespace tolerated
  • Aliases are accepted, for example "esc", "ctrl" and "cmd", and are mapped to canonical codes
  • Matching is case insensitive

Implementation details:

  • supportedIgnoreKeys centralizes the keys that can be ignored, along with their aliases
  • normalizeIgnoreKey() maps an alias or label to its canonical form
  • shouldIgnoreKey() checks a key code against the current setting
  • filterIgnoredKeys() wraps rfb.sendKey() when a connection is set up, so that ignored keys are dropped before reaching the server
  • validateIgnoreKeysInput() flags unrecognized entries as the setting is changed

UI changes:

  • New "Ignored keys" text input under the "Advanced" section of the settings panel
  • The supported keys are documented through the input's title attribute, using 
 for line breaks
  • Invalid entries are marked with a red border

Tests:

  • New tests/test.ui.js covering shouldIgnoreKey(), verifying that aliases resolve to the right key and that keys outside supportedIgnoreKeys are never ignored
  • app/ui.js added to the files served by karma, so that it can be imported from tests

Known limitation: filtering happens inside rfb.sendKey(), which is also the path used by the keyboard toolbar buttons. Ignoring esc therefore also disables the toolbar Esc button, and ignoring ctrl, alt or del breaks the Ctrl+Alt+Del button. Filtering in Keyboard._handleKeyEvent() instead would avoid this, at the cost of a change in core.

This change improves usability when interacting with fullscreen mode and other browser level shortcuts, while remaining backward compatible.

Introduce a new `ignore_keys` setting that allows users to prevent
specific keyboard inputs from being forwarded to the remote VNC host
while still allowing the browser/client to handle them locally.

This addresses common UX issues where browser-level shortcuts (e.g.
Escape to exit fullscreen or F11 for fullscreen toggle) are also sent
to the VM, potentially interrupting workflows or triggering unintended
actions.

Key behavior:
- Keys listed in `ignore_keys` are handled locally & not sent to the VM
- Default value is to not ignore any key events
- Supports comma-separated input with whitespace tolerance
- Accepts aliases (e.g. "esc", "ctrl", "cmd") mapped to canonical codes
- Matching is case-insensitive and normalized

Implementation details:
- Centralized supported keys via `supportedIgnoreKeys`
- Added `normalizeIgnoreKey()` to map aliases to canonical codes
- Introduced `wrapRfbSendKey()` to intercept and filter outgoing key
  events
- Simplified `keyEvent()` to delegate to `rfb.sendKey`
- Added validation for user input with visual feedback on invalid
  entries
- Added dynamic tooltip and placeholder generation from supported
  key list

UI changes:
- Added `ignore_keys` input to settings panel
- Added tooltip with supported key examples
- Added inline validation styling for invalid entries

Tests:
- Added coverage for `shouldIgnoreKey()` including aliases,
  normalization, whitespace handling, and edge cases
- Added tests for wrapped `sendKey` behavior to ensure filtering works
- Updated `keyEvent()` tests to reflect pass-through behavior
- Added validation and helper function tests

This change improves usability when interacting with fullscreen mode
and other browser-level shortcuts, while remaining backward compatible.

@samhed samhed left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing! I think this could be a useful feature in some cases.

I tested it in Chrome 145 on Fedora 43. Functionally, it works as advertised.

The code needs some work though, see the comments.

Comment thread app/styles/base.css Outdated

#noVNC_setting_ignore_keys.noVNC_invalid,
#noVNC_setting_ignore_keys.noVNC_invalid:focus {
border-color: var(--novnc-red);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we need our own color for this, regular "red" looks fine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, there was no need for it. I dropped both the --novnc-red-rgb and --novnc-red variables and used plain red instead. I also removed the box-shadow, the border colour on its own is enough to signal an invalid entry.

Comment thread app/ui.js Outdated
}
} else {
ctrl.value = value;
ctrl.value = value ?? '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over from an earlier iteration where the setting could still be undefined. It serves no purpose now, so I reverted it back to ctrl.value = value.

Comment thread app/ui.js Outdated
UI.rfb.sendKey(keysym, code, down);
},

wrapRfbSendKey() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filterIgnoredKeys() ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to filterIgnoredKeys(). While doing so I also dropped the _ignoreKeysWrapped guard, since the function only runs immediately after a fresh RFB object is created and so there was never anything to guard against.

Comment thread app/ui.js Outdated
UI.addSettingChangeHandler('reconnect_delay');
UI.addSettingChangeHandler('ignore_keys');
const input = document.getElementById('noVNC_setting_ignore_keys');
if (input && !input.dataset.validationBound) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you added this validationBound attribute? I can't see any reason for why these two handlers need such a guard if no others do.

We should probably get rid of the "if" and the variable as well and follow the style of the other handlers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, there was no reason for it. I removed the guard, the variable and the two manual listeners. Validation is now registered with UI.addSettingChangeHandler("ignore_keys", UI.validateIgnoreKeysInput), exactly like the other settings.

Comment thread app/ui.js Outdated
const ctrl = document.getElementById('noVNC_setting_' + name);
// Update cookie and form control setting. If value is not set, then
// updates from control to current cookie setting.
saveSetting(nameOrEvent) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this function makes no sense to me - saveSetting() doesn't ever seem to be called with an event?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it never is. This was left over from the earlier validation handling, which at one point passed the event through. Since that is gone, I reverted saveSetting() and updateSetting() back to their original form.

Comment thread vnc.html Outdated
</label>
</li>
<li><hr></li>
<li class="noVNC_setting">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most users won't need this, I think it fits best under the "advanced" section of the settings.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, moved it into the "Advanced" section, just below the Repeater ID field.

Comment thread vnc.html Outdated
<div class="noVNC_setting_with_help">
<label for="noVNC_setting_ignore_keys">Ignored Keys:</label>

<button id="noVNC_ignore_keys_help_button" type="button">?</button>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This large circled question mark doesn't fit the rest of our interface. I'd also like to avoid infrastructure for tooltips.

Couldn't we simply use the html "title" attribute to get almost the same? (With &#013; we can have line breaks in the title attribute.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The help button, the tooltip element, its CSS and the JavaScript that built it are all gone, replaced by a plain title attribute on the input using &#013; for the line breaks. That also let me remove initIgnoreKeysTooltip(), buildIgnoreKeysTooltipText() and buildIgnoreKeysPlaceholder(). The supported keys are now listed directly in vnc.html, along with a short placeholder on the input itself.

- Move the setting into the "Advanced" section, where it fits better
  since most users won't need it.
- Replace the custom tooltip (help button, CSS, and JS) with a plain
  "title" attribute, using &novnc#13; for line breaks.
- Use plain "red" for the invalid input border instead of adding a
  dedicated colour variable.
- Rename wrapRfbSendKey() to filterIgnoredKeys() and drop the
  unnecessary guard.
- Revert the unrelated changes to saveSetting() and updateSetting().
- Register the validation handler via addSettingChangeHandler(), like
  every other setting, instead of a custom guarded listener.
@tjasko
tjasko requested a review from samhed September 12, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants