InputKeyboardSource 类

定义

处理当前线程的键盘输入。

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
继承
Object Platform::Object IInspectable InputKeyboardSource
继承
Object Platform::Object IInspectable InputObject InputKeyboardSource
属性

示例

以下示例演示如何响应 ContentIsland 中的 Esc 键按下。

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

方法

GetCurrentKeyState(VirtualKey)

检索当前 (当前正在处理的输入消息之后(如果输入队列包含) 未处理的消息),则检索提供的虚拟键的状态。

GetForIsland(ContentIsland)

检索 InputKeyboardSource 指定 ContentIsland 的 对象。

GetKeyState(VirtualKey)

检索当前正在处理的输入消息 ((如果输入队列包含) 未处理的消息),则检索提供的虚拟键的状态。

GetKeyStateForCurrentThread(VirtualKey)

检索当前线程) 上当前输入消息 (时提供的虚拟密钥的状态。

事件

CharacterReceived

输入队列收到新字符时发生。

ContextMenuKey

在上一KeyDown个事件中取消处理菜单虚拟键 (或 Shift + F10) 时发生。

KeyDown

当用户按下某个键时,当 ALT 键未同时按下时发生。

KeyUp

当用户释放一个在未同时按下 ALT 键时按下的键时发生。

SystemKeyDown

当用户按下某个键时,同时按下 Alt 键时发生。

SystemKeyUp

当用户释放同时按下 Alt 键时按下的键时发生。

适用于