Share via


InputKeyboardSource Class

Definition

Processes keyboard input for the current thread.

public ref class InputKeyboardSource abstract sealed
public ref class InputKeyboardSource sealed : InputObject
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class InputKeyboardSource final
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class InputKeyboardSource final : InputObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class InputKeyboardSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class InputKeyboardSource : InputObject
Public Class InputKeyboardSource
Public NotInheritable Class InputKeyboardSource
Inherits InputObject
Inheritance
Object Platform::Object IInspectable InputKeyboardSource
Inheritance
Object Platform::Object IInspectable InputObject InputKeyboardSource
Attributes

Examples

The following example shows how to respond to an Esc key press from a ContentIsland.

class RespondToKeyDown
{
    InputKeyboardSource myInputKeyboardSource;

    public RespondToKeyDown(Microsoft.UI.Content.ContentIsland island)
    {
        myInputKeyboardSource = InputKeyboardSource.GetForIsland(island);
        myInputKeyboardSource.KeyDown += OnKeyDown;
    }

    void OnKeyDown(
        InputKeyboardSource sender,
        InputKeyboardSourceEventArgs args)
    {
        if (args.VirtualKey == Windows.System.VirtualKey.Escape)
        {
            System.Diagnostics.Debug.WriteLine("Escape key was pressed.");
            CancelCurrentOperation();
            args.Handled = true;
        }
    }
}

Methods

GetCurrentKeyState(VirtualKey)

Retrieves the state of the supplied virtual-key at the current time (which could be after the input message currently being processed, if the input queue contains unprocessed messages).

GetForIsland(ContentIsland)

Retrieves an InputKeyboardSource object for the specified ContentIsland.

GetKeyState(VirtualKey)

Retrieves the state of the supplied virtual-key at the time of the input message currently being processed (which could be in the past, if the input queue contains unprocessed messages).

GetKeyStateForCurrentThread(VirtualKey)

Retrieves the state of the supplied virtual-key at the time of the current input message (on the current thread).

Events

CharacterReceived

Occurs when a new character is received by the input queue.

ContextMenuKey

Occurs when the Menu virtual-key (or Shift + F10) is unhandled from a previous KeyDown event.

KeyDown

Occurs when the user presses a key when the ALT key is not also pressed.

KeyUp

Occurs when the user releases a key that was pressed when the ALT key was not also pressed.

SystemKeyDown

Occurs when the user presses a key when the ALT key is also pressed.

SystemKeyUp

Occurs when the user releases a key that was pressed when the ALT key was also pressed.

Applies to