Keyboard.IsKeyDown(Key) Metode
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menentukan apakah tombol yang ditentukan ditekan.
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
Kunci yang ditentukan.
true
jika key
dalam keadaan tidak berfungsi; jika tidak, false
.
Contoh berikut menunjukkan cara menggunakan IsKeyDown metode untuk menentukan status kunci tertentu. Kunci Return diteruskan ke IsKeyDown metode . Jika metode mengembalikan true
, latar belakang diubah 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
Metode GetKeyStates ini dapat digunakan untuk menentukan set status kunci tertentu.
Produk | Versi |
---|---|
.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 |
Umpan balik .NET
.NET adalah proyek sumber terbuka. Pilih tautan untuk memberikan umpan balik: