共用方式為


Keyboard.IsKeyDown(Key) 方法

定義

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

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

參數

key
Key

指定的索引鍵。

傳回

如果 key 為已按下狀態則為 true,否則為 false

範例

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

// Uses the Keyboard.IsKeyDown to determine if a key is down.
// e is an instance of KeyEventArgs.
if (Keyboard.IsKeyDown(Key.Return))
{
    btnIsDown.Background = Brushes.Red;
}
else
{
    btnIsDown.Background = Brushes.AliceBlue;
}
' Uses the Keyboard.IsKeyDown to determine if a key is down.
' e is an instance of KeyEventArgs.
If Keyboard.IsKeyDown(Key.Return) Then
    btnIsDown.Background = Brushes.Red
Else
    btnIsDown.Background = Brushes.AliceBlue
End If

備註

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

適用於

另請參閱