Keyboard.IsKeyToggled(Key) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
決定指定金鑰是否被切換。
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 方法可用來確定特定鍵的狀態集合。