feat: add configurable ignore_keys setting to filter key events#2047
feat: add configurable ignore_keys setting to filter key events#2047tjasko wants to merge 1 commit into
ignore_keys setting to filter key events#2047Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
|
||
| #noVNC_setting_ignore_keys.noVNC_invalid, | ||
| #noVNC_setting_ignore_keys.noVNC_invalid:focus { | ||
| border-color: var(--novnc-red); |
There was a problem hiding this comment.
I don't see why we need our own color for this, regular "red" looks fine.
| } | ||
| } else { | ||
| ctrl.value = value; | ||
| ctrl.value = value ?? ''; |
| UI.rfb.sendKey(keysym, code, down); | ||
| }, | ||
|
|
||
| wrapRfbSendKey() { |
| UI.addSettingChangeHandler('reconnect_delay'); | ||
| UI.addSettingChangeHandler('ignore_keys'); | ||
| const input = document.getElementById('noVNC_setting_ignore_keys'); | ||
| if (input && !input.dataset.validationBound) { |
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
The changes to this function makes no sense to me - saveSetting() doesn't ever seem to be called with an event?
| </label> | ||
| </li> | ||
| <li><hr></li> | ||
| <li class="noVNC_setting"> |
There was a problem hiding this comment.
Most users won't need this, I think it fits best under the "advanced" section of the settings.
| <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> |
There was a problem hiding this comment.
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 
 we can have line breaks in the title attribute.)
Overview
Introduce a new
ignore_keyssetting 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:
ignore_keysare handled locally & not sent to the VMImplementation details:
supportedIgnoreKeysnormalizeIgnoreKey()to map aliases to canonical codeswrapRfbSendKey()to intercept and filter outgoing key eventskeyEvent()to delegate torfb.sendKeyUI changes:
ignore_keysinput to settings panelTests:
shouldIgnoreKey()including aliases, normalization, whitespace handling, and edge casessendKeybehavior to ensure filtering workskeyEvent()tests to reflect pass-through behaviorThis change improves usability when interacting with fullscreen mode and other browser-level shortcuts, while remaining backward compatible.