Keyboard.GetKeyStates(Key) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 키의 키 상태 집합을 가져옵니다.
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 된 GetKeyStates 원본 및 상태를 비교하는 Down 데 사용됩니다. 키가 다운되면 배경 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 키 상태 정보를 가져오는 데 사용할 수 있는 여러 정적 메서드를 제공합니다. 메서드는 다음과 IsKeyDownIsKeyUpIsKeyToggled같습니다.