KeyEventArgs 類別

定義

包含虛擬金鑰事件所傳回的引數。

public ref class KeyEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class KeyEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class KeyEventArgs
Public NotInheritable Class KeyEventArgs
繼承
Object Platform::Object IInspectable KeyEventArgs
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

備註

Windows 10應用程式在啟用輸入法編輯器 (輸入法) 時,不會收到此事件。 輸入法編輯器 (輸入法) 處理所有鍵盤輸入,並將 Handled 設定為 true

Windows Phone原生應用程式僅支援此 API。

此物件是由針對下列其中一個事件註冊的委派所傳回:

void SetWindow(CoreWindow const & window)
{
    ...
    window.KeyDown({ this, &App::OnKeyDown });
    window.KeyUp({ this, &App::OnKeyUp });
}

// Keypress data is in KeyEventArgs.
void OnKeyDown(Windows::UI::Core::CoreWindow const& /* sender */,
    Windows::UI::Core::KeyEventArgs const& /* args */) {}

void OnKeyUp(Windows::UI::Core::CoreWindow const& /* sender */,
    Windows::UI::Core::KeyEventArgs const& /* args */) {}
// returning keypress events data through KeyEventArgs
void MyCoreWindowEvents::SetWindow( // implementation called by CoreApplication::Run(), provided for context
    _In_ CoreWindow^ window
    )
{
    // ...
    window->KeyDown +=
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &CoreWindowEvents::OnKeyDown);
    window->KeyUp +=
        ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &CoreWindowEvents::OnKeyUp);

    // ...
}

注意

這個類別不是敏捷的,這表示您必須考慮其執行緒模型和封送處理行為。 如需詳細資訊,請參閱 執行緒和封送處理 (C++/CX)

版本歷程記錄

Windows 版本 SDK 版本 新增值
1607 14393 DeviceId

屬性

DeviceId

取得產生此金鑰事件之輸入裝置的唯一識別碼。

使用 DeviceId 區分可產生重要事件的裝置,例如多個遊戲控制器。

所有輸入裝置都不支援 DeviceId。

Handled

取得或設定是否已處理按鍵按下事件。

KeyStatus

取得引發事件時索引鍵的狀態。

VirtualKey

取得對應至按下之按鍵的虛擬按鍵。

適用於

另請參閱