語言

Keyboard.IsKeyToggled(Key) 方法

定義

決定指定金鑰是否被切換。

public:
 static bool IsKeyToggled(System::Windows::Input::Key key);
public static bool IsKeyToggled(System.Windows.Input.Key key);
static member IsKeyToggled : System.Windows.Input.Key -> bool
Public Shared Function IsKeyToggled (key As Key) As Boolean

參數

key
Key

指定的金鑰。

傳回

true若key處於切換狀態;否則,。 false

範例

以下範例說明如何使用此 IsKeyToggled 方法來判定特定鍵的狀態。 Return金鑰會傳給方法。IsKeyToggled 若方法返回 true,則 的背景 Button 會被改變。

// Uses the Keyboard.IsToggled to determine if a key is toggled.
if (Keyboard.IsKeyToggled(Key.Return))
{
    btnIsToggle.Background = Brushes.Red;
}
else
{
    btnIsToggle.Background = Brushes.AliceBlue;
}
' Uses the Keyboard.IsToggled to determine if a key is toggled.
If Keyboard.IsKeyToggled(Key.Return) Then
    btnIsToggle.Background = Brushes.Red
Else
    btnIsToggle.Background = Brushes.AliceBlue
End If

備註

此 GetKeyStates 方法可用來確定特定鍵的狀態集合。

適用於

另請參閱