KeyEventArgs.KeyStates 속성

정의

이 이벤트와 연결된 키보드 키의 상태를 가져옵니다.

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

속성 값

키의 상태입니다.

예제

다음 예제에서는 키의 Down 및 열거형 값에 대해 KeyStates 비트 AND 비교를 수행하여 의 KeyEventArgs instance 연결된 키가 다운되었는지 여부를 확인합니다.

// 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 것만큼 간단하지 않습니다. 대신 플래그 열거형으로 처리하여 값을 검사 합니다. 첫 번째 AND 비트의 비교를 사용합니다. 또는 도우미 속성 IsUp, 및 IsDownIsToggled 를 사용하여 지정된 키가 위쪽, 아래쪽 또는 토글되었는지 여부를 확인합니다.

적용 대상

추가 정보