Keys Keys Keys Keys Enum

Definição

Especifica os modificadores e códigos de tecla.Specifies key codes and modifiers.

Esta enumeração tem um atributo FlagsAttribute que permite uma combinação bit a bit dos seus valores membros.

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
Herança
Atributos

Campos

A A A A 65

A tecla A.The A key.

Add Add Add Add 107

A tecla Adicionar.The add key.

Alt Alt Alt Alt 262144

A tecla modificadora ALT.The ALT modifier key.

Apps Apps Apps Apps 93

A tecla Aplicativo (Microsoft Natural Keyboard).The application key (Microsoft Natural Keyboard).

Attn Attn Attn Attn 246

A tecla ATTN.The ATTN key.

B B B B 66

A tecla B.The B key.

Back Back Back Back 8

A tecla BACKSPACE.The BACKSPACE key.

BrowserBack BrowserBack BrowserBack BrowserBack 166

A tecla Voltar do navegador (Windows 2000 ou posterior).The browser back key (Windows 2000 or later).

BrowserFavorites BrowserFavorites BrowserFavorites BrowserFavorites 171

A tecla Favoritos do navegador (Windows 2000 ou posterior).The browser favorites key (Windows 2000 or later).

BrowserForward BrowserForward BrowserForward BrowserForward 167

A tecla Avançar do navegador (Windows 2000 ou posterior).The browser forward key (Windows 2000 or later).

BrowserHome BrowserHome BrowserHome BrowserHome 172

A tecla Início do navegador (Windows 2000 ou posterior).The browser home key (Windows 2000 or later).

BrowserRefresh BrowserRefresh BrowserRefresh BrowserRefresh 168

A tecla Atualizar do navegador (Windows 2000 ou posterior).The browser refresh key (Windows 2000 or later).

BrowserSearch BrowserSearch BrowserSearch BrowserSearch 170

A tecla Pesquisar do navegador (Windows 2000 ou posterior).The browser search key (Windows 2000 or later).

BrowserStop BrowserStop BrowserStop BrowserStop 169

A tecla Parar do navegador (Windows 2000 ou posterior).The browser stop key (Windows 2000 or later).

C C C C 67

A tecla C.The C key.

Cancel Cancel Cancel Cancel 3

A tecla CANCEL.The CANCEL key.

Capital Capital Capital Capital 20

A tecla CAPS LOCK.The CAPS LOCK key.

CapsLock CapsLock CapsLock CapsLock 20

A tecla CAPS LOCK.The CAPS LOCK key.

Clear Clear Clear Clear 12

A tecla CLEAR.The CLEAR key.

Control Control Control Control 131072

A tecla modificadora CTRL.The CTRL modifier key.

ControlKey ControlKey ControlKey ControlKey 17

A tecla CTRL.The CTRL key.

Crsel Crsel Crsel Crsel 247

A tecla CRSEL.The CRSEL key.

D D D D 68

A tecla D.The D key.

D0 D0 D0 D0 48

A tecla 0.The 0 key.

D1 D1 D1 D1 49

A tecla 1.The 1 key.

D2 D2 D2 D2 50

A tecla 2.The 2 key.

D3 D3 D3 D3 51

A tecla 3.The 3 key.

D4 D4 D4 D4 52

A tecla 4.The 4 key.

D5 D5 D5 D5 53

A tecla 5.The 5 key.

D6 D6 D6 D6 54

A tecla 6.The 6 key.

D7 D7 D7 D7 55

A tecla 7.The 7 key.

D8 D8 D8 D8 56

A tecla 8.The 8 key.

D9 D9 D9 D9 57

A tecla 9.The 9 key.

Decimal Decimal Decimal Decimal 110

A tecla Decimal.The decimal key.

Delete Delete Delete Delete 46

A tecla DEL.The DEL key.

Divide Divide Divide Divide 111

A tecla Dividir.The divide key.

Down Down Down Down 40

A tecla SETA PARA BAIXO.The DOWN ARROW key.

E E E E 69

A tecla E.The E key.

End End End End 35

A tecla END.The END key.

Enter Enter Enter Enter 13

A tecla ENTER.The ENTER key.

EraseEof EraseEof EraseEof EraseEof 249

A tecla ERASE EOF.The ERASE EOF key.

Escape Escape Escape Escape 27

A tecla ESC.The ESC key.

Execute Execute Execute Execute 43

A tecla EXECUTE.The EXECUTE key.

Exsel Exsel Exsel Exsel 248

A tecla EXSEL.The EXSEL key.

F F F F 70

A tecla F.The F key.

F1 F1 F1 F1 112

A tecla F1.The F1 key.

F10 F10 F10 F10 121

A tecla F10.The F10 key.

F11 F11 F11 F11 122

A tecla F11.The F11 key.

F12 F12 F12 F12 123

A tecla F12.The F12 key.

F13 F13 F13 F13 124

A tecla F13.The F13 key.

F14 F14 F14 F14 125

A tecla F14.The F14 key.

F15 F15 F15 F15 126

A tecla F15.The F15 key.

F16 F16 F16 F16 127

A tecla F16.The F16 key.

F17 F17 F17 F17 128

A tecla F17.The F17 key.

F18 F18 F18 F18 129

A tecla F18.The F18 key.

F19 F19 F19 F19 130

A tecla F19.The F19 key.

F2 F2 F2 F2 113

A tecla F2.The F2 key.

F20 F20 F20 F20 131

A tecla F20.The F20 key.

F21 F21 F21 F21 132

A tecla F21.The F21 key.

F22 F22 F22 F22 133

A tecla F22.The F22 key.

F23 F23 F23 F23 134

A tecla F23.The F23 key.

F24 F24 F24 F24 135

A tecla F24.The F24 key.

F3 F3 F3 F3 114

A tecla F3.The F3 key.

F4 F4 F4 F4 115

A tecla F4.The F4 key.

F5 F5 F5 F5 116

A tecla F5.The F5 key.

F6 F6 F6 F6 117

A tecla F6.The F6 key.

F7 F7 F7 F7 118

A tecla F7.The F7 key.

F8 F8 F8 F8 119

A tecla F8.The F8 key.

F9 F9 F9 F9 120

A tecla F9.The F9 key.

FinalMode FinalMode FinalMode FinalMode 24

A tecla do modo final do IME.The IME final mode key.

G G G G 71

A tecla G.The G key.

H H H H 72

A tecla H.The H key.

HanguelMode HanguelMode HanguelMode HanguelMode 21

A tecla do modo IME Hanguel.The IME Hanguel mode key. (mantida para compatibilidade, use HangulMode)(maintained for compatibility; use HangulMode)

HangulMode HangulMode HangulMode HangulMode 21

A tecla do modo IME Hangul.The IME Hangul mode key.

HanjaMode HanjaMode HanjaMode HanjaMode 25

A tecla do modo IME Hanja.The IME Hanja mode key.

Help Help Help Help 47

A tecla HELP.The HELP key.

Home Home Home Home 36

A tecla HOME.The HOME key.

I I I I 73

A tecla I.The I key.

IMEAccept IMEAccept IMEAccept IMEAccept 30

A tecla de aceitação do IME, substitui IMEAceept.The IME accept key, replaces IMEAceept.

IMEAceept IMEAceept IMEAceept IMEAceept 30

A tecla de aceitação do IME.The IME accept key. Obsoleta, use IMEAccept em seu lugar.Obsolete, use IMEAccept instead.

IMEConvert IMEConvert IMEConvert IMEConvert 28

A tecla de conversão do IME.The IME convert key.

IMEModeChange IMEModeChange IMEModeChange IMEModeChange 31

A tecla de alteração do modo IME.The IME mode change key.

IMENonconvert IMENonconvert IMENonconvert IMENonconvert 29

A tecla IME nonconvert.The IME nonconvert key.

Insert Insert Insert Insert 45

A tecla INS.The INS key.

J J J J 74

A tecla J.The J key.

JunjaMode JunjaMode JunjaMode JunjaMode 23

A tecla do modo IME Junja.The IME Junja mode key.

K K K K 75

A tecla K.The K key.

KanaMode KanaMode KanaMode KanaMode 21

A tecla do modo IME Kana.The IME Kana mode key.

KanjiMode KanjiMode KanjiMode KanjiMode 25

A tecla do modo IME Kanji.The IME Kanji mode key.

KeyCode KeyCode KeyCode KeyCode 65535

O bitmask para extrair um código de tecla de um valor de tecla.The bitmask to extract a key code from a key value.

L L L L 76

A tecla L.The L key.

LaunchApplication1 LaunchApplication1 LaunchApplication1 LaunchApplication1 182

A tecla Iniciar Aplicativo Um (Windows 2000 ou posterior).The start application one key (Windows 2000 or later).

LaunchApplication2 LaunchApplication2 LaunchApplication2 LaunchApplication2 183

A tecla Iniciar Aplicativo Dois (Windows 2000 ou posterior).The start application two key (Windows 2000 or later).

LaunchMail LaunchMail LaunchMail LaunchMail 180

A tecla Iniciar Email (Windows 2000 ou posterior).The launch mail key (Windows 2000 or later).

LButton LButton LButton LButton 1

O botão esquerdo do mouse.The left mouse button.

LControlKey LControlKey LControlKey LControlKey 162

A tecla CTRL esquerda.The left CTRL key.

Left Left Left Left 37

A tecla SETA PARA A ESQUERDA.The LEFT ARROW key.

LineFeed LineFeed LineFeed LineFeed 10

A tecla LINEFEED.The LINEFEED key.

LMenu LMenu LMenu LMenu 164

A tecla ALT esquerda.The left ALT key.

LShiftKey LShiftKey LShiftKey LShiftKey 160

A tecla SHIFT esquerda.The left SHIFT key.

LWin LWin LWin LWin 91

A tecla esquerda do logotipo do Windows (Microsoft Natural Keyboard).The left Windows logo key (Microsoft Natural Keyboard).

M M M M 77

A tecla M.The M key.

MButton MButton MButton MButton 4

O botão do meio do mouse (mouse de três botões).The middle mouse button (three-button mouse).

MediaNextTrack MediaNextTrack MediaNextTrack MediaNextTrack 176

A tecla Próxima Faixa de Mídia (Windows 2000 ou posterior).The media next track key (Windows 2000 or later).

MediaPlayPause MediaPlayPause MediaPlayPause MediaPlayPause 179

A tecla Reproduzir/Pausar Mídia (Windows 2000 ou posterior).The media play pause key (Windows 2000 or later).

MediaPreviousTrack MediaPreviousTrack MediaPreviousTrack MediaPreviousTrack 177

A tecla Faixa Anterior de Mídia (Windows 2000 ou posterior).The media previous track key (Windows 2000 or later).

MediaStop MediaStop MediaStop MediaStop 178

A tecla Parar Mídia (Windows 2000 ou posterior).The media Stop key (Windows 2000 or later).

Menu Menu Menu Menu 18

A tecla ALT.The ALT key.

Modifiers Modifiers Modifiers Modifiers -65536

O bitmask para extrair os modificadores de um valor de tecla.The bitmask to extract modifiers from a key value.

Multiply Multiply Multiply Multiply 106

A tecla Multiply.The multiply key.

N N N N 78

A tecla N.The N key.

Next Next Next Next 34

A tecla PAGE DOWN.The PAGE DOWN key.

NoName NoName NoName NoName 252

Uma constante reservada para uso futuro.A constant reserved for future use.

None None None None 0

Nenhuma tecla pressionada.No key pressed.

NumLock NumLock NumLock NumLock 144

A tecla NUM LOCK.The NUM LOCK key.

NumPad0 NumPad0 NumPad0 NumPad0 96

A tecla 0 no teclado numérico.The 0 key on the numeric keypad.

NumPad1 NumPad1 NumPad1 NumPad1 97

A tecla 1 no teclado numérico.The 1 key on the numeric keypad.

NumPad2 NumPad2 NumPad2 NumPad2 98

A tecla 2 no teclado numérico.The 2 key on the numeric keypad.

NumPad3 NumPad3 NumPad3 NumPad3 99

A tecla 3 no teclado numérico.The 3 key on the numeric keypad.

NumPad4 NumPad4 NumPad4 NumPad4 100

A tecla 4 no teclado numérico.The 4 key on the numeric keypad.

NumPad5 NumPad5 NumPad5 NumPad5 101

A tecla 5 no teclado numérico.The 5 key on the numeric keypad.

NumPad6 NumPad6 NumPad6 NumPad6 102

A tecla 6 no teclado numérico.The 6 key on the numeric keypad.

NumPad7 NumPad7 NumPad7 NumPad7 103

A tecla 7 no teclado numérico.The 7 key on the numeric keypad.

NumPad8 NumPad8 NumPad8 NumPad8 104

A tecla 8 no teclado numérico.The 8 key on the numeric keypad.

NumPad9 NumPad9 NumPad9 NumPad9 105

A tecla 9 no teclado numérico.The 9 key on the numeric keypad.

O O O O 79

A tecla O.The O key.

Oem1 Oem1 Oem1 Oem1 186

A tecla 1 do OEM.The OEM 1 key.

Oem102 Oem102 Oem102 Oem102 226

A tecla 102 do OEM.The OEM 102 key.

Oem2 Oem2 Oem2 Oem2 191

A tecla 2 do OEM.The OEM 2 key.

Oem3 Oem3 Oem3 Oem3 192

A tecla 3 do OEM.The OEM 3 key.

Oem4 Oem4 Oem4 Oem4 219

A tecla 4 do OEM.The OEM 4 key.

Oem5 Oem5 Oem5 Oem5 220

A tecla 5 do OEM.The OEM 5 key.

Oem6 Oem6 Oem6 Oem6 221

A tecla 6 do OEM.The OEM 6 key.

Oem7 Oem7 Oem7 Oem7 222

A tecla 7 do OEM.The OEM 7 key.

Oem8 Oem8 Oem8 Oem8 223

A tecla 8 do OEM.The OEM 8 key.

OemBackslash OemBackslash OemBackslash OemBackslash 226

A tecla de colchete angular ou barra invertida do OEM no teclado de 102 teclas RT (Windows 2000 ou posterior).The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows 2000 or later).

OemClear OemClear OemClear OemClear 254

A tecla CLEAR.The CLEAR key.

OemCloseBrackets OemCloseBrackets OemCloseBrackets OemCloseBrackets 221

A tecla de parêntese de fechamento do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM close bracket key on a US standard keyboard (Windows 2000 or later).

Oemcomma Oemcomma Oemcomma Oemcomma 188

A tecla de vírgula do OEM no teclado de qualquer país/região (Windows 2000 ou posterior).The OEM comma key on any country/region keyboard (Windows 2000 or later).

OemMinus OemMinus OemMinus OemMinus 189

A tecla de menos do OEM no teclado de qualquer país/região (Windows 2000 ou posterior).The OEM minus key on any country/region keyboard (Windows 2000 or later).

OemOpenBrackets OemOpenBrackets OemOpenBrackets OemOpenBrackets 219

A tecla de parêntese de abertura do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM open bracket key on a US standard keyboard (Windows 2000 or later).

OemPeriod OemPeriod OemPeriod OemPeriod 190

A tecla de ponto do OEM no teclado de qualquer país/região (Windows 2000 ou posterior).The OEM period key on any country/region keyboard (Windows 2000 or later).

OemPipe OemPipe OemPipe OemPipe 220

A tecla de barra vertical do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM pipe key on a US standard keyboard (Windows 2000 or later).

Oemplus Oemplus Oemplus Oemplus 187

A tecla de mais do OEM no teclado de qualquer país/região (Windows 2000 ou posterior).The OEM plus key on any country/region keyboard (Windows 2000 or later).

OemQuestion OemQuestion OemQuestion OemQuestion 191

A tecla de ponto de interrogação do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM question mark key on a US standard keyboard (Windows 2000 or later).

OemQuotes OemQuotes OemQuotes OemQuotes 222

A tecla de aspas simples/duplas do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM singled/double quote key on a US standard keyboard (Windows 2000 or later).

OemSemicolon OemSemicolon OemSemicolon OemSemicolon 186

A tecla de ponto e vírgula do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM Semicolon key on a US standard keyboard (Windows 2000 or later).

Oemtilde Oemtilde Oemtilde Oemtilde 192

A tecla de til do OEM em um teclado padrão dos EUA (Windows 2000 ou posterior).The OEM tilde key on a US standard keyboard (Windows 2000 or later).

P P P P 80

A tecla P.The P key.

Pa1 Pa1 Pa1 Pa1 253

A tecla PA1.The PA1 key.

Packet Packet Packet Packet 231

Usada para passar a caracteres Unicode como se fossem pressionamentos de teclas.Used to pass Unicode characters as if they were keystrokes. O valor da tecla Packet é a palavra inferior de um valor de tecla virtual de 32 bits usado para métodos de entrada diferentes do 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

A tecla PAGE DOWN.The PAGE DOWN key.

PageUp PageUp PageUp PageUp 33

A tecla PAGE UP.The PAGE UP key.

Pause Pause Pause Pause 19

A tecla PAUSE.The PAUSE key.

Play Play Play Play 250

A tecla PLAY.The PLAY key.

Print Print Print Print 42

A tecla PRINT.The PRINT key.

PrintScreen PrintScreen PrintScreen PrintScreen 44

A tecla PRINT SCREEN.The PRINT SCREEN key.

Prior Prior Prior Prior 33

A tecla PAGE UP.The PAGE UP key.

ProcessKey ProcessKey ProcessKey ProcessKey 229

A tecla PROCESS KEY.The PROCESS KEY key.

Q Q Q Q 81

A tecla Q.The Q key.

R R R R 82

A tecla R.The R key.

RButton RButton RButton RButton 2

O botão direito do mouse.The right mouse button.

RControlKey RControlKey RControlKey RControlKey 163

A tecla CTRL direita.The right CTRL key.

Return Return Return Return 13

A tecla RETURN.The RETURN key.

Right Right Right Right 39

A tecla SETA PARA A DIREITA.The RIGHT ARROW key.

RMenu RMenu RMenu RMenu 165

A tecla ALT direita.The right ALT key.

RShiftKey RShiftKey RShiftKey RShiftKey 161

A tecla SHIFT direita.The right SHIFT key.

RWin RWin RWin RWin 92

A tecla direita do logotipo do Windows (Microsoft Natural Keyboard).The right Windows logo key (Microsoft Natural Keyboard).

S S S S 83

A tecla S.The S key.

Scroll Scroll Scroll Scroll 145

A tecla SCROLL LOCK.The SCROLL LOCK key.

Select Select Select Select 41

A tecla SELECT.The SELECT key.

SelectMedia SelectMedia SelectMedia SelectMedia 181

A tecla Selecionar Mídia (Windows 2000 ou posterior).The select media key (Windows 2000 or later).

Separator Separator Separator Separator 108

A tecla Separador.The separator key.

Shift Shift Shift Shift 65536

A tecla modificadora SHIFT.The SHIFT modifier key.

ShiftKey ShiftKey ShiftKey ShiftKey 16

A tecla SHIFT.The SHIFT key.

Sleep Sleep Sleep Sleep 95

A tecla de suspensão do computador.The computer sleep key.

Snapshot Snapshot Snapshot Snapshot 44

A tecla PRINT SCREEN.The PRINT SCREEN key.

Space Space Space Space 32

A tecla BARRA DE ESPAÇOS.The SPACEBAR key.

Subtract Subtract Subtract Subtract 109

A tecla Subtrair.The subtract key.

T T T T 84

A tecla T.The T key.

Tab Tab Tab Tab 9

A tecla TAB.The TAB key.

U U U U 85

A tecla U.The U key.

Up Up Up Up 38

A tecla SETA PARA CIMA.The UP ARROW key.

V V V V 86

A tecla V.The V key.

VolumeDown VolumeDown VolumeDown VolumeDown 174

A tecla Abaixar Volume (Windows 2000 ou posterior).The volume down key (Windows 2000 or later).

VolumeMute VolumeMute VolumeMute VolumeMute 173

A tecla Ativar mudo (Windows 2000 ou posterior).The volume mute key (Windows 2000 or later).

VolumeUp VolumeUp VolumeUp VolumeUp 175

A tecla Aumentar Volume (Windows 2000 ou posterior).The volume up key (Windows 2000 or later).

W W W W 87

A tecla W.The W key.

X X X X 88

A tecla X.The X key.

XButton1 XButton1 XButton1 XButton1 5

O primeiro botão x do mouse (mouse de cinco botões).The first x mouse button (five-button mouse).

XButton2 XButton2 XButton2 XButton2 6

O segundo botão x do mouse (mouse de cinco botões).The second x mouse button (five-button mouse).

Y Y Y Y 89

A tecla Y.The Y key.

Z Z Z Z 90

A tecla Z.The Z key.

Zoom Zoom Zoom Zoom 251

A tecla ZOOM.The ZOOM key.

Exemplos

O seguinte exemplo de código usa o KeyDown evento para determinar o tipo de caractere inserido no controle.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

Comentários

O Keys classe contém constantes para o processamento de entrada do teclado.The Keys class contains constants for processing keyboard input. Os membros da enumeração chaves consistem em um código de tecla e um conjunto de modificadores combinados em um único valor inteiro.The members of the Keys enumeration consist of a key code and a set of modifiers combined into a single integer value. Interface de programação de aplicativo (API) de um valor de chave do Win32 tem duas metades, com os bits de ordem superior que contém o código de chave (que é o mesmo que um código de tecla virtual do Windows) e os bits de ordem baixa que representa os modificadores de chave, como o controle, SHIFT e ALT chaves.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.

Aviso

Não use os valores nesta enumeração para operações bit a bit combinadas.Do not use the values in this enumeration for combined bitwise operations. Os valores na enumeração não são mutuamente exclusivos.The values in the enumeration are not mutually exclusive.

Observação

Esta enumeração não fornece nenhuma forma para testar se as chaves de CAPS LOCK ou NUM LOCK estão ativadas no momento.This enumeration provides no way to test whether the CAPS LOCK or NUM LOCK keys are currently activated. Você pode usar uma das seguintes técnicas para determinar se essas chaves são ativadas:You can use one of the following techniques to determine if these keys are activated:

  • Chame o IsKeyLocked método da Control classe.Call the IsKeyLocked method of the Control class.

  • Para ter maior controle, use as funções de API do Windows GetKeyState, GetAsyncKeyState, ou GetKeyboardState definido no User32. dll, para fazer isso.For finer control, use the Windows API functions GetKeyState, GetAsyncKeyState, or GetKeyboardState defined in user32.dll, to do this. Para obter mais informações sobre como chamar funções nativas, consulte consumindo funções de DLL não gerenciadas.For more information about calling native functions, see Consuming Unmanaged DLL Functions.

A tabela a seguir mostra os valores de chave do código representados por dois valores enumerados, que representam as chaves gerais do fabricante original do equipamento (OEM) e as associações de teclado americano mais específicas.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 americanoU.S. keyboard OEM geralGeneral 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

Cuidado

Para o .NET Framework 2.0, um membro IMEAccept foi adicionado que substitui a entrada anterior, IMEAceept, que está escrito incorretamente.For the .NET Framework 2.0, a member IMEAccept was added that supersedes the previous entry, IMEAceept, which was spelled incorrectly. A versão mais antiga foi mantida para compatibilidade com versões anteriores, mas ele pode ser excluído em versões futuras do .NET FrameworkThe older version has been retained for backward compatibility, but it may be deleted in future versions of the .NET Framework

Aplica-se a

Veja também