Keys Enumeração

Definição

Especifica os principais códigos e modificadores.

Essa enumeração dá suporte a uma combinação bit a bit dos valores de membro.

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

Campos

Nome Valor Description
Modifiers -65536

A máscara de bits para extrair modificadores de um valor de chave.

None 0

Nenhuma tecla pressionada.

LButton 1

O botão esquerdo do mouse.

RButton 2

O botão direito do mouse.

Cancel 3

A chave CANCEL.

MButton 4

O botão do mouse do meio (mouse de três botões).

XButton1 5

O primeiro botão x do mouse (mouse de cinco botões).

XButton2 6

O segundo botão x do mouse (mouse de cinco botões).

Back 8

A tecla BACKSPACE.

Tab 9

A tecla TAB.

LineFeed 10

A chave LINEFEED.

Clear 12

A chave CLEAR.

Enter 13

A chave ENTER.

Return 13

A chave RETURN.

ShiftKey 16

A tecla SHIFT.

ControlKey 17

A tecla CTRL.

Menu 18

A tecla ALT.

Pause 19

A tecla ..

Capital 20

A tecla CAPS LOCK.

CapsLock 20

A tecla CAPS LOCK.

HanguelMode 21

A chave do modo Hanguel do IME. (mantido para compatibilidade; use HangulMode)

HangulMode 21

A chave do modo Hangul do IME.

KanaMode 21

A chave de modo Kana do IME.

JunjaMode 23

A chave de modo IME Junja.

FinalMode 24

A chave de modo final do IME.

HanjaMode 25

A chave de modo IME Hanja.

KanjiMode 25

A chave de modo Kanji do IME.

Escape 27

A tecla ESC.

IMEConvert 28

A chave de conversão de IME.

IMENonconvert 29

A chave não inverter IME.

IMEAccept 30

A chave de aceitação do IME, substitui IMEAceept.

IMEAceept 30

A chave de aceitação do IME. Obsoleto, use IMEAccept em vez disso.

IMEModeChange 31

A chave de alteração do modo IME.

Space 32

A tecla SPACEBAR.

PageUp 33

A tecla PAGE UP.

Prior 33

A tecla PAGE UP.

Next 34

A tecla PAGE DOWN.

PageDown 34

A tecla PAGE DOWN.

End 35

A tecla END.

Home 36

A tecla HOME.

Left 37

A tecla seta para a esquerda.

Up 38

A tecla seta para cima.

Right 39

A tecla seta para a direita.

Down 40

A tecla seta para baixo.

Select 41

A chave SELECT.

Print 42

A tecla PRINT.

Execute 43

A chave EXECUTE.

PrintScreen 44

A tecla PRINT SCREEN.

Snapshot 44

A tecla PRINT SCREEN.

Insert 45

A chave INS.

Delete 46

A chave DEL.

Help 47

A chave DA AJUDA.

D0 48

A tecla 0.

D1 49

A tecla 1.

D2 50

A tecla 2.

D3 51

A tecla 3.

D4 52

A tecla 4.

D5 53

A tecla 5.

D6 54

A tecla 6.

D7 55

A tecla 7.

D8 56

A tecla 8.

D9 57

A tecla 9.

A 65

A tecla A.

B 66

A tecla B.

C 67

A tecla C.

D 68

A tecla D.

E 69

A tecla E.

F 70

A tecla F.

G 71

A tecla G.

H 72

A tecla H.

I 73

A tecla I.

J 74

A tecla J.

K 75

A tecla K.

L 76

A tecla L.

M 77

A tecla M.

N 78

A tecla N.

O 79

A tecla O.

P 80

A tecla P.

Q 81

A tecla Q.

R 82

A tecla R.

S 83

A tecla S.

T 84

A tecla T.

U 85

A tecla U.

V 86

A tecla V.

W 87

A tecla W.

X 88

A tecla X.

Y 89

A tecla Y.

Z 90

A tecla Z.

LWin 91

A tecla do logotipo do Windows esquerdo (Microsoft Teclado Natural).

RWin 92

A tecla do logotipo do Windows à direita (Microsoft Teclado Natural).

Apps 93

A chave do aplicativo (Microsoft Teclado Natural).

Sleep 95

A tecla de suspensão do computador.

NumPad0 96

A tecla 0 no teclado numérico.

NumPad1 97

A tecla 1 no teclado numérico.

NumPad2 98

A tecla 2 no teclado numérico.

NumPad3 99

A tecla 3 no teclado numérico.

NumPad4 100

A tecla 4 no teclado numérico.

NumPad5 101

A tecla 5 no teclado numérico.

NumPad6 102

A tecla 6 no teclado numérico.

NumPad7 103

A tecla 7 no teclado numérico.

NumPad8 104

A tecla 8 no teclado numérico.

NumPad9 105

A tecla 9 no teclado numérico.

Multiply 106

A chave multiplicada.

Add 107

A chave de adição.

Separator 108

A chave do separador.

Subtract 109

A chave de subtração.

Decimal 110

A chave decimal.

Divide 111

A chave de divisão.

F1 112

A tecla F1.

F2 113

A tecla F2.

F3 114

A tecla F3.

F4 115

A tecla F4.

F5 116

A tecla F5.

F6 117

A tecla F6.

F7 118

A tecla F7.

F8 119

A tecla F8.

F9 120

A tecla F9.

F10 121

A tecla F10.

F11 122

A tecla F11.

F12 123

A tecla F12.

F13 124

A tecla F13.

F14 125

A tecla F14.

F15 126

A tecla F15.

F16 127

A tecla F16.

F17 128

A tecla F17.

F18 129

A tecla F18.

F19 130

A tecla F19.

F20 131

A chave F20.

F21 132

A tecla F21.

F22 133

A tecla F22.

F23 134

A tecla F23.

F24 135

A tecla F24.

NumLock 144

A chave NUM LOCK.

Scroll 145

A tecla SCROLL LOCK.

LShiftKey 160

A tecla SHIFT esquerda.

RShiftKey 161

A tecla SHIFT para a direita.

LControlKey 162

A tecla CTRL esquerda.

RControlKey 163

A tecla CTRL direita.

LMenu 164

A tecla ALT esquerda.

RMenu 165

A tecla ALT direita.

BrowserBack 166

A chave de fundo do navegador.

BrowserForward 167

A chave de encaminhamento do navegador.

BrowserRefresh 168

A chave de atualização do navegador.

BrowserStop 169

A tecla de parada do navegador.

BrowserSearch 170

A chave de pesquisa do navegador.

BrowserFavorites 171

A chave de favoritos do navegador.

BrowserHome 172

A chave inicial do navegador.

VolumeMute 173

A tecla de mudo de volume.

VolumeDown 174

A tecla de volume para baixo.

VolumeUp 175

A chave de aumento de volume.

MediaNextTrack 176

A próxima tecla de faixa de mídia.

MediaPreviousTrack 177

A tecla de faixa anterior da mídia.

MediaStop 178

A tecla Stop de mídia.

MediaPlayPause 179

A tecla de pausa de reprodução de mídia.

LaunchMail 180

A chave de email de inicialização.

SelectMedia 181

A chave de mídia selecionada.

LaunchApplication1 182

A chave inicial do aplicativo um.

LaunchApplication2 183

A tecla iniciar o aplicativo dois.

Oem1 186

A chave OEM 1.

OemSemicolon 186

A tecla ponto-e-vírgula OEM em um teclado padrão dos EUA.

Oemplus 187

A tecla de adição OEM em qualquer teclado de país/região.

Oemcomma 188

A tecla de vírgula OEM em qualquer teclado de país/região.

OemMinus 189

A tecla OEM menos em qualquer teclado de país/região.

OemPeriod 190

A tecla de período OEM em qualquer teclado de país/região.

Oem2 191

A chave OEM 2.

OemQuestion 191

A tecla de ponto de interrogação OEM em um teclado padrão dos EUA.

Oem3 192

A chave OEM 3.

Oemtilde 192

A tecla de bloco OEM em um teclado padrão dos EUA.

Oem4 219

A chave OEM 4.

OemOpenBrackets 219

A tecla de colchete aberta OEM em um teclado padrão dos EUA.

Oem5 220

A chave OEM 5.

OemPipe 220

A tecla de pipe OEM em um teclado padrão dos EUA.

Oem6 221

A chave OEM 6.

OemCloseBrackets 221

A tecla de colchete de fechamento OEM em um teclado padrão dos EUA.

Oem7 222

A chave OEM 7.

OemQuotes 222

A tecla OEM singled/double quote em um teclado padrão dos EUA.

Oem8 223

A chave OEM 8.

Oem102 226

A chave OEM 102.

OemBackslash 226

O colchete angular OEM ou a tecla de barra invertida no teclado de tecla RT 102.

ProcessKey 229

A chave PROCESS KEY.

Packet 231

Usado para passar caracteres Unicode como se fossem pressionamentos de tecla. O valor da chave de pacote é a palavra baixa de um valor de chave virtual de 32 bits usado para métodos de entrada que não são de teclado.

Attn 246

A chave ATTN.

Crsel 247

A chave CRSEL.

Exsel 248

A chave EXSEL.

EraseEof 249

A chave ERASE EOF.

Play 250

A chave PLAY.

Zoom 251

A tecla ZOOM.

NoName 252

Uma constante reservada para uso futuro.

Pa1 253

A chave PA1.

OemClear 254

A chave CLEAR.

KeyCode 65535

A máscara de bits para extrair um código de chave de um valor de chave.

Shift 65536

A chave modificadora SHIFT.

Control 131072

A chave modificadora CTRL.

Alt 262144

A chave modificadora ALT.

Exemplos

O exemplo de código a seguir usa o KeyDown evento para determinar o tipo de caractere inserido no controle.

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

Comentários

A Keys classe contém constantes para processar a entrada do teclado. Os membros da enumeração Keys consistem em um código de chave e um conjunto de modificadores combinados em um único valor inteiro. Na API (interface de programação do aplicativo) Win32, um valor de chave tem duas metades, com os bits de alta ordem contendo o código de chave (que é o mesmo que um código de chave virtual Windows) e os bits de ordem baixa que representam modificadores de chave, como as teclas SHIFT, CONTROL e ALT.

Warning

Não use os valores nessa enumeração para operações bit a bit combinadas. Os valores na enumeração não são mutuamente exclusivos.

Note

Essa enumeração não fornece nenhuma maneira de testar se as chaves CAPS LOCK ou NUM LOCK estão ativadas no momento. Você pode usar uma das seguintes técnicas para determinar se essas chaves são ativadas:

  • Chame o IsKeyLocked método da Control classe.

  • Para um controle mais fino, use as funções de API Windows GetKeyState, GetAsyncKeyState ou GetKeyboardState definidos em user32.dll, para fazer isso. Para obter mais informações sobre como chamar funções nativas, consulte Consuming Unmanaged DLL Functions.

A tabela a seguir mostra os valores de código de chave representados por dois valores enumerados, representando as teclas OEM (fabricante de equipamentos originais) gerais e as associações de teclado mais específicas dos EUA.

Valor hexadecimal Teclado dos EUA OEM geral
BA OemSemicolon Oem1
BF OemQuestion Oem2
C0 Oemtilde Oem3
BD OemOpenBrackets Oem4
DC OemPipe Oem5
DD OemCloseBrackets Oem6
DE OemQuotes Oem7
E2 OemBackslash Oem102

Cuidado

Para .NET Framework 2.0, foi adicionado um membro IMEAccept que substitui a entrada anterior, IMEAceept, que foi escrito incorretamente. A versão mais antiga foi retida para compatibilidade com versões anteriores, mas pode ser excluída em versões futuras do .NET.

Aplica-se a

Confira também