KeyEventArgs KeyEventArgs KeyEventArgs Class

Contains the arguments returned by a virtual key event.

Syntax

Declaration

public sealed class KeyEventArgspublic sealed class KeyEventArgsPublic NotInheritable Class KeyEventArgs

Remarks

Windows 10 Apps do not receive this event when an 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 summary

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.

Gets or sets whether the key press event was handled.

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

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

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 string DeviceId { get; }public string DeviceId { get; }Public ReadOnly Property DeviceId As string

    Property Value

    • 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.

    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 bool Handled { get; set; }public bool Handled { get; set; }Public ReadWrite Property Handled As bool

    Property Value

    • 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 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

    Property Value

    Remarks

    Windows 10 Apps do not receive this event when an 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

    Property Value

    Remarks

    Windows 10 Apps do not receive this event when an 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.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Core.dll