Class KeyEventArgs
Provides information specific to a keyboard event.
public class KeyEventArgs : RoutedEventArgs
- Inheritance
-
KeyEventArgs
- Inherited Members
Constructors
KeyEventArgs()
public KeyEventArgs()
Properties
Key
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:
- Z for an English (QWERTY) layout
- W for a French (AZERTY) layout
- Y for a German (QWERTZ) layout
- Z for a Russian (JCUKEN) layout
public Key Key { get; init; }
Property Value
Remarks
This property should be used for letter-related shortcuts only.
Prefer using 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 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
Type of the device that fire the event
public KeyDeviceType KeyDeviceType { get; init; }
Property Value
KeyModifiers
Gets the key modifiers for the associated event.
public KeyModifiers KeyModifiers { get; init; }
Property Value
KeySymbol
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; init; }
Property Value
PhysicalKey
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 PhysicalKey PhysicalKey { get; init; }
Property Value
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