共用方式為


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

發生于 功能表 虛擬鍵 (或 Shift + F10) 未處理先前 KeyDown 事件時。

KeyDown

發生于使用者未按下 ALT 鍵時按下按鍵時。

KeyUp

發生于使用者放開未按下 ALT 鍵時按下的按鍵時。

SystemKeyDown

發生于使用者同步選取 ALT 鍵時按下按鍵時。

SystemKeyUp

發生于使用者放開同步選取 ALT 鍵時按下的按鍵時。

適用於