Language

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アプリは、入力メソッド エディター (IME) が有効になっている場合、このイベントを受信しません。 入力メソッド エディター (IME) は、すべてのキーボード入力を処理し、 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

プロパティ

Name 説明
DeviceId

このキー イベントを生成した入力デバイスの一意の ID を取得します。

DeviceId を使用して、複数のゲーム コントローラーなどの主要なイベントを生成できるデバイスを区別します。

DeviceId は、すべての入力デバイスでサポートされているわけではありません。

Handled

キー押下イベントが処理されたかどうかを取得または設定します。

KeyStatus

イベントが発生した時点のキーの状態を取得します。

VirtualKey

押されたキーにマップされる仮想キーを取得します。

適用対象

関連項目