Skip to main content

KeyEventArgs Class

Definition

Namespace:Avalonia.Input
Assembly:Avalonia.Base
Package:Avalonia

Provides information specific to a keyboard event.

public class KeyEventArgs

Inheritance: EventArgs -> RoutedEventArgs -> KeyEventArgs

Constructors

NameDescription
KeyEventArgsNo summary available.

KeyEventArgs Constructor

public KeyEventArgs()

Properties

NameDescription
KeyGets the virtual-key for the associated event. A given physical key can result in different virtual keys depending on the current keyboard layout. This is the key that is generally referred to when creating keyboard shortcuts.
KeyDeviceTypeType of the device that fire the event
KeyModifiersNo summary available.
KeySymbolGets the unicode symbol of the key, or null if none is applicable.
PhysicalKeyGets the physical key for the associated event.
HandledGets or sets a value indicating whether the routed event has already been handled. Inherited from RoutedEventArgs.
RouteGets or sets the routing strategy (direct, bubbling, or tunneling) of the routed event. Inherited from RoutedEventArgs.
RoutedEventGets or sets the routed event associated with these event args. Inherited from RoutedEventArgs.
SourceGets or sets the source object that raised the routed event. Inherited from RoutedEventArgs.

Key Property

Gets the virtual-key for the associated event. A given physical key can result in different virtual keys depending on the current keyboard layout. This is the key that is generally referred to when creating keyboard shortcuts.

For example, when pressing the key located at the Z position on standard US English QWERTY keyboard, this property returns:

public Avalonia.Input.Key Key { get; set; }

Remarks

This property should be used for letter-related shortcuts only. Prefer using Avalonia.Input.KeyEventArgs.PhysicalKey if you need to refer to a key given its position on the keyboard (a common usage is moving the player with WASD-like keys in games), or Avalonia.Input.KeyEventArgs.KeySymbol if you want to know which character the key will output. Avoid using this for shortcuts related to punctuation keys, as they differ wildly depending on keyboard layouts.

See also

KeyDeviceType Property

Type of the device that fire the event

public Avalonia.Input.KeyDeviceType KeyDeviceType { get; set; }

KeyModifiers Property

public Avalonia.Input.KeyModifiers KeyModifiers { get; set; }

KeySymbol Property

Gets the unicode symbol of the key, or null if none is applicable.

For example, when pressing the key located at the Z position on standard US English QWERTY keyboard, this property returns:

  • z for an English (QWERTY) layout
  • w for a French (AZERTY) layout
  • y for a German (QWERTZ) layout
  • я for a Russian (JCUKEN) layout
public string KeySymbol { get; set; }

PhysicalKey Property

Gets the physical key for the associated event.

This value is independent of the current keyboard layout and usually correspond to the key printed on a standard US English QWERTY keyboard.

public Avalonia.Input.PhysicalKey PhysicalKey { get; set; }

Remarks

Use this property if you need to refer to a key given its position on the keyboard (a common usage is moving the player with WASD-like keys).

See also