Keyboard.IsKeyDown(Key) Metod

Definition

Avgör om den angivna nyckeln trycks in.

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

Parametrar

key
Key

Den angivna nyckeln.

Returer

true if key is in the down state;wise, false.

Exempel

I följande exempel visas hur du använder IsKeyDown metoden för att fastställa tillståndet för en specifik nyckel. Nyckeln Return skickas till IsKeyDown metoden. Om metoden returnerar trueändras bakgrunden för en 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

Kommentarer

Metoden GetKeyStates kan användas för att fastställa uppsättningen tillstånd för en specifik nyckel.

Gäller för

Se även