UserInput Class

The input devices of the user of a top-level browsing context (see BrowsingContext.Input): a host application injects the input of the user (the moves, the presses and the releases of the pointers, the rotations of the wheel), and the library dispatches the trusted events of the Pointer Events (https://w3c.github.io/pointerevents/) and UI Events (https://w3c.github.io/uievents/) specifications to the documents of the browsing context and of its nested browsing contexts, and runs the default actions of the user agent (the focus, the activation, the drag and drop, the scrolling). The positions are in CSS pixels, relative to the viewport of the top-level browsing context.

public sealed class UserInput

Properties

NameDescription
KeyboardGets the keyboard of the user agent: the keys pressed and released by the user, dispatched as trusted keyboard events (https://w3c.github.io/uievents/#events-keyboardevents) to the focused element of the top-level browsing context.
ModifiersGets or sets the modifier keys that are pressed (the shiftKey, ctrlKey, altKey and metaKey of the events).
MouseGets the mouse of the user agent (its pointer always exists, https://w3c.github.io/pointerevents/#dfn-active-pointer).

Gets the keyboard of the user agent: the keys pressed and released by the user, dispatched as trusted keyboard events (https://w3c.github.io/uievents/#events-keyboardevents) to the focused element of the top-level browsing context.

public KeyboardInput Keyboard { get; }

Property value

KeyboardInput

Modifiers

UserInput.cs

Gets or sets the modifier keys that are pressed (the shiftKey, ctrlKey, altKey and metaKey of the events).

public InputModifiers Modifiers { get; set; }

Property value

InputModifiers

Gets the mouse of the user agent (its pointer always exists, https://w3c.github.io/pointerevents/#dfn-active-pointer).

public PointerInput Mouse { get; }

Property value

PointerInput

Methods

NameDescription
CreatePointer(string)Creates a pointer of the given type: touch (a finger: a new pointer of the touch screen for each contact), pen (a stylus that hovers) or mouse (returns UserInput.Mouse: there is a single mouse).
HitTest(double, double)Returns the element at a point of the viewport of the top-level browsing context, as the hit testing finds it (https://drafts.csswg.org/cssom-view/#hit-testing): not retargeted out of the shadow trees, and in the document of the nested browsing context when the point is in the content box of its container. The point of an empty area hits the document element. It returns null when the documents are not laid out (e.g. the document is not fully active).
MapToDocument(Document, double, double)Maps a point of the viewport of the top-level browsing context to the viewport of a document of a nested browsing context (the document of an iframe), through the transforms and the scroll offsets of the containers.
MapToTopLevel(Document, double, double)Maps a point of the viewport of a document (e.g. the coordinates of Element.GetBoundingClientRect in the document of an iframe) to the viewport of the top-level browsing context, through the transforms and the scroll offsets of the containers: the coordinates of the input of the user (see PointerInput.Move).
Wheel(double, double, double, double)Rotates the wheel of the mouse at a position of the viewport of the top-level browsing context: a wheel event is fired at the element at the position (at the pointer-lock target while the mouse is locked; at the target of the wheel event transaction in progress, see below) and, unless it is canceled, the nearest scroll container that can scroll in the direction of the deltas (in CSS pixels) is scrolled, without snapping until the gesture of the wheel ends (at once, or 100 ms after the last wheel event when ViewportOptions.SmoothUserScrolling is set). Returns whether a scrolling box was scrolled.

CreatePointer(string)

UserInput.cs

Creates a pointer of the given type: touch (a finger: a new pointer of the touch screen for each contact), pen (a stylus that hovers) or mouse (returns UserInput.Mouse: there is a single mouse).

public PointerInput CreatePointer(string pointerType)

Parameters

pointerType string

Returns

PointerInput

HitTest(double, double)

UserInput.cs

Returns the element at a point of the viewport of the top-level browsing context, as the hit testing finds it (https://drafts.csswg.org/cssom-view/#hit-testing): not retargeted out of the shadow trees, and in the document of the nested browsing context when the point is in the content box of its container. The point of an empty area hits the document element. It returns null when the documents are not laid out (e.g. the document is not fully active).

public Element? HitTest(double x, double y)

Parameters

x double
The horizontal position, in CSS pixels, relative to the viewport of the top-level browsing context.
y double
The vertical position, in CSS pixels, relative to the viewport of the top-level browsing context.

Returns

Element?

MapToDocument(Document, double, double)

UserInput.cs

Maps a point of the viewport of the top-level browsing context to the viewport of a document of a nested browsing context (the document of an iframe), through the transforms and the scroll offsets of the containers.

public (double X, double Y) MapToDocument(Document document, double x, double y)

Parameters

document Document
A document of the top-level browsing context or of a nested browsing context.
x double
The horizontal position, in CSS pixels, relative to the viewport of the top-level browsing context.
y double
The vertical position, in CSS pixels, relative to the viewport of the top-level browsing context.

Returns

(double X, double Y)

MapToTopLevel(Document, double, double)

UserInput.cs

Maps a point of the viewport of a document (e.g. the coordinates of Element.GetBoundingClientRect in the document of an iframe) to the viewport of the top-level browsing context, through the transforms and the scroll offsets of the containers: the coordinates of the input of the user (see PointerInput.Move).

public static (double X, double Y) MapToTopLevel(Document document, double x, double y)

Parameters

document Document
A document of the top-level browsing context or of a nested browsing context.
x double
The horizontal position, in CSS pixels, relative to the viewport of the document.
y double
The vertical position, in CSS pixels, relative to the viewport of the document.

Returns

(double X, double Y)

Wheel(double, double, double, double)

UserInput.Scrolling.cs

Rotates the wheel of the mouse at a position of the viewport of the top-level browsing context: a wheel event is fired at the element at the position (at the pointer-lock target while the mouse is locked; at the target of the wheel event transaction in progress, see below) and, unless it is canceled, the nearest scroll container that can scroll in the direction of the deltas (in CSS pixels) is scrolled, without snapping until the gesture of the wheel ends (at once, or 100 ms after the last wheel event when ViewportOptions.SmoothUserScrolling is set). Returns whether a scrolling box was scrolled.

public bool Wheel(double x, double y, double deltaX, double deltaY)

Parameters

x double
y double
deltaX double
deltaY double

Returns

bool

Remarks

The wheel events of a wheel event transaction (https://w3c.github.io/uievents/#wheel-event-transactions) are fired at the target of its first event, even when the scroll moves other contents under the pointer. A transaction ends when a wheel event is at another position (the mouse moved), 500 ms after its last wheel event (on the clock of the event loop), or when its target is removed from its document or stops generating a box.