Keyboard Class

The keyboard of a window (https://wicg.github.io/keyboard-lock/#keyboard-interface, navigator.keyboard): the Keyboard Lock API, which captures the keys that the system or the browser handle, with KeyboardLockOptions. A document whose keyboard is locked is not kept in the back/forward cache (as in Chromium).

public sealed class Keyboard : EventTarget
Inheritance
EventTarget Keyboard

Properties

NameDescription
OnLayoutChangeGets or sets the event handler of the layoutchange event, fired when the keyboard layout changes.

OnLayoutChange

KeyboardMap.cs

Gets or sets the event handler of the layoutchange event, fired when the keyboard layout changes.

public Action<Event>? OnLayoutChange { get; set; }

Methods

NameDescription
GetLayoutMap()Returns the keyboard layout of the device (https://wicg.github.io/keyboard-map/#h-keyboard-getlayoutmap), read from KeyboardMapOptions.Provider (US QWERTY by default). The calls made before the task completes return the same task (as in Chromium). The task fails with a SecurityError DomException when the document is not allowed to use the keyboard-map feature, and an InvalidStateError when it is not fully active.
Lock(IReadOnlyList<string>?)Captures the keys that the system or the browser handle (https://wicg.github.io/keyboard-lock/#h-keyboard-lock), with KeyboardLockOptions.Lock. The task fails with an InvalidStateError DomException when the document is not the active document of a top-level browsing context, an InvalidAccessError when a key code is not valid, and an AbortError when another call replaces the request before it completes.
Unlock()Releases the keys captured by Keyboard.Lock (https://wicg.github.io/keyboard-lock/#h-keyboard-unlock), with KeyboardLockOptions.Unlock.

GetLayoutMap()

KeyboardMap.cs

Returns the keyboard layout of the device (https://wicg.github.io/keyboard-map/#h-keyboard-getlayoutmap), read from KeyboardMapOptions.Provider (US QWERTY by default). The calls made before the task completes return the same task (as in Chromium). The task fails with a SecurityError DomException when the document is not allowed to use the keyboard-map feature, and an InvalidStateError when it is not fully active.

public Task<KeyboardLayoutMap> GetLayoutMap()

Lock(IReadOnlyList<string>?)

KeyboardLock.cs

Captures the keys that the system or the browser handle (https://wicg.github.io/keyboard-lock/#h-keyboard-lock), with KeyboardLockOptions.Lock. The task fails with an InvalidStateError DomException when the document is not the active document of a top-level browsing context, an InvalidAccessError when a key code is not valid, and an AbortError when another call replaces the request before it completes.

public Task Lock(IReadOnlyList<string>? keyCodes = null)

Parameters

keyCodes IReadOnlyList<string>?
The code values of the keys to capture, or an empty list to capture all the keys.

Returns

Task

See also

Releases the keys captured by Keyboard.Lock (https://wicg.github.io/keyboard-lock/#h-keyboard-unlock), with KeyboardLockOptions.Unlock.

public void Unlock()