Keys Enumeração

Definição

Especifica códigos de chave e modificadores.

Esta enumeração suporta uma combinação bit-a-bit dos respetivos valores 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

Name Valor Description
Modifiers -65536

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

None 0

Nenhuma tecla pressionada.

LButton 1

O botão esquerdo do rato.

RButton 2

O botão direito do rato.

Cancel 3

A tecla CANCELAR.

MButton 4

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

XButton1 5

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

XButton2 6

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

Back 8

A tecla BACKSPACE.

Tab 9

A tecla TAB.

LineFeed 10

A tecla LINEFEED.

Clear 12

A tecla CLEAR.

Enter 13

A tecla ENTER.

Return 13

A tecla RETORNO.

ShiftKey 16

A tecla SHIFT.

ControlKey 17

A chave CTRL.

Menu 18

A tecla ALT.

Pause 19

A tecla PAUSE.

Capital 20

A tecla CAPS LOCK.

CapsLock 20

A tecla CAPS LOCK.

HanguelMode 21

A tecla de modo Hanguel IME. (mantido para compatibilidade; uso HangulMode)

HangulMode 21

A tecla do modo Hangul IME.

KanaMode 21

A tecla de modo Kana do IME.

JunjaMode 23

A tecla de modo Junja do IME.

FinalMode 24

A chave final do modo IME.

HanjaMode 25

A tecla de modo Hanja do IME.

KanjiMode 25

A tecla do modo Kanji IME.

Escape 27

A tecla ESC.

IMEConvert 28

A chave de conversão IME.

IMENonconvert 29

A chave não de conversão IME.

IMEAccept 30

A chave de aceitação IME substitui IMEAceept.

IMEAceept 30

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

IMEModeChange 31

A tecla de mudança de 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 FIM.

Home 36

A chave HOME.

Left 37

A TECLA DE SETA ESQUERDA.

Up 38

A tecla SETA PARA CIMA.

Right 39

A TECLA DE SETA DA DIREITA.

Down 40

A tecla SETA PARA BAIXO.

Select 41

A tecla SELECT.

Print 42

A chave PRINT.

Execute 43

A tecla EXECUTAR.

PrintScreen 44

A tecla IMPRIMIR ECRÃ.

Snapshot 44

A tecla IMPRIMIR ECRÃ.

Insert 45

A chave do INS.

Delete 46

A chave DEL.

Help 47

A chave HELP.

D0 48

A chave 0.

D1 49

A chave 1.

D2 50

A chave 2.

D3 51

O de 3 chaves.

D4 52

A chave 4.

D5 53

A chave 5.

D6 54

O de 6 chaves.

D7 55

A chave 7.

D8 56

O de 8 chaves.

D9 57

A chave 9.

A 65

A chave 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 Sol.

H 72

A tecla H.

I 73

A tecla I.

J 74

A tecla J.

K 75

A tecla K.

L 76

A chave 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 chave 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 esquerda do logótipo do Windows (Microsoft Natural Keyboard).

RWin 92

A tecla direita do logótipo do Windows (Microsoft Natural Keyboard).

Apps 93

A tecla de aplicação (Microsoft Natural Keyboard).

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 de 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 de multiplicação.

Add 107

A tecla de adicionar.

Separator 108

A chave do separador.

Subtract 109

A chave de subtrair.

Decimal 110

A chave decimal.

Divide 111

A chave de divisão.

F1 112

A chave F1.

F2 113

A tecla F2.

F3 114

A tecla F3.

F4 115

A chave F4.

F5 116

A tecla F5.

F6 117

A chave F6.

F7 118

A chave F7.

F8 119

A chave F8.

F9 120

A chave F9.

F10 121

A chave F10.

F11 122

A chave F11.

F12 123

A chave F12.

F13 124

A tecla F13.

F14 125

A chave F14.

F15 126

A chave F15.

F16 127

A chave F16.

F17 128

A chave F17.

F18 129

A chave F18.

F19 130

A chave F19.

F20 131

A chave F20.

F21 132

A chave F21.

F22 133

A chave F22.

F23 134

A chave F23.

F24 135

A chave F24.

NumLock 144

A chave NUM LOCK.

Scroll 145

A chave de FECHO DE PERGAMINHO.

LShiftKey 160

A tecla SHIFT esquerda.

RShiftKey 161

A tecla SHIFT 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 tecla de fundo do navegador.

BrowserForward 167

A tecla do navegador para avançar.

BrowserRefresh 168

A chave de atualização do navegador.

BrowserStop 169

A tecla de paragem 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 volume para silenciar.

VolumeDown 174

A tonalidade de volume para baixo.

VolumeUp 175

A tecla de volume para aumentar.

MediaNextTrack 176

A chave da faixa seguinte dos media.

MediaPreviousTrack 177

A faixa anterior dos media.

MediaStop 178

A chave Stop dos media.

MediaPlayPause 179

A tecla de pausa do media play.

LaunchMail 180

A chave de correio de lançamento.

SelectMedia 181

A tecla select media.

LaunchApplication1 182

A aplicação inicial é uma chave.

LaunchApplication2 183

A segunda chave inicial da aplicação.

Oem1 186

A chave OEM 1.

OemSemicolon 186

A tecla OEM de ponto e vírgula num teclado padrão dos EUA.

Oemplus 187

A tecla OEM plus 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 menos OEM em qualquer teclado de país/região.

OemPeriod 190

A tecla de época original em qualquer teclado de país/região.

Oem2 191

A chave OEM 2.

OemQuestion 191

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

Oem3 192

A chave OEM 3.

Oemtilde 192

A tecla tilde OEM num teclado padrão dos EUA.

Oem4 219

A chave OEM de 4 pontos.

OemOpenBrackets 219

A tecla OEM de suporte aberto num teclado padrão dos EUA.

Oem5 220

A chave OEM 5.

OemPipe 220

A tecla OEM de tubo num teclado padrão dos EUA.

Oem6 221

A chave OEM de 6.

OemCloseBrackets 221

A tecla OEM de fecho de suporte num teclado padrão dos EUA.

Oem7 222

A chave OEM 7.

OemQuotes 222

A tecla OEM de aspas simples/duplas num teclado padrão dos EUA.

Oem8 223

A chave OEM 8.

Oem102 226

A chave OEM 102.

OemBackslash 226

O suporte angular OEM ou tecla de barra inversa no teclado RT de 102 teclas.

ProcessKey 229

A chave CHAVE DE PROCESSO.

Packet 231

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

Attn 246

A chave ATTN.

Crsel 247

A chave CRSEL.

Exsel 248

A chave EXSEL.

EraseEof 249

A tecla EOF de APAGAR.

Play 250

A tecla PLAY.

Zoom 251

A tecla ZOOM.

NoName 252

Uma constante reservada para uso futuro.

Pa1 253

A chave PA1.

OemClear 254

A tecla CLEAR.

KeyCode 65535

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

Shift 65536

A tecla modificadora SHIFT.

Control 131072

A tecla modificadora CTRL.

Alt 262144

A tecla modificadora ALT.

Exemplos

O exemplo de código seguinte utiliza o KeyDown evento para determinar o tipo de carácter introduzido no controlo.

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

Observações

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

Warning

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

Note

Esta enumeração não oferece forma de testar se as teclas CAPS LOCK ou NUM LOCK estão atualmente ativadas. Pode usar uma das seguintes técnicas para determinar se estas teclas estão ativadas:

  • Chama o IsKeyLocked método da Control aula.

  • Para um controlo mais fino, use as funções Windows API GetKeyState, GetAsyncKeyState ou GetKeyboardState definidas em user32.dll, para isso. Para mais informações sobre como chamar funções nativas, veja Consuming Unmanaged DLL Functions.

A tabela seguinte mostra os valores dos códigos de teclas representados por dois valores enumerados, representando tanto as teclas originais gerais do fabricante do equipamento (OEM) como as associações mais específicas EUA-teclado.

Valor hexadecimal Teclado dos EUA OEM geral
BA OemPonto e vírgula Oem1
BF OemQuestion Oem2
C0 Oemtilde Oem3
DB OemOpenBrackets Oem4
DC OemPipe Oem5
DD OemCloseBrackets Oem6
Alemanha OemQuotes Oem7
E2 OemBackslash OEM102

Atenção

Para .NET Framework 2.0, foi adicionado um membro IMEAccept que substitui a entrada anterior, IMEAceept, que estava escrita incorretamente. A versão mais antiga foi mantida para compatibilidade retroativa, mas poderá ser eliminada em versões futuras do .NET.

Aplica-se a

Ver também