Keys Enum
Definisi
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 kode kunci dan pengubah.
Enumerasi ini mendukung kombinasi bitwise dari nilai yang termasuk di dalamnya.
public enum class Keys
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.KeysConverter))]
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum Keys
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.KeysConverter))]
[System.Flags]
public enum Keys
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.KeysConverter))>]
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Keys =
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.KeysConverter))>]
[<System.Flags>]
type Keys =
Public Enum Keys
- Warisan
- Atribut
Bidang
| Nama | Nilai | Deskripsi |
|---|---|---|
| Modifiers | -65536 | Bitmask untuk mengekstrak pengubah dari nilai kunci. |
| None | 0 | Tidak ada tombol yang ditekan. |
| LButton | 1 | Tombol kiri mouse. |
| RButton | 2 | Tombol kanan mouse. |
| Cancel | 3 | Kunci CANCEL. |
| MButton | 4 | Tombol mouse tengah (mouse tiga tombol). |
| XButton1 | 5 | Tombol x mouse pertama (mouse lima tombol). |
| XButton2 | 6 | Tombol kedua x mouse (mouse lima tombol). |
| Back | 8 | Kunci BACKSPACE. |
| Tab | 9 | Tombol TAB. |
| LineFeed | 10 | Kunci LINEFEED. |
| Clear | 12 | Kunci CLEAR. |
| Enter | 13 | Tombol ENTER. |
| Return | 13 | Kunci RETURN. |
| ShiftKey | 16 | Tombol SHIFT. |
| ControlKey | 17 | Kunci CTRL. |
| Menu | 18 | Kunci ALT. |
| Pause | 19 | Kunci JEDA. |
| Capital | 20 | Kunci CAPS LOCK. |
| CapsLock | 20 | Kunci CAPS LOCK. |
| HanguelMode | 21 | Kunci mode Hanguel IME. (dipertahankan untuk kompatibilitas; gunakan |
| HangulMode | 21 | Kunci mode Hangul IME. |
| KanaMode | 21 | Kunci mode IME Kana. |
| JunjaMode | 23 | Kunci mode IME Junja. |
| FinalMode | 24 | Kunci mode akhir IME. |
| HanjaMode | 25 | Kunci mode IME Hanja. |
| KanjiMode | 25 | Kunci mode IME Kanji. |
| Escape | 27 | Kunci ESC. |
| IMEConvert | 28 | Kunci konversi IME. |
| IMENonconvert | 29 | Kunci nonkonvert IME. |
| IMEAccept | 30 | Kunci penerimaan IME, menggantikan IMEAceept. |
| IMEAceept | 30 | Kunci penerimaan IME. Usang, gunakan IMEAccept sebagai gantinya. |
| IMEModeChange | 31 | Kunci perubahan mode IME. |
| Space | 32 | Kunci SPACEBAR. |
| PageUp | 33 | Kunci PAGE UP. |
| Prior | 33 | Kunci PAGE UP. |
| Next | 34 | Tombol PAGE DOWN. |
| PageDown | 34 | Tombol PAGE DOWN. |
| End | 35 | Kunci END. |
| Home | 36 | Kunci HOME. |
| Left | 37 | Tombol PANAH KIRI. |
| Up | 38 | Tombol PANAH ATAS. |
| Right | 39 | Tombol PANAH KANAN. |
| Down | 40 | Tombol PANAH BAWAH. |
| Select | 41 | Kunci SELECT. |
| 42 | Tombol PRINT. |
|
| Execute | 43 | Kunci EXECUTE. |
| PrintScreen | 44 | Tombol PRINT SCREEN. |
| Snapshot | 44 | Tombol PRINT SCREEN. |
| Insert | 45 | Kunci INS. |
| Delete | 46 | Kunci DEL. |
| Help | 47 | Kunci BANTUAN. |
| D0 | 48 | Kunci 0. |
| D1 | 49 | Kunci 1. |
| D2 | 50 | Kunci 2. |
| D3 | 51 | Kunci 3. |
| D4 | 52 | Kunci 4. |
| D5 | 53 | Kunci 5. |
| D6 | 54 | Kunci 6. |
| D7 | 55 | Kunci 7. |
| D8 | 56 | Kunci 8. |
| D9 | 57 | Kunci 9. |
| A | 65 | Kunci A. |
| B | 66 | Kunci B. |
| C | 67 | Kunci C. |
| D | 68 | Kunci D. |
| E | 69 | Kunci E. |
| F | 70 | Kunci F. |
| G | 71 | Kunci G. |
| H | 72 | Kunci H. |
| I | 73 | Kunci I. |
| J | 74 | Kunci J. |
| K | 75 | Kunci K. |
| L | 76 | Kunci L. |
| M | 77 | Kunci M. |
| N | 78 | Kunci N. |
| O | 79 | Kunci O. |
| P | 80 | Kunci P. |
| Q | 81 | Kunci Q. |
| R | 82 | Kunci R. |
| S | 83 | Kunci S. |
| T | 84 | Kunci T. |
| U | 85 | Kunci U. |
| V | 86 | Kunci V. |
| W | 87 | Kunci W. |
| X | 88 | Kunci X. |
| Y | 89 | Kunci Y. |
| Z | 90 | Kunci Z. |
| LWin | 91 | Kunci logo Windows kiri (Microsoft Keyboard Alami). |
| RWin | 92 | Kunci logo Windows kanan (Microsoft Keyboard Alami). |
| Apps | 93 | Kunci aplikasi (Microsoft Keyboard Alami). |
| Sleep | 95 | Kunci tidur komputer. |
| NumPad0 | 96 | Tombol 0 pada keypad numerik. |
| NumPad1 | 97 | 1 tombol pada keypad numerik. |
| NumPad2 | 98 | Tombol 2 pada keypad numerik. |
| NumPad3 | 99 | Tombol 3 pada keypad numerik. |
| NumPad4 | 100 | Tombol 4 pada keypad numerik. |
| NumPad5 | 101 | 5 tombol pada keypad numerik. |
| NumPad6 | 102 | Tombol 6 pada keypad numerik. |
| NumPad7 | 103 | Tombol 7 pada keypad numerik. |
| NumPad8 | 104 | Tombol 8 pada keypad numerik. |
| NumPad9 | 105 | Tombol 9 pada keypad numerik. |
| Multiply | 106 | Kunci perkalian. |
| Add | 107 | Tombol tambahkan. |
| Separator | 108 | Kunci pemisah. |
| Subtract | 109 | Pengurangan kunci. |
| Decimal | 110 | Kunci desimal. |
| Divide | 111 | Kunci pembagian. |
| F1 | 112 | Kunci F1. |
| F2 | 113 | Kunci F2. |
| F3 | 114 | Kunci F3. |
| F4 | 115 | Kunci F4. |
| F5 | 116 | Kunci F5. |
| F6 | 117 | Kunci F6. |
| F7 | 118 | Kunci F7. |
| F8 | 119 | Kunci F8. |
| F9 | 120 | Kunci F9. |
| F10 | 121 | Kunci F10. |
| F11 | 122 | Kunci F11. |
| F12 | 123 | Kunci F12. |
| F13 | 124 | Kunci F13. |
| F14 | 125 | Kunci F14. |
| F15 | 126 | Kunci F15. |
| F16 | 127 | Kunci F16. |
| F17 | 128 | Kunci F17. |
| F18 | 129 | Kunci F18. |
| F19 | 130 | Kunci F19. |
| F20 | 131 | Kunci F20. |
| F21 | 132 | Kunci F21. |
| F22 | 133 | Kunci F22. |
| F23 | 134 | Kunci F23. |
| F24 | 135 | Kunci F24. |
| NumLock | 144 | Kunci NUM LOCK. |
| Scroll | 145 | Tombol SCROLL LOCK. |
| LShiftKey | 160 | Tombol SHIFT kiri. |
| RShiftKey | 161 | Tombol SHIFT kanan. |
| LControlKey | 162 | Kunci CTRL kiri. |
| RControlKey | 163 | Kunci CTRL kanan. |
| LMenu | 164 | Kunci ALT kiri. |
| RMenu | 165 | Kunci ALT kanan. |
| BrowserBack | 166 | Kunci kembali browser. |
| BrowserForward | 167 | Kunci penerusan browser. |
| BrowserRefresh | 168 | Kunci refresh browser. |
| BrowserStop | 169 | Kunci stop browser. |
| BrowserSearch | 170 | Kunci pencarian browser. |
| BrowserFavorites | 171 | Kunci favorit browser. |
| BrowserHome | 172 | Kunci beranda browser. |
| VolumeMute | 173 | Tombol matikan suara volume. |
| VolumeDown | 174 | Tombol volume turun. |
| VolumeUp | 175 | Kunci volume naik. |
| MediaNextTrack | 176 | Kunci trek berikutnya media. |
| MediaPreviousTrack | 177 | Kunci trek media sebelumnya. |
| MediaStop | 178 | Tombol Hentikan media. |
| MediaPlayPause | 179 | Tombol jeda pemutaran media. |
| LaunchMail | 180 | Kunci email peluncuran. |
| SelectMedia | 181 | Pilih kunci media. |
| LaunchApplication1 | 182 | Aplikasi awal satu kunci. |
| LaunchApplication2 | 183 | Kunci mulai aplikasi dua. |
| Oem1 | 186 | Kunci OEM 1. |
| OemSemicolon | 186 | Tombol Titik Koma OEM pada keyboard standar AS. |
| Oemplus | 187 | Tombol OEM plus pada keyboard negara/wilayah mana pun. |
| Oemcomma | 188 | Tombol koma OEM pada keyboard negara/wilayah mana pun. |
| OemMinus | 189 | Tombol minus OEM pada keyboard negara/wilayah mana pun. |
| OemPeriod | 190 | Kunci periode OEM pada keyboard negara/wilayah mana pun. |
| Oem2 | 191 | Kunci OEM 2. |
| OemQuestion | 191 | Tombol tanda tanya OEM pada keyboard standar AS. |
| Oem3 | 192 | Kunci OEM 3. |
| Oemtilde | 192 | Tombol tilde OEM pada keyboard standar AS. |
| Oem4 | 219 | Kunci OEM 4. |
| OemOpenBrackets | 219 | Tombol kurung siku terbuka OEM pada keyboard standar AS. |
| Oem5 | 220 | Kunci OEM 5. |
| OemPipe | 220 | Tombol pipa OEM pada keyboard standar AS. |
| Oem6 | 221 | Kunci OEM 6. |
| OemCloseBrackets | 221 | Tombol braket tutup OEM pada keyboard standar AS. |
| Oem7 | 222 | Kunci OEM 7. |
| OemQuotes | 222 | Kunci kutipan tunggal/ganda OEM pada keyboard standar AS. |
| Oem8 | 223 | Kunci OEM 8. |
| Oem102 | 226 | Kunci OEM 102. |
| OemBackslash | 226 | Braket sudut OEM atau tombol garis miring terbalik pada keyboard tombol RT 102. |
| ProcessKey | 229 | Kunci KUNCI PROSES. |
| Packet | 231 | Digunakan untuk meneruskan karakter Unicode seolah-olah karakter tersebut adalah penekanan kunci. Nilai kunci Paket adalah kata rendah dari nilai kunci virtual 32-bit yang digunakan untuk metode input non-keyboard. |
| Attn | 246 | Kunci ATTN. |
| Crsel | 247 | Kunci CRSEL. |
| Exsel | 248 | Kunci EXSEL. |
| EraseEof | 249 | Kunci ERASE EOF. |
| Play | 250 | Kunci PLAY. |
| Zoom | 251 | Tombol ZOOM. |
| NoName | 252 | Konstanta yang dicadangkan untuk digunakan di masa mendatang. |
| Pa1 | 253 | Kunci PA1. |
| OemClear | 254 | Kunci CLEAR. |
| KeyCode | 65535 | Bitmask untuk mengekstrak kode kunci dari nilai kunci. |
| Shift | 65536 | Tombol pengubah SHIFT. |
| Control | 131072 | Tombol pengubah CTRL. |
| Alt | 262144 | Kunci pengubah ALT. |
Contoh
Contoh kode berikut menggunakan KeyDown peristiwa untuk menentukan jenis karakter yang dimasukkan ke dalam kontrol.
// Boolean flag used to determine when a character other than a number is entered.
private:
bool nonNumberEntered;
// Handle the KeyDown event to determine the type of character entered into the control.
void textBox1_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
// Initialize the flag to false.
nonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if ( e->KeyCode < Keys::D0 || e->KeyCode > Keys::D9 )
{
// Determine whether the keystroke is a number from the keypad.
if ( e->KeyCode < Keys::NumPad0 || e->KeyCode > Keys::NumPad9 )
{
// Determine whether the keystroke is a backspace.
if ( e->KeyCode != Keys::Back )
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
//If shift key was pressed, it's not a number.
if (Control::ModifierKeys == Keys::Shift) {
nonNumberEntered = true;
}
}
// This event occurs after the KeyDown event and can be used to prevent
// characters from entering the control.
void textBox1_KeyPress( Object^ /*sender*/, System::Windows::Forms::KeyPressEventArgs^ e )
{
// Check for the flag being set in the KeyDown event.
if ( nonNumberEntered)
{ // Stop the character from being entered into the control since it is non-numerical.
e->Handled = true;
}
}
// Boolean flag used to determine when a character other than a number is entered.
private bool nonNumberEntered = false;
// Handle the KeyDown event to determine the type of character entered into the control.
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Initialize the flag to false.
nonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if(e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
//If shift key was pressed, it's not a number.
if (Control.ModifierKeys == Keys.Shift) {
nonNumberEntered = true;
}
}
// This event occurs after the KeyDown event and can be used to prevent
// characters from entering the control.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
// Check for the flag being set in the KeyDown event.
if (nonNumberEntered)
{
// Stop the character from being entered into the control since it is non-numerical.
e.Handled = true;
}
}
' Boolean flag used to determine when a character other than a number is entered.
Private nonNumberEntered As Boolean = False
' Handle the KeyDown event to determine the type of character entered into the control.
Private Sub textBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles textBox1.KeyDown
' Initialize the flag to false.
nonNumberEntered = False
' Determine whether the keystroke is a number from the top of the keyboard.
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
' Determine whether the keystroke is a number from the keypad.
If e.KeyCode < Keys.NumPad0 OrElse e.KeyCode > Keys.NumPad9 Then
' Determine whether the keystroke is a backspace.
If e.KeyCode <> Keys.Back Then
' A non-numerical keystroke was pressed.
' Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = True
End If
End If
End If
'If shift key was pressed, it's not a number.
If Control.ModifierKeys = Keys.Shift Then
nonNumberEntered = true
End If
End Sub
' This event occurs after the KeyDown event and can be used
' to prevent characters from entering the control.
Private Sub textBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) _
Handles textBox1.KeyPress
' Check for the flag being set in the KeyDown event.
If nonNumberEntered = True Then
' Stop the character from being entered into the control since it is non-numerical.
e.Handled = True
End If
End Sub
Keterangan
Kelas Keys berisi konstanta untuk memproses input keyboard. Anggota enumerasi Kunci terdiri dari kode kunci dan sekumpulan pengubah yang digabungkan menjadi satu nilai bilangan bulat. Dalam antarmuka pemrograman aplikasi Win32 (API) nilai kunci memiliki dua bagian, dengan bit urutan tinggi yang berisi kode kunci (yang sama dengan kode kunci virtual Windows), dan bit urutan rendah yang mewakili pengubah kunci seperti tombol SHIFT, CONTROL, dan ALT.
Warning
Jangan gunakan nilai dalam enumerasi ini untuk operasi bitwise gabungan. Nilai dalam enumerasi tidak saling eksklusif.
Note
Enumerasi ini tidak menyediakan cara untuk menguji apakah kunci CAPS LOCK atau NUM LOCK saat ini diaktifkan. Anda dapat menggunakan salah satu teknik berikut untuk menentukan apakah kunci ini diaktifkan:
IsKeyLocked Panggil metode Control kelas .
Untuk kontrol yang lebih baik, gunakan fungsi API Windows
GetKeyState,GetAsyncKeyState, atauGetKeyboardStateyang ditentukan dalam user32.dll, untuk melakukan ini. Untuk informasi selengkapnya tentang memanggil fungsi asli, lihat Mengonsumsi Fungsi DLL Yang Tidak Dikelola.
Tabel berikut menunjukkan nilai kode kunci yang diwakili oleh dua nilai enumerasi, mewakili kunci produsen peralatan asli umum (OEM) dan asosiasi papan ketik AS yang lebih spesifik.
| Nilai heksadesimal | Keyboard A.S. | OEM Umum |
|---|---|---|
| Bachelor of Arts | OemSemicolon | Oem1 |
| Pacar | OemQuestion | Oem2 |
| C0 | Oemtilde | Oem3 |
| DB | OemOpenBrackets | Oem4 |
| DC | OemPipe | Oem5 |
| DD | OemCloseBrackets | Oem6 |
| Jerman | OemQuotes | Oem7 |
| E2 | OemBackslash | Oem102 |
Caution
Untuk .NET Framework 2.0, anggota IMEAccept ditambahkan yang menggantikan entri sebelumnya, IMEAceept, yang salah dieja. Versi lama telah dipertahankan untuk kompatibilitas mundur, tetapi mungkin dihapus dalam versi .NET mendatang.