KeyEventArgs KeyEventArgs KeyEventArgs KeyEventArgs Class

Definition

Contains the arguments returned by a virtual key event.

public : sealed class KeyEventArgs : ICoreWindowEventArgs, IKeyEventArgs, IKeyEventArgs2
public sealed class KeyEventArgs : ICoreWindowEventArgs, IKeyEventArgs, IKeyEventArgs2
Public NotInheritable Class KeyEventArgs Implements ICoreWindowEventArgs, IKeyEventArgs, IKeyEventArgs2
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

Windows 10 Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Windows Phone This API is supported in native apps only.

This object is returned by a delegate registered for one of the following events:


// returning keypress events data through KeyEventArgs

void MyCoreWindowEvents::SetWindow( // implementation called by CoreApplication::Run(), provided for context
    _In_ CoreWindow^ window
    )
{
    // ...
    window->KeyDown +=
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &CoreWindowEvents::OnKeyDown);
    window->KeyUp +=
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &CoreWindowEvents::OnKeyUp);

    // ...

}

Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX).

Properties

DeviceId DeviceId DeviceId DeviceId

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

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

DeviceId is not supported for all input devices.

public : Platform::String DeviceId { get; }
public string DeviceId { get; }
Public ReadOnly Property DeviceId As string
var string = keyEventArgs.deviceId;
Value
Platform::String string string string

A unique identifier for the input device associated with the key event, or an empty string. The same device can be assigned a different ID each time it is connected.

Additional features and requirements
Device family
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v3)

Remarks

This property is useful for retrieving info for a specific user account associated with the input device.

Handled Handled Handled Handled

Gets or sets whether the key press event was handled.

public : Platform::Boolean Handled { get; set; }
public bool Handled { get; set; }
Public ReadWrite Property Handled As bool
var bool = keyEventArgs.handled;
keyEventArgs.handled = bool;
Value
Platform::Boolean bool bool bool

True if the key press event has been handled by the appropriate delegate; false if it has not.

Remarks

Windows 10 Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Windows Phone This API is supported in native apps only.

KeyStatus KeyStatus KeyStatus KeyStatus

Gets the status of a key at the time the event is fired.

public : CorePhysicalKeyStatus KeyStatus { get; }
public CorePhysicalKeyStatus KeyStatus { get; }
Public ReadOnly Property KeyStatus As CorePhysicalKeyStatus
var corePhysicalKeyStatus = keyEventArgs.keyStatus;

Remarks

Windows 10 Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Windows Phone This API is supported in native apps only.

VirtualKey VirtualKey VirtualKey VirtualKey

Gets the virtual key that maps to the key that was pressed.

public : VirtualKey VirtualKey { get; }
public VirtualKey VirtualKey { get; }
Public ReadOnly Property VirtualKey As VirtualKey
var virtualKey = keyEventArgs.virtualKey;
Value
VirtualKey VirtualKey VirtualKey VirtualKey

The virtual key value.

Remarks

Windows 10 Apps do not receive this event when an Input Method Editor (IME) is enabled. The Input Method Editor (IME) handles all keyboard input and sets Handled to true.

Windows Phone This API is supported in native apps only.