Keyboard.GetKeyStates(Key) 메서드

정의

지정한 키의 키 상태 집합을 가져옵니다.

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

매개 변수

key
Key

지정한 키입니다.

반환

KeyStates 값의 비트 조합입니다.

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다 합니다 GetKeyStates 여부를 확인 하는 메서드를 Return 키가는 Down 상태. 비트 AND 연산을 비교에 사용 되는 KeyStates 에서 반환 된 GetKeyStatesDown 상태입니다. 키가 눌러져 배경의 경우는 Button 변경 됩니다.

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

설명

KeyStates 비트 필드 열거형입니다. 따라서 키가 여러 상태에 있을 가능성이 있습니다. 예를 들어 키 누름 상태의 전환 된 상태와 같이 수 있습니다. 키가의 정확한 상태를 확인 하려면 비트 비교 작업을 사용 합니다.

Keyboard 클래스는 다양 한 주요 상태 정보를 얻는 사용할 수 있는 정적 메서드를 제공 합니다. 메서드: IsKeyDown, IsKeyUp, 및 IsKeyToggled합니다.

적용 대상

추가 정보