Keyboard.GetKeyStates(Key) Metodo

Definizione

Ottiene il set di stati della chiave per la chiave specificata.

public:
 static System::Windows::Input::KeyStates GetKeyStates(System::Windows::Input::Key key);
public static System.Windows.Input.KeyStates GetKeyStates(System.Windows.Input.Key key);
static member GetKeyStates : System.Windows.Input.Key -> System.Windows.Input.KeyStates
Public Shared Function GetKeyStates (key As Key) As KeyStates

Parametri

key
Key

Chiave specificata.

Valori restituiti

Combinazione bit per bit dei KeyStates valori.

Esempio

Nell'esempio seguente viene illustrato come usare il GetKeyStates metodo per determinare se la Return chiave è nello Down stato . Un'operazione AND di bit viene usata per confrontare l'oggetto KeyStates restituito da GetKeyStates e lo Down stato. Se la chiave è inattiva, lo sfondo di un Button oggetto viene modificato.

// Uses the Keyboard.GetKeyStates to determine if a key is down.
// A bitwise AND operation is used in the comparison. 
// e is an instance of KeyEventArgs.
if ((Keyboard.GetKeyStates(Key.Return) & KeyStates.Down) > 0)
{
    btnNone.Background = Brushes.Red;
}
' Uses the Keyboard.GetKeyStates to determine if a key is down.
' A bitwise AND operation is used in the comparison. 
' e is an instance of KeyEventArgs.
If (Keyboard.GetKeyStates(Key.Return) And KeyStates.Down) > 0 Then
    btnNone.Background = Brushes.Red

Commenti

KeyStates è un'enumerazione di campi di bit; pertanto, è possibile che una chiave sia in più stati. Ad esempio, un tasto potrebbe trovarsi nello stato premuto e nello stato attivato. Usare operazioni di confronto dei bit per determinare lo stato esatto o gli stati in cui si trova la chiave.

La Keyboard classe fornisce diversi metodi statici che possono essere usati anche per ottenere informazioni sullo stato della chiave. I metodi sono: IsKeyDown, IsKeyUpe IsKeyToggled.

Si applica a

Vedi anche