Keys Keys Keys Keys Enum

Definición

Especifica los modificadores y códigos de tecla.Specifies key codes and modifiers.

Esta enumeración tiene el atributo FlagsAttribute, que permite una combinación bit a bit de sus valores de miembro.

public enum class Keys
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.KeysConverter))]
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum Keys
type Keys = 
Public Enum Keys
Herencia
Atributos

Campos

A A A A 65

Tecla A.The A key.

Add Add Add Add 107

Tecla agregar.The add key.

Alt Alt Alt Alt 262144

Tecla modificadora ALT.The ALT modifier key.

Apps Apps Apps Apps 93

La clave de aplicación (Microsoft Natural Keyboard).The application key (Microsoft Natural Keyboard).

Attn Attn Attn Attn 246

Tecla ATTN.The ATTN key.

B B B B 66

Tecla B.The B key.

Back Back Back Back 8

Tecla RETROCESO.The BACKSPACE key.

BrowserBack BrowserBack BrowserBack BrowserBack 166

Tecla Atrás del explorador (Windows 2000 o posterior).The browser back key (Windows 2000 or later).

BrowserFavorites BrowserFavorites BrowserFavorites BrowserFavorites 171

Tecla Favoritos del explorador (Windows 2000 o posterior).The browser favorites key (Windows 2000 or later).

BrowserForward BrowserForward BrowserForward BrowserForward 167

La tecla adelante del explorador (Windows 2000 o posterior).The browser forward key (Windows 2000 or later).

BrowserHome BrowserHome BrowserHome BrowserHome 172

Tecla Inicio (Windows 2000 o posterior) del explorador.The browser home key (Windows 2000 or later).

BrowserRefresh BrowserRefresh BrowserRefresh BrowserRefresh 168

Tecla Actualizar del explorador (Windows 2000 o posterior).The browser refresh key (Windows 2000 or later).

BrowserSearch BrowserSearch BrowserSearch BrowserSearch 170

La clave de búsqueda del explorador (Windows 2000 o posterior).The browser search key (Windows 2000 or later).

BrowserStop BrowserStop BrowserStop BrowserStop 169

Tecla Detener del explorador (Windows 2000 o posterior).The browser stop key (Windows 2000 or later).

C C C C 67

Tecla C.The C key.

Cancel Cancel Cancel Cancel 3

Tecla Cancelar.The CANCEL key.

Capital Capital Capital Capital 20

La tecla BLOQ MAYÚS.The CAPS LOCK key.

CapsLock CapsLock CapsLock CapsLock 20

La tecla BLOQ MAYÚS.The CAPS LOCK key.

Clear Clear Clear Clear 12

Tecla BORRAR.The CLEAR key.

Control Control Control Control 131072

Tecla modificadora CTRL.The CTRL modifier key.

ControlKey ControlKey ControlKey ControlKey 17

La tecla CTRL.The CTRL key.

Crsel Crsel Crsel Crsel 247

Tecla CRSEL.The CRSEL key.

D D D D 68

Tecla D.The D key.

D0 D0 D0 D0 48

Tecla 0.The 0 key.

D1 D1 D1 D1 49

Tecla 1.The 1 key.

D2 D2 D2 D2 50

Tecla 2.The 2 key.

D3 D3 D3 D3 51

Tecla 3.The 3 key.

D4 D4 D4 D4 52

Tecla 4.The 4 key.

D5 D5 D5 D5 53

Tecla 5.The 5 key.

D6 D6 D6 D6 54

Tecla 6.The 6 key.

D7 D7 D7 D7 55

Tecla 7.The 7 key.

D8 D8 D8 D8 56

Tecla 8.The 8 key.

D9 D9 D9 D9 57

Tecla 9.The 9 key.

Decimal Decimal Decimal Decimal 110

Tecla decimal.The decimal key.

Delete Delete Delete Delete 46

La tecla SUPR.The DEL key.

Divide Divide Divide Divide 111

Tecla dividir.The divide key.

Down Down Down Down 40

Tecla FLECHA ABAJO.The DOWN ARROW key.

E E E E 69

Tecla E.The E key.

End End End End 35

Tecla FIN.The END key.

Enter Enter Enter Enter 13

Tecla ENTRAR.The ENTER key.

EraseEof EraseEof EraseEof EraseEof 249

Tecla ERASE EOF.The ERASE EOF key.

Escape Escape Escape Escape 27

Tecla ESC.The ESC key.

Execute Execute Execute Execute 43

Tecla EJECUTAR.The EXECUTE key.

Exsel Exsel Exsel Exsel 248

Tecla EXSEL.The EXSEL key.

F F F F 70

Tecla F.The F key.

F1 F1 F1 F1 112

Tecla F1.The F1 key.

F10 F10 F10 F10 121

Tecla F10.The F10 key.

F11 F11 F11 F11 122

Tecla F11.The F11 key.

F12 F12 F12 F12 123

Tecla F12.The F12 key.

F13 F13 F13 F13 124

Tecla F13.The F13 key.

F14 F14 F14 F14 125

Tecla F14.The F14 key.

F15 F15 F15 F15 126

Tecla F15.The F15 key.

F16 F16 F16 F16 127

Tecla F16.The F16 key.

F17 F17 F17 F17 128

Tecla F17.The F17 key.

F18 F18 F18 F18 129

Tecla F18.The F18 key.

F19 F19 F19 F19 130

Tecla F19.The F19 key.

F2 F2 F2 F2 113

Tecla F2.The F2 key.

F20 F20 F20 F20 131

Tecla F20.The F20 key.

F21 F21 F21 F21 132

Tecla F21.The F21 key.

F22 F22 F22 F22 133

Tecla F22.The F22 key.

F23 F23 F23 F23 134

Tecla F23.The F23 key.

F24 F24 F24 F24 135

Tecla F24.The F24 key.

F3 F3 F3 F3 114

Tecla F3.The F3 key.

F4 F4 F4 F4 115

Tecla F4.The F4 key.

F5 F5 F5 F5 116

Tecla F5.The F5 key.

F6 F6 F6 F6 117

Tecla F6.The F6 key.

F7 F7 F7 F7 118

Tecla F7.The F7 key.

F8 F8 F8 F8 119

Tecla F8.The F8 key.

F9 F9 F9 F9 120

Tecla F9.The F9 key.

FinalMode FinalMode FinalMode FinalMode 24

La clave de modo final de IME.The IME final mode key.

G G G G 71

Tecla G.The G key.

H H H H 72

Tecla H.The H key.

HanguelMode HanguelMode HanguelMode HanguelMode 21

La clave de modo Hanguel de IME.The IME Hanguel mode key. (se mantiene por compatibilidad; use HangulMode)(maintained for compatibility; use HangulMode)

HangulMode HangulMode HangulMode HangulMode 21

Tecla de modo Hangul de IME.The IME Hangul mode key.

HanjaMode HanjaMode HanjaMode HanjaMode 25

Tecla de modo Hanja de IME.The IME Hanja mode key.

Help Help Help Help 47

Tecla AYUDA.The HELP key.

Home Home Home Home 36

Tecla INICIO.The HOME key.

I I I I 73

Tecla I.The I key.

IMEAccept IMEAccept IMEAccept IMEAccept 30

El IME acepte clave, reemplaza IMEAceept.The IME accept key, replaces IMEAceept.

IMEAceept IMEAceept IMEAceept IMEAceept 30

Tecla Aceptar de IME.The IME accept key. Obsoleto, utilice IMEAccept en su lugar.Obsolete, use IMEAccept instead.

IMEConvert IMEConvert IMEConvert IMEConvert 28

La clave de conversión IME.The IME convert key.

IMEModeChange IMEModeChange IMEModeChange IMEModeChange 31

La clave de cambio del modo IME.The IME mode change key.

IMENonconvert IMENonconvert IMENonconvert IMENonconvert 29

La tecla no convertir IME.The IME nonconvert key.

Insert Insert Insert Insert 45

Tecla INS.The INS key.

J J J J 74

Tecla J.The J key.

JunjaMode JunjaMode JunjaMode JunjaMode 23

Tecla de modo Junja de IME.The IME Junja mode key.

K K K K 75

Tecla K.The K key.

KanaMode KanaMode KanaMode KanaMode 21

Tecla de modo Kana de IME.The IME Kana mode key.

KanjiMode KanjiMode KanjiMode KanjiMode 25

Tecla de modo Kanji de IME.The IME Kanji mode key.

KeyCode KeyCode KeyCode KeyCode 65535

La máscara de bits para extraer un código de tecla de un valor de clave.The bitmask to extract a key code from a key value.

L L L L 76

Tecla L.The L key.

LaunchApplication1 LaunchApplication1 LaunchApplication1 LaunchApplication1 182

Tecla Iniciar aplicación uno (Windows 2000 o posterior).The start application one key (Windows 2000 or later).

LaunchApplication2 LaunchApplication2 LaunchApplication2 LaunchApplication2 183

Tecla Iniciar aplicación dos (Windows 2000 o posterior).The start application two key (Windows 2000 or later).

LaunchMail LaunchMail LaunchMail LaunchMail 180

Tecla Iniciar correo (Windows 2000 o posterior).The launch mail key (Windows 2000 or later).

LButton LButton LButton LButton 1

El botón primario del mouse.The left mouse button.

LControlKey LControlKey LControlKey LControlKey 162

Tecla CTRL izquierda.The left CTRL key.

Left Left Left Left 37

Tecla FLECHA IZQUIERDA.The LEFT ARROW key.

LineFeed LineFeed LineFeed LineFeed 10

Tecla avance de línea.The LINEFEED key.

LMenu LMenu LMenu LMenu 164

Tecla ALT izquierda.The left ALT key.

LShiftKey LShiftKey LShiftKey LShiftKey 160

Tecla MAYÚS izquierda.The left SHIFT key.

LWin LWin LWin LWin 91

Tecla del logotipo de Windows izquierda (Microsoft Natural Keyboard).The left Windows logo key (Microsoft Natural Keyboard).

M M M M 77

Tecla M.The M key.

MButton MButton MButton MButton 4

El botón central del mouse (mouse de tres botones).The middle mouse button (three-button mouse).

MediaNextTrack MediaNextTrack MediaNextTrack MediaNextTrack 176

La tecla multimedia pista siguiente (Windows 2000 o posterior).The media next track key (Windows 2000 or later).

MediaPlayPause MediaPlayPause MediaPlayPause MediaPlayPause 179

Tecla Pausa (Windows 2000 o posterior) de reproducción de multimedia.The media play pause key (Windows 2000 or later).

MediaPreviousTrack MediaPreviousTrack MediaPreviousTrack MediaPreviousTrack 177

La media tecla pista anterior (Windows 2000 o posterior).The media previous track key (Windows 2000 or later).

MediaStop MediaStop MediaStop MediaStop 178

La clave de detención de multimedia (Windows 2000 o posterior).The media Stop key (Windows 2000 or later).

Menu Menu Menu Menu 18

La tecla ALT.The ALT key.

Modifiers Modifiers Modifiers Modifiers -65536

La máscara de bits para extraer modificadores de un valor de clave.The bitmask to extract modifiers from a key value.

Multiply Multiply Multiply Multiply 106

Tecla multiplicar.The multiply key.

N N N N 78

Tecla N.The N key.

Next Next Next Next 34

Tecla AV PÁG.The PAGE DOWN key.

NoName NoName NoName NoName 252

Constante reservada para un uso futuro.A constant reserved for future use.

None None None None 0

Ninguna tecla presionada.No key pressed.

NumLock NumLock NumLock NumLock 144

La tecla BLOQ NUM.The NUM LOCK key.

NumPad0 NumPad0 NumPad0 NumPad0 96

Tecla 0 del teclado numérico.The 0 key on the numeric keypad.

NumPad1 NumPad1 NumPad1 NumPad1 97

Tecla 1 del teclado numérico.The 1 key on the numeric keypad.

NumPad2 NumPad2 NumPad2 NumPad2 98

Tecla 2 del teclado numérico.The 2 key on the numeric keypad.

NumPad3 NumPad3 NumPad3 NumPad3 99

Tecla 3 del teclado numérico.The 3 key on the numeric keypad.

NumPad4 NumPad4 NumPad4 NumPad4 100

Tecla 4 del teclado numérico.The 4 key on the numeric keypad.

NumPad5 NumPad5 NumPad5 NumPad5 101

Tecla 5 del teclado numérico.The 5 key on the numeric keypad.

NumPad6 NumPad6 NumPad6 NumPad6 102

Tecla 6 del teclado numérico.The 6 key on the numeric keypad.

NumPad7 NumPad7 NumPad7 NumPad7 103

Tecla 7 del teclado numérico.The 7 key on the numeric keypad.

NumPad8 NumPad8 NumPad8 NumPad8 104

Tecla 8 del teclado numérico.The 8 key on the numeric keypad.

NumPad9 NumPad9 NumPad9 NumPad9 105

Tecla 9 del teclado numérico.The 9 key on the numeric keypad.

O O O O 79

Tecla O.The O key.

Oem1 Oem1 Oem1 Oem1 186

Tecla 1 de OEM.The OEM 1 key.

Oem102 Oem102 Oem102 Oem102 226

Tecla 102 de OEM.The OEM 102 key.

Oem2 Oem2 Oem2 Oem2 191

Tecla 2 de OEM.The OEM 2 key.

Oem3 Oem3 Oem3 Oem3 192

Tecla 3 de OEM.The OEM 3 key.

Oem4 Oem4 Oem4 Oem4 219

Tecla 4 de OEM.The OEM 4 key.

Oem5 Oem5 Oem5 Oem5 220

Tecla 5 de OEM.The OEM 5 key.

Oem6 Oem6 Oem6 Oem6 221

Tecla 6 de OEM.The OEM 6 key.

Oem7 Oem7 Oem7 Oem7 222

Tecla 7 de OEM.The OEM 7 key.

Oem8 Oem8 Oem8 Oem8 223

Tecla 8 de OEM.The OEM 8 key.

OemBackslash OemBackslash OemBackslash OemBackslash 226

El corchete angular de OEM o la clave de barra diagonal inversa en la RT de 102 teclas (Windows 2000 o posterior).The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows 2000 or later).

OemClear OemClear OemClear OemClear 254

Tecla BORRAR.The CLEAR key.

OemCloseBrackets OemCloseBrackets OemCloseBrackets OemCloseBrackets 221

Tecla de corchete de cierre OEM en un teclado US estándar (Windows 2000 o posterior).The OEM close bracket key on a US standard keyboard (Windows 2000 or later).

Oemcomma Oemcomma Oemcomma Oemcomma 188

La tecla de coma OEM en un teclado de cualquier país o región (Windows 2000 o posterior).The OEM comma key on any country/region keyboard (Windows 2000 or later).

OemMinus OemMinus OemMinus OemMinus 189

La tecla menos OEM en un teclado de cualquier país o región (Windows 2000 o posterior).The OEM minus key on any country/region keyboard (Windows 2000 or later).

OemOpenBrackets OemOpenBrackets OemOpenBrackets OemOpenBrackets 219

Tecla de corchete de apertura OEM en un teclado US estándar (Windows 2000 o posterior).The OEM open bracket key on a US standard keyboard (Windows 2000 or later).

OemPeriod OemPeriod OemPeriod OemPeriod 190

Tecla de punto OEM en un teclado de cualquier país o región (Windows 2000 o posterior).The OEM period key on any country/region keyboard (Windows 2000 or later).

OemPipe OemPipe OemPipe OemPipe 220

La clave de barra vertical OEM en un teclado US estándar (Windows 2000 o posterior).The OEM pipe key on a US standard keyboard (Windows 2000 or later).

Oemplus Oemplus Oemplus Oemplus 187

Los OEM además de la clave en un teclado de cualquier país o región (Windows 2000 o posterior).The OEM plus key on any country/region keyboard (Windows 2000 or later).

OemQuestion OemQuestion OemQuestion OemQuestion 191

Tecla de signo de interrogación OEM en un teclado US estándar (Windows 2000 o posterior).The OEM question mark key on a US standard keyboard (Windows 2000 or later).

OemQuotes OemQuotes OemQuotes OemQuotes 222

Los simples y dobles OEM tecla de comillas en un teclado US estándar (Windows 2000 o posterior).The OEM singled/double quote key on a US standard keyboard (Windows 2000 or later).

OemSemicolon OemSemicolon OemSemicolon OemSemicolon 186

La clave de punto y coma OEM en un teclado US estándar (Windows 2000 o posterior).The OEM Semicolon key on a US standard keyboard (Windows 2000 or later).

Oemtilde Oemtilde Oemtilde Oemtilde 192

La tecla de tilde OEM en un teclado US estándar (Windows 2000 o posterior).The OEM tilde key on a US standard keyboard (Windows 2000 or later).

P P P P 80

Tecla P.The P key.

Pa1 Pa1 Pa1 Pa1 253

Tecla PA1.The PA1 key.

Packet Packet Packet Packet 231

Se usa para pasar caracteres Unicode como si fueran pulsaciones de teclas.Used to pass Unicode characters as if they were keystrokes. El valor de clave de paquete es la palabra baja de un valor de tecla virtual de 32 bits utilizado para métodos de entrada sin teclado.The Packet key value is the low word of a 32-bit virtual-key value used for non-keyboard input methods.

PageDown PageDown PageDown PageDown 34

Tecla AV PÁG.The PAGE DOWN key.

PageUp PageUp PageUp PageUp 33

Tecla RE PÁG.The PAGE UP key.

Pause Pause Pause Pause 19

Tecla PAUSA.The PAUSE key.

Play Play Play Play 250

Tecla PLAY.The PLAY key.

Print Print Print Print 42

Tecla IMPRIMIR.The PRINT key.

PrintScreen PrintScreen PrintScreen PrintScreen 44

Tecla IMPRIMIR PANTALLA.The PRINT SCREEN key.

Prior Prior Prior Prior 33

Tecla RE PÁG.The PAGE UP key.

ProcessKey ProcessKey ProcessKey ProcessKey 229

TECLA PROCESS key.The PROCESS KEY key.

Q Q Q Q 81

Tecla Q.The Q key.

R R R R 82

Tecla R.The R key.

RButton RButton RButton RButton 2

El botón secundario del mouse.The right mouse button.

RControlKey RControlKey RControlKey RControlKey 163

Tecla CTRL derecha.The right CTRL key.

Return Return Return Return 13

La tecla ENTRAR.The RETURN key.

Right Right Right Right 39

Tecla FLECHA DERECHA.The RIGHT ARROW key.

RMenu RMenu RMenu RMenu 165

Tecla ALT derecha.The right ALT key.

RShiftKey RShiftKey RShiftKey RShiftKey 161

Tecla MAYÚS derecha.The right SHIFT key.

RWin RWin RWin RWin 92

Tecla del logotipo de Windows derecha (Microsoft Natural Keyboard).The right Windows logo key (Microsoft Natural Keyboard).

S S S S 83

Tecla S.The S key.

Scroll Scroll Scroll Scroll 145

Tecla Bloq Despl.The SCROLL LOCK key.

Select Select Select Select 41

Tecla SELECCIONAR.The SELECT key.

SelectMedia SelectMedia SelectMedia SelectMedia 181

La tecla Seleccionar reproducción de multimedia (Windows 2000 o posterior).The select media key (Windows 2000 or later).

Separator Separator Separator Separator 108

Tecla separador.The separator key.

Shift Shift Shift Shift 65536

Tecla modificadora MAYÚS.The SHIFT modifier key.

ShiftKey ShiftKey ShiftKey ShiftKey 16

La tecla MAYÚS.The SHIFT key.

Sleep Sleep Sleep Sleep 95

La tecla de suspensión del equipo.The computer sleep key.

Snapshot Snapshot Snapshot Snapshot 44

Tecla IMPRIMIR PANTALLA.The PRINT SCREEN key.

Space Space Space Space 32

Tecla BARRA ESPACIADORA.The SPACEBAR key.

Subtract Subtract Subtract Subtract 109

Tecla restar.The subtract key.

T T T T 84

Tecla T.The T key.

Tab Tab Tab Tab 9

Tecla TAB.The TAB key.

U U U U 85

Tecla U.The U key.

Up Up Up Up 38

Tecla FLECHA ARRIBA.The UP ARROW key.

V V V V 86

Tecla V.The V key.

VolumeDown VolumeDown VolumeDown VolumeDown 174

El volumen presionada (Windows 2000 o posterior).The volume down key (Windows 2000 or later).

VolumeMute VolumeMute VolumeMute VolumeMute 173

Tecla Silenciar el volumen (Windows 2000 o posterior).The volume mute key (Windows 2000 or later).

VolumeUp VolumeUp VolumeUp VolumeUp 175

El volumen de clave (Windows 2000 o posterior).The volume up key (Windows 2000 or later).

W W W W 87

Tecla W.The W key.

X X X X 88

Tecla X.The X key.

XButton1 XButton1 XButton1 XButton1 5

El primer botón x del mouse (mouse de cinco botones).The first x mouse button (five-button mouse).

XButton2 XButton2 XButton2 XButton2 6

El segundo botón x del mouse (mouse de cinco botones).The second x mouse button (five-button mouse).

Y Y Y Y 89

Tecla Y.The Y key.

Z Z Z Z 90

Tecla Z.The Z key.

Zoom Zoom Zoom Zoom 251

Tecla ZOOM.The ZOOM key.

Ejemplos

El siguiente ejemplo de código utiliza el KeyDown evento para determinar el tipo de carácter especificado en el control.The following code example uses the KeyDown event to determine the type of character entered into the control.

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


' 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 'textBox1_KeyPress

Comentarios

La Keys clase contiene constantes para el procesamiento de entrada de teclado.The Keys class contains constants for processing keyboard input. Los miembros de la enumeración de claves constan de un código de tecla y un conjunto de modificadores combinados en un único valor entero.The members of the Keys enumeration consist of a key code and a set of modifiers combined into a single integer value. En Win32, interfaz de programación de aplicaciones (API) un valor de clave tiene dos mitades, con los bits de orden superior que contiene el código de tecla (que es el mismo que un código de tecla virtual de Windows) y los bits de orden inferior que representan los modificadores claves como ALT, CONTROL y MAYÚS claves.In the Win32 application programming interface (API) a key value has two halves, with the high-order bits containing the key code (which is the same as a Windows virtual key code), and the low-order bits representing key modifiers such as the SHIFT, CONTROL, and ALT keys.

Advertencia

No use los valores de esta enumeración para las operaciones bit a bit combinadas.Do not use the values in this enumeration for combined bitwise operations. Los valores de la enumeración no son mutuamente excluyentes.The values in the enumeration are not mutually exclusive.

Nota

Esta enumeración no proporciona ninguna manera de comprobar si las teclas BLOQ NUM o BLOQ NUM están activadas actualmente.This enumeration provides no way to test whether the CAPS LOCK or NUM LOCK keys are currently activated. Puede usar una de las técnicas siguientes para determinar si se activan estas claves:You can use one of the following techniques to determine if these keys are activated:

  • Llame al método IsKeyLocked de la clase Control .Call the IsKeyLocked method of the Control class.

  • Para un control más preciso, utilice las funciones de API de Windows GetKeyState, GetAsyncKeyState, o GetKeyboardState definido en user32.dll, para ello.For finer control, use the Windows API functions GetKeyState, GetAsyncKeyState, or GetKeyboardState defined in user32.dll, to do this. Para obtener más información sobre cómo llamar a funciones nativas, vea consumir funciones de DLL no administradas.For more information about calling native functions, see Consuming Unmanaged DLL Functions.

En la siguiente tabla muestra los valores de código de tecla representados por dos valores enumerados, que representan las claves general fabricante de equipos originales (OEM) y las asociaciones más específicas del teclado de Estados Unidos.The following table shows the key code values represented by two enumerated values, representing both the general original equipment manufacturer (OEM) keys and the more specific U.S.-keyboard associations.

Valor hexadecimalHexadecimal value Teclado de EE. UU.U.S. keyboard OEM generalGeneral OEM
BABA OemSemicolonOemSemicolon Oem1Oem1
BFBF OemQuestionOemQuestion Oem2Oem2
C0C0 OemtildeOemtilde Oem3Oem3
DBDB OemOpenBracketsOemOpenBrackets Oem4Oem4
DCDC OemPipeOemPipe Oem5Oem5
DDDD OemCloseBracketsOemCloseBrackets Oem6Oem6
DEDE OemQuotesOemQuotes Oem7Oem7
E2E2 OemBackslashOemBackslash Oem102Oem102

Precaución

Para .NET Framework 2.0, se ha agregado un miembro IMEAccept que reemplaza la entrada anterior, IMEAceept, que se ha escrito incorrectamente.For the .NET Framework 2.0, a member IMEAccept was added that supersedes the previous entry, IMEAceept, which was spelled incorrectly. La versión más antigua ha conservado para la compatibilidad con versiones anteriores, pero se puede eliminar en versiones futuras de .NET FrameworkThe older version has been retained for backward compatibility, but it may be deleted in future versions of the .NET Framework

Se aplica a

Consulte también: