KeyEventArgs.KeyStates Proprietà

Definizione

Ottiene lo stato del tasto della tastiera associato a questo evento.

public:
 property System::Windows::Input::KeyStates KeyStates { System::Windows::Input::KeyStates get(); };
public System.Windows.Input.KeyStates KeyStates { get; }
member this.KeyStates : System.Windows.Input.KeyStates
Public ReadOnly Property KeyStates As KeyStates

Valore della proprietà

Stato del tasto.

Esempio

Nell'esempio seguente viene verificato se una chiave associata a un'istanza di KeyEventArgs è inattiva eseguendo un confronto bit per AND bit sull'oggetto KeyStates della chiave e sul Down valore di enumerazione .

// A bitwise AND operation is used in the comparison.
// e is an instance of KeyEventArgs.
// btnDown is a Button.
if ((e.KeyStates & KeyStates.Down) > 0)
{
    btnDown.Background = Brushes.Red;
}
' A bitwise AND operation is used in the comparison.
' e is an instance of KeyEventArgs.
' btnDown is a Button.
If (e.KeyStates And KeyStates.Down) > 0 Then
    btnDown.Background = Brushes.Red

Commenti

Una chiave può trovarsi sia negli stati di attivazione che di attivazione/disattivazione o di attivazione/disattivazione.A key can be in both the up and toggled states or the down and toggled states. Per questo motivo, determinare se una chiave è su o giù non è semplice come controllare il KeyStates valore come valore numerico. È invece consigliabile controllare il valore trattandolo come enumerazione flag. Usare un AND confronto del primo bit. In alternativa, usare le proprietà IsUpdell'helper , IsDowne IsToggled per determinare se una determinata chiave è attiva, inattiva o disattivata.

Si applica a

Vedi anche