Keyboard.IsKeyToggled(Key) 方法

定義

判斷指定的按鍵是否為已切換。

C#
public static bool IsKeyToggled(System.Windows.Input.Key key);

參數

key
Key

指定的索引鍵。

傳回

如果 key 為已切換狀態則為 true,否則為 false

範例

下列範例示範如何使用 IsKeyToggled 方法來判斷特定索引鍵的狀態。 金鑰 Return 會傳遞至 IsKeyToggled 方法。 如果方法傳 true回 ,則會變更的背景 Button

C#
// 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;
}

備註

方法 GetKeyStates 可用來判斷特定索引鍵的狀態集合。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱