KeyRoutedEventArgs Class

Definition

Provides event data for the KeyUp and KeyDown routed events.

C#
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class KeyRoutedEventArgs : RoutedEventArgs
Inheritance
Object RoutedEventArgs KeyRoutedEventArgs
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

Button input is mapped to different key values for various devices.

This table provides the mapping detail for game pad and remote devices.

ButtonKey valueOriginalKey value
GamepadA buttonSpaceGamepadA or NavigationAccept
GamepadB buttonEscapeGamepadB or NavigationCancel
GamepadX buttonGamepadXGamepadX
GamepadY buttonGamepadYGamepadY
GamepadDPad button

50

GamepadDPadUp/Down/Left/RightGamepadDPadUp/Down/Left/Right or NavigationUp/Down/Left/Right
GamePad Joystick/ThumbstickGamepadLeftThumbstickButton/Up/Down/Left/Right or GamepadRightThumbstickButton/Up/Down/Left/RightGamepadLeftThumbstickButton/Up/Down/Left/Right or GamepadRightThumbstickButton/Up/Down/Left/Right or NavigationUp/Down/Left/Right
Gamepad TriggerGamePadRightTrigger/LeftTriggerGamePadRightTrigger/LeftTrigger
Gamepad Bumper/ShoulderGamePadRightShoulder/LeftShoulderGamePadRightShoulder/LeftShoulder
Gamepad Menu buttonGamepadMenuGamepadMenu or NavigationMenu
Gamepad View buttonGamepadViewGamepadView or NavigationView

Version history

Windows version SDK version Value added
1607 14393 DeviceId

Properties

DeviceId

Gets a unique ID for the input device that generated this key event.

Use DeviceId to differentiate between all connected devices that can generate key events, such as multiple game controllers.

DeviceId is not supported for all input devices.

Handled

Gets or sets a value that marks the routed event as handled. A true value for Handled prevents most handlers along the event route from handling the same event again.

Key

Gets the virtual key associated with the event.

Depending on the input device, this can be a mapped value. For raw, unmapped event data, see the OriginalKey property.

KeyStatus

Gets a structure value that reports various system-detected characteristics of the key press, including repeat count and menu status.

OriginalKey

Gets the original, unmapped virtual key associated with the event.

Depending on the input device, the input button might be mapped to a different key value. For the mapped event value, see the Key property.

OriginalSource

Gets a reference to the object that raised the event. This is often a template part of a control rather than an element that was declared in your app UI.

(Inherited from RoutedEventArgs)

Applies to

Product Versions
WinRT Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100

See also