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. 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:1251
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. 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:1260
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:1261
send
send: (message) => void;Defined in: lib/input.js:1262
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
void
isSharedMode
isSharedMode: boolean;Defined in: lib/input.js:1264
controllerSlot
controllerSlot: number;Defined in: lib/input.js:1265
playerIndex
playerIndex: number;Defined in: lib/input.js:1266
cursorDiv
cursorDiv: HTMLCanvasElement;Defined in: lib/input.js:1267
cursorImg
cursorImg: CanvasRenderingContext2D;Defined in: lib/input.js:1274
cursorHotspot
cursorHotspot: object;Defined in: lib/input.js:1276
x
x: number = 0;y
y: number = 0;use_browser_cursors
use_browser_cursors: boolean;Defined in: lib/input.js:1280
useCssScaling
useCssScaling: boolean;Defined in: lib/input.js:1283
m
m: object;Defined in: lib/input.js:1284
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:1285
gamepadManager
gamepadManager: GamepadManager;Defined in: lib/input.js:1286
x
x: number;Defined in: lib/input.js:1287
y
y: number;Defined in: lib/input.js:1288
onmenuhotkey
onmenuhotkey: any;Defined in: lib/input.js:1294
gamingMode
gamingMode: boolean;Defined in: lib/input.js:1295
ongamingmode
ongamingmode: any;Defined in: lib/input.js:1296
onfullscreenhotkey
onfullscreenhotkey: () => void;Defined in: lib/input.js:1297
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:1298
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:1299
ongamepadconnected
ongamepadconnected: any;Defined in: lib/input.js:1300
ongamepaddisconnected
ongamepaddisconnected: any;Defined in: lib/input.js:1301
listeners
listeners: any[];Defined in: lib/input.js:1302
listeners_context
listeners_context: any[];Defined in: lib/input.js:1303
cursorScaleFactor
cursorScaleFactor: any;Defined in: lib/input.js:1334
isComposing
isComposing: boolean;Defined in: lib/input.js:1351
compositionString
compositionString: string;Defined in: lib/input.js:1352
keyboardInputAssist
keyboardInputAssist: HTMLElement;Defined in: lib/input.js:1364
inputAttached
inputAttached: boolean;Defined in: lib/input.js:1383
Methods
setSharedMode()
setSharedMode(enabled): void;Defined in: lib/input.js:1387
Sets whether this is a viewer-only session.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
updateControllerSlot()
updateControllerSlot(newSlot): void;Defined in: lib/input.js:1392
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:1506
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:1539
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:1545
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:1657
Releases every held key and stops the heartbeat. The armed Windows AltGr timer is cancelled so it cannot synthesize a Control keydown after the reset, while the page is hidden or detached.
Returns
void
setTrackpadMode()
setTrackpadMode(enabled): void;Defined in: lib/input.js:2761
Switches trackpad emulation, clearing touch state and any held button.
Parameters
| Parameter | Type |
|---|---|
enabled | any |
Returns
void
setUseBrowserCursors()
setUseBrowserCursors(enabled): Promise<void>;Defined in: lib/input.js:2796
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:3543
The page size in device pixels, rounded down to even.
Returns
number[]
Width and height.
resize()
resize(): void;Defined in: lib/input.js:3553
Re-derives the window math after a layout change.
Returns
void
isInputAttached()
isInputAttached(): boolean;Defined in: lib/input.js:3558
True while the full input context is attached.
Returns
boolean
attach()
attach(): void;Defined in: lib/input.js:3571
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.
Returns
void
attach_context()
attach_context(): void;Defined in: lib/input.js:3603
Attaches the keyboard, pointer, touch, wheel and composition listeners, shows the cursor and adopts connected pads.
Returns
void
detach()
detach(): void;Defined in: lib/input.js:3682
Removes every listener and the gamepad manager, then the input context.
Returns
void
detach_context()
detach_context(): void;Defined in: lib/input.js:3696
Removes the input context listeners, releases every key and button, and exits pointer lock.
Returns
void
enterFullscreen()
enterFullscreen(): void;Defined in: lib/input.js:3734
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:3747
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:3771
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 cancelled 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:3798
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:3807
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:3823
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:3835
Removes listeners added by addListener and empties the list.
Parameters
| Parameter | Type |
|---|---|
listeners | any |
Returns
void