Keys Enumerazione

Definizione

Specifica i codici chiave e i modificatori.

Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.

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>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Keys = 
Public Enum Keys
Ereditarietà
Attributi

Campi

Nome Valore Descrizione
Modifiers -65536

Maschera di bit per estrarre modificatori da un valore di chiave.

None 0

Nessun tasto premuto.

LButton 1

Pulsante sinistro del mouse.

RButton 2

Pulsante destro del mouse.

Cancel 3

Tasto CANCEL.

MButton 4

Pulsante centrale del mouse (mouse a tre pulsanti).

XButton1 5

Il primo pulsante x del mouse (mouse a cinque pulsanti).

XButton2 6

Il secondo pulsante x del mouse (mouse a cinque pulsanti).

Back 8

Tasto BACKSPACE.

Tab 9

Tasto TAB.

LineFeed 10

Tasto LINEFEED.

Clear 12

Tasto CLEAR.

Enter 13

Tasto INVIO.

Return 13

Chiave RETURN.

ShiftKey 16

Tasto MAIUSC.

ControlKey 17

Tasto CTRL.

Menu 18

Tasto ALT.

Pause 19

Tasto PAUSE.

Capital 20

Tasto BLOC MAIUSC.

CapsLock 20

Tasto BLOC MAIUSC.

HanguelMode 21

Tasto della modalità Hanguel IME. (mantenuto per la compatibilità; usare HangulMode)

HangulMode 21

Tasto modalità Hangul IME.

KanaMode 21

Tasto kana IME.

JunjaMode 23

Tasto della modalità Junja IME.

FinalMode 24

Tasto di modalità finale IME.

HanjaMode 25

Tasto modalità IME Hanja.

KanjiMode 25

Tasto kanji IME.

Escape 27

Tasto ESC.

IMEConvert 28

Chiave di conversione IME.

IMENonconvert 29

Tasto IME non invertito.

IMEAccept 30

La chiave di accettazione IME sostituisce IMEAceept.

IMEAceept 30

Chiave di accettazione IME. In alternativa, usare IMEAccept obsoleto.

IMEModeChange 31

Tasto di modifica della modalità IME.

Space 32

Tasto BARRA SPAZIATRICE.

PageUp 33

Tasto PAGE UP.

Prior 33

Tasto PAGE UP.

Next 34

Tasto PAGINA GIÙ.

PageDown 34

Tasto PAGINA GIÙ.

End 35

Tasto END.

Home 36

Tasto HOME.

Left 37

Tasto FRECCIA SINISTRA.

Up 38

Tasto FRECCIA SU.

Right 39

Tasto FRECCIA DESTRA.

Down 40

Tasto FRECCIA GIÙ.

Select 41

Tasto SELECT.

Print 42

Tasto PRINT.

Execute 43

Tasto EXECUTE.

PrintScreen 44

Tasto PRINT SCREEN.

Snapshot 44

Tasto PRINT SCREEN.

Insert 45

Tasto INS.

Delete 46

Tasto CANC.

Help 47

Tasto HELP.

D0 48

Tasto 0.

D1 49

Tasto 1.

D2 50

Tasto 2.

D3 51

Tasto 3.

D4 52

Tasto 4.

D5 53

Tasto 5.

D6 54

Tasto 6.

D7 55

Tasto 7.

D8 56

Tasto 8.

D9 57

Tasto 9.

A 65

Tasto A.

B 66

Tasto B.

C 67

Tasto C.

D 68

Tasto D.

E 69

Tasto E.

F 70

Tasto F.

G 71

Tasto G.

H 72

Tasto H.

I 73

La chiave io.

J 74

Tasto J.

K 75

Tasto K.

L 76

Tasto L.

M 77

Tasto M.

N 78

Tasto N.

O 79

Tasto O.

P 80

Tasto P.

Q 81

Tasto Q.

R 82

Tasto R.

S 83

Tasto S.

T 84

Tasto T.

U 85

Tasto U.

V 86

Tasto V.

W 87

Tasto W.

X 88

Tasto X.

Y 89

Tasto Y.

Z 90

Tasto Z.

LWin 91

Tasto logo Windows sinistro (Microsoft tastiera naturale).

RWin 92

Tasto logo Windows destro (Microsoft tastiera naturale).

Apps 93

Tasto applicazione (Microsoft tastiera naturale).

Sleep 95

Tasto di sospensione del computer.

NumPad0 96

Tasto 0 sul tastierino numerico.

NumPad1 97

Tasto 1 sul tastierino numerico.

NumPad2 98

Tasto 2 sul tastierino numerico.

NumPad3 99

Tasto 3 sul tastierino numerico.

NumPad4 100

Tasto 4 sul tastierino numerico.

NumPad5 101

Tasto 5 sul tastierino numerico.

NumPad6 102

Tasto 6 sul tastierino numerico.

NumPad7 103

Tasto 7 sul tastierino numerico.

NumPad8 104

Tasto 8 sul tastierino numerico.

NumPad9 105

Tasto 9 sul tastierino numerico.

Multiply 106

Chiave di moltiplicazione.

Add 107

Tasto add.

Separator 108

Tasto separatore.

Subtract 109

Chiave di sottrazione.

Decimal 110

Chiave decimale.

Divide 111

Chiave di divisione.

F1 112

Tasto F1.

F2 113

Tasto F2.

F3 114

Tasto F3.

F4 115

Tasto F4.

F5 116

Tasto F5.

F6 117

Tasto F6.

F7 118

Tasto F7.

F8 119

Tasto F8.

F9 120

Tasto F9.

F10 121

Tasto F10.

F11 122

Tasto F11.

F12 123

Tasto F12.

F13 124

Tasto F13.

F14 125

Tasto F14.

F15 126

Tasto F15.

F16 127

Tasto F16.

F17 128

Tasto F17.

F18 129

Tasto F18.

F19 130

Tasto F19.

F20 131

Tasto F20.

F21 132

Tasto F21.

F22 133

Tasto F22.

F23 134

Tasto F23.

F24 135

Tasto F24.

NumLock 144

Tasto BLOC NUM.

Scroll 145

Tasto SCROLL LOCK.

LShiftKey 160

Tasto MAIUSC a sinistra.

RShiftKey 161

Tasto MAIUSC a destra.

LControlKey 162

Tasto CTRL sinistro.

RControlKey 163

Tasto CTRL destro.

LMenu 164

Tasto ALT sinistro.

RMenu 165

Tasto ALT destro.

BrowserBack 166

Tasto Indietro del browser.

BrowserForward 167

Tasto di inoltro del browser.

BrowserRefresh 168

Tasto di aggiornamento del browser.

BrowserStop 169

Tasto di arresto del browser.

BrowserSearch 170

Chiave di ricerca del browser.

BrowserFavorites 171

Tasto Preferiti del browser.

BrowserHome 172

Tasto home del browser.

VolumeMute 173

Tasto di disattivazione del volume.

VolumeDown 174

Tasto di riduzione del volume.

VolumeUp 175

Tasto di aumento del volume.

MediaNextTrack 176

Tasto di traccia successivo del supporto.

MediaPreviousTrack 177

Chiave di traccia precedente del supporto.

MediaStop 178

Tasto di arresto multimediale.

MediaPlayPause 179

Tasto pausa riproduzione multimediale.

LaunchMail 180

Chiave di posta di avvio.

SelectMedia 181

Tasto di selezione multimediale.

LaunchApplication1 182

Chiave di avvio dell'applicazione.

LaunchApplication2 183

Tasto due dell'applicazione di avvio.

Oem1 186

Tasto OEM 1.

OemSemicolon 186

Tasto punto e virgola OEM su una tastiera standard statunitense.

Oemplus 187

Tasto PIÙ OEM su qualsiasi tastiera paese/area geografica.

Oemcomma 188

Tasto virgola OEM in qualsiasi tastiera paese/area geografica.

OemMinus 189

Tasto meno OEM in qualsiasi tastiera paese/area geografica.

OemPeriod 190

Tasto punto OEM in qualsiasi tastiera paese/area geografica.

Oem2 191

Tasto OEM 2.

OemQuestion 191

Tasto punto interrogativo OEM su una tastiera standard statunitense.

Oem3 192

Tasto OEM 3.

Oemtilde 192

Tasto tilde OEM su una tastiera standard statunitense.

Oem4 219

Tasto OEM 4.

OemOpenBrackets 219

Tasto tra parentesi quadre aperte OEM su una tastiera standard statunitense.

Oem5 220

Tasto OEM 5.

OemPipe 220

Tasto barra verticale OEM su una tastiera standard statunitense.

Oem6 221

Tasto OEM 6.

OemCloseBrackets 221

Tasto parentesi chiusa OEM su una tastiera standard statunitense.

Oem7 222

Tasto OEM 7.

OemQuotes 222

Tasto tra virgolette singole/doppie OEM su una tastiera standard statunitense.

Oem8 223

Tasto OEM 8.

Oem102 226

Tasto OEM 102.

OemBackslash 226

La parentesi quadra angolare OEM o il tasto barra rovesciata sulla tastiera del tasto RT 102.

ProcessKey 229

Tasto PROCESS KEY.

Packet 231

Usato per passare caratteri Unicode come se fossero sequenze di tasti. Il valore della chiave di pacchetto è la parola bassa di un valore di chiave virtuale a 32 bit usato per i metodi di input non da tastiera.

Attn 246

Tasto ATTN.

Crsel 247

Tasto CRSEL.

Exsel 248

Tasto EXSEL.

EraseEof 249

Tasto ERASE EOF.

Play 250

Tasto PLAY.

Zoom 251

Tasto ZOOM.

NoName 252

Costante riservata per uso futuro.

Pa1 253

Tasto PA1.

OemClear 254

Tasto CLEAR.

KeyCode 65535

Maschera di bit per estrarre un codice chiave da un valore di chiave.

Shift 65536

Tasto di modifica MAIUSC.

Control 131072

Tasto di modifica CTRL.

Alt 262144

Tasto di modifica ALT.

Esempio

Nell'esempio di codice seguente viene utilizzato l'evento KeyDown per determinare il tipo di carattere immesso nel controllo .

   // 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

Commenti

La Keys classe contiene costanti per l'elaborazione dell'input da tastiera. I membri dell'enumerazione Keys sono costituiti da un codice chiave e da un set di modificatori combinati in un singolo valore intero. Nell'API (Application Programming Interface) Win32 un valore di chiave ha due metà, con i bit di ordine elevato contenenti il codice della chiave (che corrisponde a un codice di chiave virtuale Windows) e i bit di ordine basso che rappresentano i modificatori di chiave, ad esempio MAIUSC, CONTROL e ALT.

Avvertimento

Non usare i valori in questa enumerazione per le operazioni bit per bit combinate. I valori nell'enumerazione non si escludono a vicenda.

Note

Questa enumerazione non consente di verificare se i tasti CAPS LOCK o NUM LOCK sono attualmente attivati. È possibile usare una delle tecniche seguenti per determinare se queste chiavi sono attivate:

  • Chiamare il IsKeyLocked metodo della Control classe .

  • Per il controllo più fine, usare le funzioni API Windows GetKeyState, GetAsyncKeyState o GetKeyboardState definite in user32.dll, per eseguire questa operazione. Per altre informazioni sulla chiamata di funzioni native, vedere Utilizzo di funzioni DLL non gestite.

La tabella seguente mostra i valori di codice chiave rappresentati da due valori enumerati, che rappresentano sia i tasti OEM (Original Equipment Manufacturer) generali che le associazioni di tastiera statunitensi più specifiche.

Valore esadecimale Tastiera statunitense OEM generale
BA OemSemicolon Oem1
BF OemQuestion Oem2
C0 Oemtilde Oem3
DB OemOpenBrackets Oem4
DC OemPipe Oem5
DD OemCloseBrackets Oem6
DE OemQuotes Oem7
E2 OemBackslash Oem102

Caution

Per .NET Framework 2.0, è stato aggiunto un membro IMEAccept che sostituisce la voce precedente, IMEAceept, digitata in modo non corretto. La versione precedente è stata mantenuta per la compatibilità con le versioni precedenti, ma potrebbe essere eliminata nelle versioni future di .NET.

Si applica a

Vedi anche