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 Down,则下面的示例将更改的颜色。 KeyEventArgs KeyStatesThe 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.

适用于

另请参阅