Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.03 KB

inputkeyboardsource.md

File metadata and controls

48 lines (36 loc) · 1.03 KB
-api-id -api-type
T:Microsoft.UI.Input.InputKeyboardSource
winrt class

Microsoft.UI.Input.InputKeyboardSource

-description

Processes keyboard input for the current thread.

-remarks

-see-also

-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;
        }
    }
}