-api-id | -api-type |
---|---|
T:Microsoft.UI.Input.InputKeyboardSource |
winrt class |
Processes keyboard input for the current thread.
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;
}
}
}