Keys 列挙型

定義

キー コードと修飾子を指定します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

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
継承
属性

フィールド

A 65

A キー。

Add 107

Add キー

Alt 262144

Alt 修飾子キー

Apps 93

アプリケーション キー (Microsoft Natural Keyboard)

Attn 246

Attn キー。

B 66

B キー。

Back 8

BackSpace キー。

BrowserBack 166

ブラウザーの戻るキー。

BrowserFavorites 171

ブラウザーのお気に入りキー。

BrowserForward 167

ブラウザーの進むキー。

BrowserHome 172

ブラウザーのホーム キー。

BrowserRefresh 168

ブラウザーの更新キー。

BrowserSearch 170

ブラウザーの検索キー。

BrowserStop 169

ブラウザーの中止キー。

C 67

C キー。

Cancel 3

Cancel キー

Capital 20

CAPS LOCK キー

CapsLock 20

CAPS LOCK キー

Clear 12

Clear キー。

Control 131072

Ctrl 修飾子キー

ControlKey 17

CTRL キー

Crsel 247

Crsel キー。

D 68

D キー。

D0 48

0 キー。

D1 49

1 キー。

D2 50

2 キー。

D3 51

3 キー。

D4 52

4 キー。

D5 53

5 キー。

D6 54

6 キー。

D7 55

7 キー。

D8 56

8 キー。

D9 57

9 キー。

Decimal 110

小数点キー

Delete 46

DEL キー

Divide 111

除算記号 (/) キー

Down 40

↓キー。

E 69

E キー。

End 35

End キー。

Enter 13

Enter キー。

EraseEof 249

Erase Eof キー。

Escape 27

Esc キー。

Execute 43

Execute キー。

Exsel 248

Exsel キー。

F 70

F キー。

F1 112

F1 キー。

F10 121

F10 キー。

F11 122

F11 キー。

F12 123

F12 キー。

F13 124

F13 キー。

F14 125

F14 キー。

F15 126

F15 キー。

F16 127

F16 キー。

F17 128

F17 キー。

F18 129

F18 キー。

F19 130

F19 キー。

F2 113

F2 キー。

F20 131

F20 キー。

F21 132

F21 キー。

F22 133

F22 キー。

F23 134

F23 キー。

F24 135

F24 キー。

F3 114

F3 キー。

F4 115

F4 キー。

F5 116

F5 キー。

F6 117

F6 キー。

F7 118

F7 キー。

F8 119

F8 キー。

F9 120

F9 キー。

FinalMode 24

IME Final モード キー

G 71

G キー。

H 72

H キー。

HanguelMode 21

IME ハングル モード キー (互換性を保つために保持されています。HangulMode を使用します)

HangulMode 21

IME ハングル モード キー。

HanjaMode 25

IME Hanja モード キー。

Help 47

Help キー。

Home 36

Home キー。

I 73

I キー。

IMEAccept 30

IME Accept キー (IMEAceept の代わりに使用します)

IMEAceept 30

IME Accept キー 互換性を維持するために残されています。代わりに IMEAccept を使用してください。

IMEConvert 28

IME 変換キー

IMEModeChange 31

IME モード変更キー

IMENonconvert 29

IME 無変換キー

Insert 45

INS キー

J 74

J キー。

JunjaMode 23

IME Junja モード キー。

K 75

K キー。

KanaMode 21

IME かなモード キー。

KanjiMode 25

IME 漢字モード キー。

KeyCode 65535

キー値からキー コードを抽出するビット マスク。

L 76

L キー。

LaunchApplication1 182

カスタム ホット キー 1。

LaunchApplication2 183

カスタム ホット キー 2。

LaunchMail 180

メールの起動キー。

LButton 1

マウスの左ボタン

LControlKey 162

左 Ctrl キー。

Left 37

←キー。

LineFeed 10

ライン フィード キー

LMenu 164

左 Alt キー。

LShiftKey 160

左の Shift キー

LWin 91

左 Windows ロゴ キー (Microsoft Natural Keyboard)。

M 77

M キー。

MButton 4

マウスの中央ボタン (3 ボタン マウスの場合)

MediaNextTrack 176

メディアの次のトラック キー。

MediaPlayPause 179

メディアの再生/一時停止キー。

MediaPreviousTrack 177

メディアの前のトラック キー。

MediaStop 178

メディアの停止キー。

Menu 18

Alt キー。

Modifiers -65536

キー値から修飾子を抽出するビット マスク。

Multiply 106

乗算記号 (*) キー

N 78

N キー。

Next 34

Page Down キー。

NoName 252

将来使用するために予約されている定数。

None 0

押されたキーがありません。

NumLock 144

NUM LOCK キー

NumPad0 96

0 キー (テンキー)。

NumPad1 97

1 キー (テンキー)。

NumPad2 98

2 キー (テンキー)。

NumPad3 99

3 キー (テンキー)。

NumPad4 100

4 キー (テンキー)。

NumPad5 101

5 キー (テンキー)。

NumPad6 102

6 キー (テンキー)。

NumPad7 103

7 キー (テンキー)。

NumPad8 104

8 キー (テンキー)。

NumPad9 105

9 キー (テンキー)

O 79

O キー。

Oem1 186

OEM 1 キー。

Oem102 226

OEM 102 キー。

Oem2 191

OEM 2 キー。

Oem3 192

OEM 3 キー。

Oem4 219

OEM 4 キー。

Oem5 220

OEM 5 キー。

Oem6 221

OEM 6 キー。

Oem7 222

OEM 7 キー。

Oem8 223

OEM 8 キー。

OemBackslash 226

RT 102 キーのキーボード上の OEM 山かっこキーまたは円記号キー。

OemClear 254

Clear キー。

OemCloseBrackets 221

米国標準キーボード上の OEM 右角かっこキー。

Oemcomma 188

国または地域別キーボード上の OEM コンマ キー。

OemMinus 189

国または地域別キーボード上の OEM マイナス キー。

OemOpenBrackets 219

米国標準キーボード上の OEM 左角かっこキー。

OemPeriod 190

国または地域別キーボード上の OEM ピリオド キー。

OemPipe 220

米国標準キーボード上の OEM パイプ キー。

Oemplus 187

国または地域別キーボード上の OEM プラス キー。

OemQuestion 191

米国標準キーボード上の OEM 疑問符キー。

OemQuotes 222

米国標準キーボード上の OEM 一重/二重引用符キー。

OemSemicolon 186

米国標準キーボード上の OEM セミコロン キー。

Oemtilde 192

米国標準キーボード上の OEM チルダ キー。

P 80

P キー。

Pa1 253

PA1 キー。

Packet 231

Unicode 文字がキーストロークであるかのように渡されます。 Packet のキー値は、キーボード以外の入力手段に使用される 32 ビット仮想キー値の下位ワードです。

PageDown 34

Page Down キー。

PageUp 33

Page Up キー。

Pause 19

Pause キー。

Play 250

Play キー。

Print 42

Print キー。

PrintScreen 44

Print Screen キー。

Prior 33

Page Up キー。

ProcessKey 229

ProcessKey キー

Q 81

Q キー。

R 82

R キー。

RButton 2

マウスの右ボタン

RControlKey 163

右 Ctrl キー。

Return 13

Return キー

Right 39

→キー。

RMenu 165

右 Alt キー。

RShiftKey 161

右の Shift キー

RWin 92

右 Windows ロゴ キー (Microsoft Natural Keyboard)。

S 83

S キー。

Scroll 145

ScrollLock キー

Select 41

Select キー。

SelectMedia 181

メディアの選択キー。

Separator 108

区切り記号キー

Shift 65536

Shift 修飾子キー

ShiftKey 16

Shift キー

Sleep 95

コンピューターのスリープ キー

Snapshot 44

Print Screen キー。

Space 32

Space キー。

Subtract 109

減算記号 (-) キー

T 84

T キー。

Tab 9

Tab キー。

U 85

U キー。

Up 38

↑キー。

V 86

V キー。

VolumeDown 174

音量下げるキー。

VolumeMute 173

音量ミュート キー。

VolumeUp 175

音量上げるキー。

W 87

W キー。

X 88

X キー。

XButton1 5

x マウスの 1 番目のボタン (5 ボタン マウスの場合)

XButton2 6

x マウスの 2 番目のボタン (5 ボタン マウスの場合)

Y 89

Y キー。

Z 90

Z キー。

Zoom 251

Zoom キー。

次のコード例では、 イベントを KeyDown 使用して、コントロールに入力された文字の種類を決定します。

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


 ' 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

注釈

クラスには Keys 、キーボード入力を処理するための定数が含まれています。 Keys 列挙体のメンバーは、キー コードと、1 つの整数値に結合された修飾子のセットで構成されます。 Win32 アプリケーション プログラミング インターフェイス (API) では、キー値に 2 つの部分があり、キー コード (Windows 仮想キー コードと同じ) を含む上位ビットと、Shift キー、CONTROL キー、ALT キーなどのキー修飾子を表す下位ビットがあります。

警告

結合されたビットごとの操作には、この列挙体の値を使用しないでください。 列挙体の値は相互に排他的ではありません。

注意

この列挙では、CAPS LOCK キーまたは NUM LOCK キーが現在アクティブになっているかどうかをテストする方法はありません。 次のいずれかの手法を使用して、これらのキーがアクティブ化されているかどうかを判断できます。

  • IsKeyLocked クラスの Control メソッドを呼び出します。

  • より細かく制御するには、windows API 関数 GetKeyState、、 GetAsyncKeyStateまたは GetKeyboardState user32.dll で定義されている を使用してこれを行います。 ネイティブ関数の呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。

次の表は、2 つの列挙値で表されるキー コード値を示しています。これは、一般的なオリジナル機器メーカー (OEM) キーと、より具体的な米国キーボードの関連付けの両方を表しています。

16 進数値 U.S. キーボード 一般 OEM
BA OemSemicolon Oem1
BF OemQuestion Oem2
C0 Oemtilde Oem3
DB OemOpenBrackets Oem4
DC OemPipe Oem5
DD OemCloseBrackets Oem6
DE OemQuotes Oem7
E2 OemBackslash Oem102

注意事項

.NET Framework 2.0 では、前のエントリ IMEAceept に置き換わるメンバー IMEAccept が追加されました。これは間違ったスペルでした。 旧バージョンは下位互換性のために保持されていますが、将来のバージョンの.NET Frameworkで削除される可能性があります

適用対象

こちらもご覧ください