KeyboardEvent Class

https://w3c.github.io/uievents/#keyboardevent

public sealed class KeyboardEvent : UIEvent
Inheritance
UIEvent KeyboardEvent

Constructors

NameDescription
KeyboardEvent(string, KeyboardEventInit?)Creates a keyboard event of the given type with the given initialization dictionary.

KeyboardEvent(string, KeyboardEventInit?)

UIEvents.cs

Creates a keyboard event of the given type with the given initialization dictionary.

public KeyboardEvent(string type, KeyboardEventInit? eventInitDict = null)

Properties

NameDescription
AltKeyGets a value indicating whether the Alt key was active.
CharCodeGets the legacy Unicode code of the character key.
CodeGets the physical key code, such as KeyA or Enter.
CtrlKeyGets a value indicating whether the Control key was active.
IsComposingGets a value indicating whether the event is part of a composition session.
KeyGets the value of the key, such as a or Enter.
KeyCodeGets the legacy code of the key.
LocationGets the location of the key on the device (standard, left, right or numpad).
MetaKeyGets a value indicating whether the Meta key was active.
RepeatGets a value indicating whether the key is held down so that the event is auto-repeated.
ShiftKeyGets a value indicating whether the Shift key was active.

Gets a value indicating whether the Alt key was active.

public bool AltKey { get; }

CharCode

UIEvents.cs

Gets the legacy Unicode code of the character key.

public uint CharCode { get; }

Gets the physical key code, such as KeyA or Enter.

public string Code { get; }

Gets a value indicating whether the Control key was active.

public bool CtrlKey { get; }

IsComposing

UIEvents.cs

Gets a value indicating whether the event is part of a composition session.

public bool IsComposing { get; }

Gets the value of the key, such as a or Enter.

public string Key { get; }

Gets the legacy code of the key.

public uint KeyCode { get; }

Location

UIEvents.cs

Gets the location of the key on the device (standard, left, right or numpad).

public uint Location { get; }

Gets a value indicating whether the Meta key was active.

public bool MetaKey { get; }

Gets a value indicating whether the key is held down so that the event is auto-repeated.

public bool Repeat { get; }

ShiftKey

UIEvents.cs

Gets a value indicating whether the Shift key was active.

public bool ShiftKey { get; }

Methods

NameDescription
GetModifierState(string)Returns whether the given modifier key (such as Shift or CapsLock) was active when the event occurred.
InitKeyboardEvent(string, bool, bool, EventTarget?, string, uint, bool, bool, bool, bool)https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent

GetModifierState(string)

UIEvents.cs

Returns whether the given modifier key (such as Shift or CapsLock) was active when the event occurred.

public bool GetModifierState(string keyArg)

InitKeyboardEvent(string, bool, bool, EventTarget?, string, uint, bool, bool, bool, bool)

UIEvents.cs

https://w3c.github.io/uievents/#dom-keyboardevent-initkeyboardevent

public void InitKeyboardEvent(string typeArg, bool bubblesArg = false, bool cancelableArg = false, EventTarget? viewArg = null, string keyArg = "", uint locationArg = 0U, bool ctrlKey = false, bool altKey = false, bool shiftKey = false, bool metaKey = false)

Parameters

typeArg string
bubblesArg bool
cancelableArg bool
viewArg EventTarget?
keyArg string
locationArg uint
ctrlKey bool
altKey bool
shiftKey bool
metaKey bool

See also

Constants

NameDescription
DomKeyLocationLeftThe key is on the left side of the keyboard.
DomKeyLocationNumpadThe key is on the numeric keypad.
DomKeyLocationRightThe key is on the right side of the keyboard.
DomKeyLocationStandardThe key has a single location on the keyboard.

DomKeyLocationLeft

The key is on the left side of the keyboard.

public const uint DomKeyLocationLeft = 1U

DomKeyLocationNumpad

The key is on the numeric keypad.

public const uint DomKeyLocationNumpad = 3U

DomKeyLocationRight

The key is on the right side of the keyboard.

public const uint DomKeyLocationRight = 2U

DomKeyLocationStandard

The key has a single location on the keyboard.

public const uint DomKeyLocationStandard = 0U