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

指定的索引鍵。

傳回

如果 key 為已切換狀態則為 true,否則為 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 可用來判斷特定索引鍵的狀態集合。

適用於

另請參閱