Keys Enum

Definisi

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

A 65

Kunci A.

Add 107

Tombol tambahkan.

Alt 262144

Tombol pengubah ALT.

Apps 93

Kunci aplikasi (Microsoft Natural Keyboard).

Attn 246

Kunci ATTN.

B 66

Kunci B.

Back 8

Kunci BACKSPACE.

BrowserBack 166

Kunci kembali browser.

BrowserFavorites 171

Kunci favorit browser.

BrowserForward 167

Kunci penerusan browser.

BrowserHome 172

Kunci beranda browser.

BrowserRefresh 168

Kunci refresh browser.

BrowserSearch 170

Kunci pencarian browser.

BrowserStop 169

Kunci perhentian browser.

C 67

Kunci C.

Cancel 3

Kunci CANCEL.

Capital 20

Kunci CAPS LOCK.

CapsLock 20

Kunci CAPS LOCK.

Clear 12

Kunci CLEAR.

Control 131072

Tombol pengubah CTRL.

ControlKey 17

Tombol CTRL.

Crsel 247

Kunci CRSEL.

D 68

Kunci D.

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.

Decimal 110

Kunci desimal.

Delete 46

Kunci DEL.

Divide 111

Kunci pembagian.

Down 40

Tombol PANAH BAWAH.

E 69

Kunci E.

End 35

Kunci END.

Enter 13

Tombol ENTER.

EraseEof 249

Kunci EOF PENGHAPUSAN.

Escape 27

Kunci ESC.

Execute 43

Kunci EXECUTE.

Exsel 248

Kunci EXSEL.

F 70

Kunci F.

F1 112

Kunci F1.

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.

F2 113

Kunci F2.

F20 131

Kunci F20.

F21 132

Kunci F21.

F22 133

Kunci F22.

F23 134

Kunci F23.

F24 135

Kunci F24.

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.

FinalMode 24

Kunci mode akhir IME.

G 71

Kunci G.

H 72

Kunci H.

HanguelMode 21

Kunci mode Hanguel IME. (dipertahankan untuk kompatibilitas; gunakan HangulMode)

HangulMode 21

Kunci mode Hangul IME.

HanjaMode 25

Kunci mode Hanja IME.

Help 47

Kunci BANTUAN.

Home 36

Kunci HOME.

I 73

Kunci I.

IMEAccept 30

Kunci terima IME, menggantikan IMEAceept.

IMEAceept 30

Kunci penerimaan IME. Usang, gunakan IMEAccept sebagai gantinya.

IMEConvert 28

Kunci konversi IME.

IMEModeChange 31

Kunci perubahan mode IME.

IMENonconvert 29

Kunci tidak konvert IME.

Insert 45

Kunci INS.

J 74

Kunci J.

JunjaMode 23

Kunci mode IME Junja.

K 75

Kunci K.

KanaMode 21

Kunci mode IME Kana.

KanjiMode 25

Kunci mode IME Kanji.

KeyCode 65535

Bitmask untuk mengekstrak kode kunci dari nilai kunci.

L 76

Kunci L.

LaunchApplication1 182

Aplikasi awal satu kunci.

LaunchApplication2 183

Aplikasi awal dua kunci.

LaunchMail 180

Kunci email peluncuran.

LButton 1

Tombol kiri mouse.

LControlKey 162

Tombol CTRL kiri.

Left 37

Tombol PANAH KIRI.

LineFeed 10

Kunci LINEFEED.

LMenu 164

Kunci ALT kiri.

LShiftKey 160

Tombol SHIFT kiri.

LWin 91

Tombol logo Windows kiri (Microsoft Natural Keyboard).

M 77

Kunci M.

MButton 4

Tombol mouse tengah (mouse tiga tombol).

MediaNextTrack 176

Kunci trek berikutnya media.

MediaPlayPause 179

Kunci jeda pemutaran media.

MediaPreviousTrack 177

Kunci trek media sebelumnya.

MediaStop 178

Tombol Hentikan media.

Menu 18

Kunci ALT.

Modifiers -65536

Bitmask untuk mengekstrak pengubah dari nilai kunci.

Multiply 106

Kunci perkalian.

N 78

Kunci N.

Next 34

Tombol PAGE DOWN.

NoName 252

Konstanta yang disediakan untuk digunakan di masa mendatang.

None 0

Tidak ada tombol yang ditekan.

NumLock 144

Kunci NUM LOCK.

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.

O 79

Kunci O.

Oem1 186

Kunci OEM 1.

Oem102 226

Kunci OEM 102.

Oem2 191

Kunci OEM 2.

Oem3 192

Kunci OEM 3.

Oem4 219

Kunci OEM 4.

Oem5 220

Kunci OEM 5.

Oem6 221

Kunci OEM 6.

Oem7 222

Kunci OEM 7.

Oem8 223

Kunci OEM 8.

OemBackslash 226

Kurung sudut OEM atau tombol garis miring terbalik pada keyboard tombol RT 102.

OemClear 254

Kunci CLEAR.

OemCloseBrackets 221

Tombol kurung tutup OEM pada keyboard standar AS.

Oemcomma 188

Kunci koma OEM pada keyboard negara/wilayah mana pun.

OemMinus 189

Kunci minus OEM pada keyboard negara/wilayah mana pun.

OemOpenBrackets 219

Tombol kurung siku terbuka OEM pada keyboard standar AS.

OemPeriod 190

Kunci periode OEM pada keyboard negara/wilayah mana pun.

OemPipe 220

Tombol pipa OEM pada keyboard standar AS.

Oemplus 187

Tombol OEM plus pada keyboard negara/wilayah mana pun.

OemQuestion 191

Tombol tanda tanya OEM pada keyboard standar AS.

OemQuotes 222

Tombol kutipan tunggal/ganda OEM pada keyboard standar AS.

OemSemicolon 186

Tombol Titik Koma OEM pada keyboard standar AS.

Oemtilde 192

Tombol tilde OEM pada keyboard standar AS.

P 80

Kunci P.

Pa1 253

Kunci PA1.

Packet 231

Digunakan untuk meneruskan karakter Unicode seolah-olah itu adalah penekanan tombol. Nilai kunci Paket adalah kata rendah dari nilai kunci virtual 32-bit yang digunakan untuk metode input non-keyboard.

PageDown 34

Tombol PAGE DOWN.

PageUp 33

Kunci PAGE UP.

Pause 19

Kunci JEDA.

Play 250

Kunci PLAY.

Print 42

Tombol PRINT.

PrintScreen 44

Tombol PRINT SCREEN.

Prior 33

Kunci PAGE UP.

ProcessKey 229

Kunci KUNCI PROSES.

Q 81

Kunci Q.

R 82

Kunci R.

RButton 2

Tombol kanan mouse.

RControlKey 163

Tombol CTRL kanan.

Return 13

Kunci RETURN.

Right 39

Tombol PANAH KANAN.

RMenu 165

Kunci ALT yang tepat.

RShiftKey 161

Tombol SHIFT kanan.

RWin 92

Tombol logo Windows yang tepat (Microsoft Natural Keyboard).

S 83

Kunci S.

Scroll 145

Tombol SCROLL LOCK.

Select 41

Kunci SELECT.

SelectMedia 181

Pilih kunci media.

Separator 108

Kunci pemisah.

Shift 65536

Tombol pengubah SHIFT.

ShiftKey 16

Tombol SHIFT.

Sleep 95

Kunci tidur komputer.

Snapshot 44

Tombol PRINT SCREEN.

Space 32

Kunci SPACEBAR.

Subtract 109

Pengurangan kunci.

T 84

Kunci T.

Tab 9

Tombol TAB.

U 85

Kunci U.

Up 38

Tombol PANAH ATAS.

V 86

Kunci V.

VolumeDown 174

Tombol volume turun.

VolumeMute 173

Tombol matikan suara volume.

VolumeUp 175

Kunci volume naik.

W 87

Kunci W.

X 88

Kunci X.

XButton1 5

Tombol x mouse pertama (mouse lima tombol).

XButton2 6

Tombol x mouse kedua (mouse lima tombol).

Y 89

Kunci Y.

Z 90

Kunci Z.

Zoom 251

Tombol ZOOM.

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 == true )
      {         // 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 == true)
    {
        // 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 (API) Win32, nilai kunci memiliki dua bagian, dengan bit urutan tinggi yang berisi kode kunci (yang sama dengan kode kunci virtual Windows), dan bit berurutan rendah yang mewakili pengubah kunci seperti tombol SHIFT, CONTROL, dan ALT.

Peringatan

Jangan gunakan nilai dalam enumerasi ini untuk operasi bitwise gabungan. Nilai dalam enumerasi tidak saling eksklusif.

Catatan

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 GetKeyStateWindows API , , GetAsyncKeyStateatau GetKeyboardState yang 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 U.S.-keyboard yang lebih spesifik.

Nilai heksadesimal Keyboard A.S. OEM Umum
BA OemSemicolon Oem1
BF OemQuestion Oem2
C0 Oemtilde Oem3
DB OemOpenBrackets Oem4
DC OemPipe Oem5
DD OemCloseBrackets Oem6
DE OemQuotes Oem7
E2 OemBackslash Oem102

Perhatian

Untuk .NET Framework 2.0, anggota IMEAccept ditambahkan yang menggantikan entri sebelumnya, IMEAceept, yang dieja dengan tidak benar. Versi lama telah dipertahankan untuk kompatibilitas mundur, tetapi dapat dihapus dalam versi .NET Framework mendatang

Berlaku untuk

Lihat juga