Keyboard.IsKeyDown(Key) メソッド

定義

指定したキーが押されているかどうかを判断します。

public:
 static bool IsKeyDown(System::Windows::Input::Key key);
public static bool IsKeyDown(System.Windows.Input.Key key);
static member IsKeyDown : System.Windows.Input.Key -> bool
Public Shared Function IsKeyDown (key As Key) As Boolean

パラメーター

key
Key

指定したキー。

返品

がダウン状態の場合は a0/&。それ以外の場合は。

次の例は、 IsKeyDown メソッドを使用して特定のキーの状態を判断する方法を示しています。 Return キーは、IsKeyDown メソッドに渡されます。 メソッドが trueを返す場合、 Button の背景が変更されます。

// Uses the Keyboard.IsKeyDown to determine if a key is down.
// e is an instance of KeyEventArgs.
if (Keyboard.IsKeyDown(Key.Return))
{
    btnIsDown.Background = Brushes.Red;
}
else
{
    btnIsDown.Background = Brushes.AliceBlue;
}
' Uses the Keyboard.IsKeyDown to determine if a key is down.
' e is an instance of KeyEventArgs.
If Keyboard.IsKeyDown(Key.Return) Then
    btnIsDown.Background = Brushes.Red
Else
    btnIsDown.Background = Brushes.AliceBlue
End If

注釈

GetKeyStates メソッドを使用して、特定のキーの状態のセットを決定できます。

適用対象

こちらもご覧ください