Keyboard.IsKeyDown(Key) Metodo

Definizione

Determina se viene premuto il tasto specificato.

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

Parametri

key
Key

Chiave specificata.

Restituisce

true se l'oggetto key è nello stato premuto; in caso contrario, false.

Esempio

Nell'esempio seguente viene illustrato come usare il IsKeyDown metodo per determinare lo stato di una chiave specifica. La Return chiave viene passata al IsKeyDown metodo . Se il metodo restituisce true, lo sfondo di un Button oggetto viene modificato.

// 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

Commenti

Il GetKeyStates metodo può essere usato per determinare il set di stati di una chiave specifica.

Si applica a

Vedi anche