KeyStates 列舉

定義

指定定義按鍵狀態的常數。Specifies constants that define the state of a key.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

public enum class KeyStates
[System.Flags]
public enum KeyStates
type KeyStates = 
Public Enum KeyStates
繼承
KeyStates
屬性

欄位

Down 1

已按下按鍵。The key is pressed.

None 0

未按下按鍵。The key is not pressed.

Toggled 2

已切換按鍵。The key is toggled.

範例

Button如果KeyStates傳入的索引Down鍵的為, 則下列範例會變更的色彩。 KeyEventArgsThe following example changes the color of a Button if the KeyStates of the key passed in the KeyEventArgs is Down. 金鑰的狀態是藉由使用位AND運算來判斷。The state of the key is determined by using a bitwise AND operation. 相同的技巧可以用來判斷某個金鑰是否有多個狀態, 例如處於Toggled狀態Down和狀態。The same technique can be used to determine whether a key has multiple states, such as being in the Toggled state and the Down state.

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

備註

KeyStates類別是位欄位 (位) 列舉。The KeyStates class is a bit field (bitwise) enumeration. 因此, 索引鍵可以處於多種狀態。Therefore, a key can be in multiple states. 例如, 索引鍵可能處於Down狀態Toggled以及狀態中。For example, a key could be in the Down state as well as in the Toggled state. 使用位作業來判斷金鑰的確切狀態或狀態。Use bit operations to determine the exact state or states the key is in.

適用於

另請參閱