lib/input
Keyboard, pointer, touch, wheel and gamepad capture on the stream element, sent to the server as the text messages of the input protocol.
Keyboard: every event resolves to an X11 keysym through noVNC's key tables
and KeyboardUtil, and what is held server-side is tracked per physical
code so a keyup releases what its keydown pressed. While anything is held a
kh heartbeat repeats the held keysyms so the server can release keys whose
keyup was lost, and modifiers a trusted event reports up are healed. IME
composition streams the preedit as momentary presses diffed per codepoint;
a shortcut chord pressed mid-composition is held until the commit lands so
it applies after the text. A soft keyboard types into the off-screen assist
field, whose value is mirrored to the server by the same diff and emptied
once nothing composes in it. Chords on non-Latin layouts resolve from the
physical key position, and a chord whose modifier keydown never reached the
server is sent self-contained, wrapped in the missing modifiers. macOS
Command is remapped onto Control, and Windows defers a ControlLeft keydown
briefly to tell AltGr apart.
Pointer: absolute positions map through the presenting sink (the canvas or
<video> box) where the stream has a fixed size, and through the element's
window math otherwise; motion is coalesced to one send per animation frame.
Under pointer lock the payload is a relative delta, scaled to server pixels
and quantized with a carried remainder. Gaming mode is document fullscreen
plus pointer and keyboard lock. Touch is direct (tap, drag, long-press right
click, two-finger scroll) or a trackpad emulation. Wheel events are
classified as discrete wheel or trackpad and accumulated in fractional
notches so no distance is lost. The server-drawn cursor is painted on a
page canvas or applied as a CSS cursor.
Wire messages: kd,<keysym>, ku,<keysym>, kh,<keysym>,..., kr;
m,<x>,<y>,<mask>,<magnitude> (absolute) and
m2,<dx>,<dy>,<mask>,<magnitude> (relative; scroll pulses ride mask bits
3 to 7); p,<0|1> and SET_NATIVE_CURSOR_RENDERING,<0|1> on pointer lock
changes; js,c, js,d, js,b, js,a and js,h for gamepads.
Classes
Input
Defined in: lib/input.js:1347
Captures input on the stream element and sends it to the server.
One instance is live per page: attach detaches any previous one. Hotkeys:
Ctrl+Shift+M opens the dashboard menu (onmenuhotkey), Ctrl+Shift+F enters
plain fullscreen (onfullscreenhotkey, enterFullscreen by default),
Ctrl+Shift+X toggles gaming mode (ongaminghotkey, toggleGamingMode by
default), Ctrl+Shift+G toggles the gamepad overlay (ongamepadhotkey), and
Ctrl+Shift+Click takes pointer lock; shortcutsEnabled false passes every
one of them to the session instead. Three quick Escape presses in a row
also leave gaming mode (_escapeHatch), whatever that flag says. Elements carrying the
allow-native-input class keep native keyboard and touch handling.
Constructors
Constructor
new Input(
element,
send,
isSharedMode?,
playerIndex?,
useCssScaling?,
initialSlot?
): Input;Defined in: lib/input.js:1356
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
element | HTMLElement | undefined | Overlay element the stream input lands on; it also hosts IME composition. |
send | (message) => void | undefined | Sends one input protocol message to the server. |
isSharedMode? | boolean | false | Viewer-only session: listeners are limited to suppressing touch defaults. |
playerIndex? | number | 0 | Gamepad slot used while the server has assigned no controller slot. |
useCssScaling? | boolean | false | Whether the stream is realized in CSS pixels, so no device pixel ratio applies. |
initialSlot? | number | null | One-based controller slot assigned by the server. |
Returns
Properties
element
element: HTMLElement;Defined in: lib/input.js:1357
send
send: (message) => void;Defined in: lib/input.js:1358
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
void
sendMotion
sendMotion: (message) => void;Defined in: lib/input.js:1365
Sends coalesced pointer motion where the transport has a channel that
keeps no order for it, so a lost sample holds nothing behind it; null
sends motion through send like every other message.
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
void
isSharedMode
isSharedMode: boolean;Defined in: lib/input.js:1368
controllerSlot
controllerSlot: number;Defined in: lib/input.js:1369
playerIndex
playerIndex: number;Defined in: lib/input.js:1370
cursorDiv
cursorDiv: HTMLCanvasElement;Defined in: lib/input.js:1371
cursorImg
cursorImg: CanvasRenderingContext2D;Defined in: lib/input.js:1378
cursorHotspot
cursorHotspot: object;Defined in: lib/input.js:1380
x
x: number = 0;y
y: number = 0;use_browser_cursors
use_browser_cursors: boolean;Defined in: lib/input.js:1384
useCssScaling
useCssScaling: boolean;Defined in: lib/input.js:1387
m
m: object;Defined in: lib/input.js:1389
mouseMultiX
mouseMultiX: number;mouseMultiY
mouseMultiY: number;mouseOffsetX
mouseOffsetX: number = offsetX;mouseOffsetY
mouseOffsetY: number = offsetY;elementClientX
elementClientX: number = elementRect.left;elementClientY
elementClientY: number = elementRect.top;frameW
frameW: number;frameH
frameH: number;buttonMask
buttonMask: number;Defined in: lib/input.js:1402
gamepadManager
gamepadManager: GamepadManager;Defined in: lib/input.js:1403
x
x: number;Defined in: lib/input.js:1404
y
y: number;Defined in: lib/input.js:1405
onmenuhotkey
onmenuhotkey: any;Defined in: lib/input.js:1411
gamingMode
gamingMode: boolean;Defined in: lib/input.js:1412
shortcutsEnabled
shortcutsEnabled: boolean;Defined in: lib/input.js:1413
ongamingmode
ongamingmode: any;Defined in: lib/input.js:1416
onnotice
onnotice: any;Defined in: lib/input.js:1417
onfullscreenhotkey
onfullscreenhotkey: () => void;Defined in: lib/input.js:1418
Fullscreen with no lock, leaving the pointer and the keyboard to the browser: the dashboard button and the Ctrl+Shift+F chord land here. The whole document goes fullscreen, not the stream container: the dashboard overlay is a body-level sibling, which container fullscreen would hide.
Returns
void
ongaminghotkey
ongaminghotkey: () => void;Defined in: lib/input.js:1419
Gaming mode on the Ctrl+Shift+X chord. Leaving it drops fullscreen, which is what releases both locks through the fullscreenchange handler; a mode left set without fullscreen (a refused request) is cleared directly.
Returns
void
ongamepadhotkey
ongamepadhotkey: any;Defined in: lib/input.js:1420
ongamepadconnected
ongamepadconnected: any;Defined in: lib/input.js:1421
ongamepaddisconnected
ongamepaddisconnected: any;Defined in: lib/input.js:1422
listeners
listeners: any[];Defined in: lib/input.js:1423
listeners_context
listeners_context: any[];Defined in: lib/input.js:1424
cursorScaleFactor
cursorScaleFactor: any;Defined in: lib/input.js:1455
isComposing
isComposing: boolean;Defined in: lib/input.js:1478
compositionString
compositionString: string;Defined in: lib/input.js:1479
keyboardInputAssist
keyboardInputAssist: HTMLElement;Defined in: lib/input.js:1493
inputAttached
inputAttached: boolean;Defined in: lib/input.js:1516
rawPointerMotion
static rawPointerMotion: boolean;Defined in: lib/input.js:1554
Whether pointer lock asks for raw movement: the raw_pointer_motion
setting, which the core resolves and pushes through setRawPointerMotion.
Until it does, the platform decides: off on macOS, where the engine grants
the option instead of refusing it and nothing replaces the acceleration
curve it takes away. The client scales a locked delta by the stream box
and quantizes it (_relativeToServer), but that gain is the same at every
speed, so the slow motion the curve used to expand now covers far less of
the remote screen and the pointer feels heavy. Windows grants it as well
and is left on it: raw deltas are what pointer lock is for, and nobody has
reported the same there.
macCmdAsCtrl
static macCmdAsCtrl: boolean = true;Defined in: lib/input.js:1565
Whether a macOS Command chord reaches the session as its Control chord:
the mac_cmd_as_ctrl setting, which the core pushes through
setMacCmdAsCtrl. On by default, so Cmd+C copies in the remote
application the way it does locally. Off sends Command as the Super it
physically is, which is what a session whose window manager takes Super
as its own modifier needs: remapped, its Cmd+Return arrives as
Ctrl+Return and its Cmd+C interrupts the foreground program.
Methods
setSharedMode()
setSharedMode(enabled): void;Defined in: lib/input.js:1520
Sets whether this is a viewer-only session.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
updateControllerSlot()
updateControllerSlot(newSlot): void;Defined in: lib/input.js:1525
Assigns the one-based controller slot the server gave this client.
Parameters
| Parameter | Type |
|---|---|
newSlot | any |
Returns
void
updateServerCursor()
updateServerCursor(cursorData): Promise<void>;Defined in: lib/input.js:1675
Applies a cursor update from the server; an empty or null-handle update, and trackpad mode, hide the cursor.
Parameters
| Parameter | Type | Description |
|---|---|---|
cursorData | { curdata?: string; handle: string | number; hotx?: string | number; hoty?: string | number; } | Base64 PNG and hotspot as the server sends them. |
cursorData.curdata? | string | - |
cursorData.handle | string | number | - |
cursorData.hotx? | string | number | - |
cursorData.hoty? | string | number | - |
Returns
Promise<void>
setSynth()
setSynth(isSynth): void;Defined in: lib/input.js:1708
Marks input as synthetic (tests), which disables the keydown stuck-modifier heal.
Parameters
| Parameter | Type |
|---|---|
isSynth | any |
Returns
void
updateCssScaling()
updateCssScaling(newUseCssScalingValue): void;Defined in: lib/input.js:1714
Switches CSS-pixel scaling and re-derives the window math and cursor.
Parameters
| Parameter | Type |
|---|---|
newUseCssScalingValue | any |
Returns
void
resetKeyboard()
resetKeyboard(): void;Defined in: lib/input.js:1847
Releases every held key and stops the heartbeat. The armed Windows AltGr timer is canceled so it cannot synthesize a Control keydown after the reset, while the page is hidden or detached.
Returns
void
setDisplayLayouts()
setDisplayLayouts(layouts, ownId): void;Defined in: lib/input.js:3144
Sets the extended-desktop layout the mapping above uses: display
rectangles in remote pixels, keyed by display id, each carrying the
owning page's CSS-to-remote scale where known, and its stream box in
desktop coordinates where that page has published one. Fewer than two
valid rectangles (or no entry for ownId) disables cross-display
mapping.
Parameters
| Parameter | Type | Description |
|---|---|---|
layouts | { } | - |
ownId | string | Display id this page renders. |
Returns
void
setStreamDensity()
setStreamDensity(density): void;Defined in: lib/input.js:3323
Sets the density the core streams this page at, or null to derive it from the page's own; the window math and cursor follow it.
Parameters
| Parameter | Type | Description |
|---|---|---|
density | number | Stream pixels per CSS pixel. |
Returns
void
setTrackpadMode()
setTrackpadMode(enabled): void;Defined in: lib/input.js:3433
Switches trackpad emulation, clearing touch state and any held button.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
setRawPointerMotion()
setRawPointerMotion(enabled): void;Defined in: lib/input.js:3475
Applies the raw pointer motion setting. A lock the stream already holds is re-requested with the new option, which switches the running lock in place on engines that allow it rather than deferring the change to the next lock; an engine that refuses the option falls back the way a first request does.
Parameters
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | - |
Returns
void
setShortcutsEnabled()
setShortcutsEnabled(enabled): void;Defined in: lib/input.js:3496
Whether the client keeps its own chords rather than passing them on.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
setMacCmdAsCtrl()
setMacCmdAsCtrl(enabled): void;Defined in: lib/input.js:3500
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
setUseBrowserCursors()
setUseBrowserCursors(enabled): Promise<void>;Defined in: lib/input.js:3514
Switches between the CSS cursor and the page-drawn cursor canvas.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
Promise<void>
getWindowResolution()
getWindowResolution(): number[];Defined in: lib/input.js:4285
The page size in device pixels, rounded down to even.
Returns
number[]
Width and height.
resize()
resize(): void;Defined in: lib/input.js:4295
Re-derives the window math after a layout change.
Returns
void
isInputAttached()
isInputAttached(): boolean;Defined in: lib/input.js:4300
True while the full input context is attached.
Returns
boolean
attach()
attach(): void;Defined in: lib/input.js:4314
Attaches the window and document listeners, and the input context
unless this is a viewer-only session. Any previously attached instance
is detached first: reconnect paths construct a fresh Input, whose
predecessor's listeners and gamepad poller would otherwise keep firing
alongside it. The overlay element takes focus, since browsers only run
IME composition on the focused editable element, unless the user is in
another field. Pads are adopted for every role, since a #playerN link
grants a gamepad without the rest of the input context.
Returns
void
attach_context()
attach_context(): void;Defined in: lib/input.js:4349
Attaches the keyboard, pointer, touch, wheel and composition listeners and shows the cursor.
Returns
void
resyncGamepads()
resyncGamepads(): void;Defined in: lib/input.js:4417
Adopts pads the browser already exposes: gamepadconnected fires only on
physical connect (or first press), so a re-attach would otherwise leave
the pad dead until re-plugged. Public because a channel that opens after
attach must re-announce: the js,c it sent into a closed channel was
dropped, leaving the server no association to release when the peer goes.
Returns
void
detach()
detach(): void;Defined in: lib/input.js:4434
Removes every listener and the gamepad manager, then the input context.
Returns
void
detach_context()
detach_context(): void;Defined in: lib/input.js:4449
Removes the input context listeners, releases every key and button, and exits pointer lock.
Returns
void
enterFullscreen()
enterFullscreen(): void;Defined in: lib/input.js:4487
Fullscreen with no lock, leaving the pointer and the keyboard to the browser: the dashboard button and the Ctrl+Shift+F chord land here. The whole document goes fullscreen, not the stream container: the dashboard overlay is a body-level sibling, which container fullscreen would hide.
Returns
void
toggleGamingMode()
toggleGamingMode(): void;Defined in: lib/input.js:4500
Gaming mode on the Ctrl+Shift+X chord. Leaving it drops fullscreen, which is what releases both locks through the fullscreenchange handler; a mode left set without fullscreen (a refused request) is cleared directly.
Returns
void
enterGamingMode()
enterGamingMode(): void;Defined in: lib/input.js:4524
Enters gaming mode: fullscreen that also holds the pointer and the keyboard, so a game sees Escape, Alt+Tab and raw motion instead of the browser. A locked keyboard delivers a short Escape to the session, so holding it is what leaves this mode.
A lock requested before the transition would be canceled by it, so the fullscreenchange handler arms both once fullscreen lands, still inside the gesture's transient-activation window. A refused request takes the mode back down with it: left set, the next transition from any source would arm the locks.
Returns
void
requestKeyboardLock()
requestKeyboardLock(): void;Defined in: lib/input.js:4551
Locks the system keys the browser would otherwise intercept, for gaming mode alone, where the Keyboard Lock API exists.
Returns
void
releaseKeyboardLock()
releaseKeyboardLock(): void;Defined in: lib/input.js:4584
Hands the system keys back; a browser that never locked them ignores it.
Returns
void
Functions
addListener()
function addListener(
obj,
name,
func,
ctx,
useCapture?
): any[];Defined in: lib/input.js:4600
Adds a listener bound to ctx, with passive: false so the handler keeps
preventDefault().
Parameters
| Parameter | Type | Default value |
|---|---|---|
obj | any | undefined |
name | any | undefined |
func | any | undefined |
ctx | any | undefined |
useCapture | boolean | false |
Returns
any[]
The tuple removeListeners takes, or null for an invalid target.
removeListeners()
function removeListeners(listeners): void;Defined in: lib/input.js:4612
Removes listeners added by addListener and empties the list.
Parameters
| Parameter | Type |
|---|---|
listeners | any |
Returns
void