Keys 列挙型
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キー コードと修飾子を指定します。
この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。
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
- 継承
- 属性
フィールド
| 名前 | 値 | 説明 |
|---|---|---|
| Modifiers | -65536 | キー値から修飾子を抽出するビットマスク。 |
| None | 0 | キーが押されていません。 |
| LButton | 1 | マウスの左ボタン。 |
| RButton | 2 | マウスの右ボタン。 |
| Cancel | 3 | CANCEL キー。 |
| MButton | 4 | マウスの中央ボタン (3 ボタンのマウス)。 |
| XButton1 | 5 | 最初の x 個のマウス ボタン (5 ボタンのマウス)。 |
| XButton2 | 6 | 2 番目の x マウス ボタン (5 ボタンのマウス)。 |
| Back | 8 | BackSpace キー |
| Tab | 9 | Tab キー |
| LineFeed | 10 | LINEFEED キー。 |
| Clear | 12 | CLEAR キー。 |
| Enter | 13 | Enter キー。 |
| Return | 13 | RETURN キー。 |
| ShiftKey | 16 | Shift キー |
| ControlKey | 17 | Ctrl キー |
| Menu | 18 | Alt キー |
| Pause | 19 | Pause キー |
| Capital | 20 | CAPS ロック キー。 |
| CapsLock | 20 | CAPS ロック キー。 |
| HanguelMode | 21 | IME ハングエル モード キー。 (互換性のために維持されます。 |
| HangulMode | 21 | IME ハングル モード キー。 |
| KanaMode | 21 | IME かなモード キー。 |
| JunjaMode | 23 | IME Junja モード キー。 |
| FinalMode | 24 | IME の最終モード キー。 |
| HanjaMode | 25 | IME Hanja モード キー。 |
| KanjiMode | 25 | IME 漢字モード キー。 |
| Escape | 27 | Esc キー |
| IMEConvert | 28 | IME 変換キー。 |
| IMENonconvert | 29 | IME 非変換キー。 |
| IMEAccept | 30 | IME はキーを受け入れ、 IMEAceeptを置き換えます。 |
| IMEAceept | 30 | IME はキーを受け入れます。 現在は使用されていません。代わりに IMEAccept を使用してください。 |
| IMEModeChange | 31 | IME モード変更キー。 |
| Space | 32 | Space キー |
| PageUp | 33 | PageUp キー |
| Prior | 33 | PageUp キー |
| Next | 34 | PageDown キー |
| PageDown | 34 | PageDown キー |
| End | 35 | End キー |
| Home | 36 | Home キー |
| Left | 37 | 左方向キー。 |
| Up | 38 | 上方向キー。 |
| Right | 39 | 右方向キー。 |
| Down | 40 | 下方向キー。 |
| Select | 41 | SELECT キー。 |
| 42 | PRINT キー。 |
|
| Execute | 43 | EXECUTE キー。 |
| PrintScreen | 44 | 印刷画面キー。 |
| Snapshot | 44 | 印刷画面キー。 |
| Insert | 45 | INS キー。 |
| Delete | 46 | DEL キー。 |
| Help | 47 | HELP キー。 |
| 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 キー |
| A | 65 | A キー |
| B | 66 | B キー |
| C | 67 | C キー |
| D | 68 | D キー |
| E | 69 | E キー |
| F | 70 | F キー |
| G | 71 | G キー |
| H | 72 | H キー |
| I | 73 | I キー |
| J | 74 | J キー |
| K | 75 | K キー |
| L | 76 | L キー |
| M | 77 | M キー |
| N | 78 | N キー |
| O | 79 | O キー |
| P | 80 | P キー |
| Q | 81 | Q キー |
| R | 82 | R キー |
| S | 83 | S キー |
| T | 84 | T キー |
| U | 85 | U キー |
| V | 86 | V キー |
| W | 87 | W キー |
| X | 88 | X キー |
| Y | 89 | Y キー |
| Z | 90 | Z キー |
| LWin | 91 | 左側のWindowsロゴ キー (Microsoftナチュラル キーボード)。 |
| RWin | 92 | 右Windowsロゴ キー (Microsoftナチュラル キーボード)。 |
| Apps | 93 | アプリケーション キー (Microsoftナチュラル キーボード)。 |
| Sleep | 95 | コンピューターのスリープ キー。 |
| 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 キー。 |
| Multiply | 106 | 乗算キー。 |
| Add | 107 | 追加キー。 |
| Separator | 108 | 区切り記号キー。 |
| Subtract | 109 | 減算キー。 |
| Decimal | 110 | 10 進キー。 |
| Divide | 111 | 除算キー。 |
| F1 | 112 | F1 キー |
| F2 | 113 | F2 キー |
| F3 | 114 | F3 キー |
| F4 | 115 | F4 キー |
| F5 | 116 | F5 キー |
| F6 | 117 | F6 キー |
| F7 | 118 | F7 キー |
| F8 | 119 | F8 キー |
| F9 | 120 | F9 キー |
| 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 キー。 |
| F20 | 131 | F20 キー。 |
| F21 | 132 | F21 キー。 |
| F22 | 133 | F22 キー。 |
| F23 | 134 | F23 キー。 |
| F24 | 135 | F24 キー。 |
| NumLock | 144 | NUM LOCK キー。 |
| Scroll | 145 | ScrollLock キー |
| LShiftKey | 160 | 左 Shift キー。 |
| RShiftKey | 161 | 右 Shift キー。 |
| LControlKey | 162 | 左の Ctrl キー。 |
| RControlKey | 163 | 右の Ctrl キー。 |
| LMenu | 164 | 左側の Alt キー。 |
| RMenu | 165 | 右 Alt キー。 |
| BrowserBack | 166 | ブラウザーの戻るキー。 |
| BrowserForward | 167 | ブラウザーの転送キー。 |
| BrowserRefresh | 168 | ブラウザーの更新キー。 |
| BrowserStop | 169 | ブラウザーの停止キー。 |
| BrowserSearch | 170 | ブラウザーの検索キー。 |
| BrowserFavorites | 171 | ブラウザーのお気に入りキー。 |
| BrowserHome | 172 | ブラウザーのホーム キー。 |
| VolumeMute | 173 | 音量ミュート キー。 |
| VolumeDown | 174 | 音量ダウン キー。 |
| VolumeUp | 175 | ボリューム アップ キー。 |
| MediaNextTrack | 176 | メディアの次のトラック キー。 |
| MediaPreviousTrack | 177 | メディアの前のトラック キー。 |
| MediaStop | 178 | メディア停止キー。 |
| MediaPlayPause | 179 | メディア 再生の一時停止キー。 |
| LaunchMail | 180 | 起動メール キー。 |
| SelectMedia | 181 | メディア キーの選択。 |
| LaunchApplication1 | 182 | 開始アプリケーションの 1 つのキー。 |
| LaunchApplication2 | 183 | アプリケーションの開始 2 つのキー。 |
| Oem1 | 186 | OEM 1 キー。 |
| OemSemicolon | 186 | 米国標準キーボードの OEM セミコロン キー。 |
| Oemplus | 187 | 任意の国/地域のキーボードの OEM + キー。 |
| Oemcomma | 188 | 任意の国/地域キーボードの OEM コンマ キー。 |
| OemMinus | 189 | 任意の国/地域キーボードの OEM マイナス キー。 |
| OemPeriod | 190 | 任意の国/地域キーボードの OEM ピリオド キー。 |
| Oem2 | 191 | OEM 2 キー。 |
| OemQuestion | 191 | 米国標準キーボードの OEM 疑問符キー。 |
| Oem3 | 192 | OEM 3 キー。 |
| Oemtilde | 192 | 米国標準キーボードの OEM チルダ キー。 |
| Oem4 | 219 | OEM 4 キー。 |
| OemOpenBrackets | 219 | 米国標準キーボードの OEM オープン ブラケット キー。 |
| Oem5 | 220 | OEM 5 キー。 |
| OemPipe | 220 | 米国標準キーボードの OEM パイプ キー。 |
| Oem6 | 221 | OEM 6 キー。 |
| OemCloseBrackets | 221 | 米国標準キーボードの OEM 閉じブラケット キー。 |
| Oem7 | 222 | OEM 7 キー。 |
| OemQuotes | 222 | 米国標準キーボードの OEM シングル/ダブル クォート キー。 |
| Oem8 | 223 | OEM 8 キー。 |
| Oem102 | 226 | OEM 102 キー。 |
| OemBackslash | 226 | RT 102 キー キーボードの OEM 山かっこまたはバックスラッシュ キー。 |
| ProcessKey | 229 | PROCESS KEY キー。 |
| Packet | 231 | Unicode 文字をキーストロークのように渡すために使用されます。 パケット キー値は、キーボード以外の入力方法で使用される 32 ビット仮想キー値の下位ワードです。 |
| Attn | 246 | ATTN キー。 |
| Crsel | 247 | CRSEL キー。 |
| Exsel | 248 | EXSEL キー。 |
| EraseEof | 249 | ERASE EOF キー。 |
| Play | 250 | PLAY キー。 |
| Zoom | 251 | ZOOM キー。 |
| NoName | 252 | 将来使用するために予約された定数。 |
| Pa1 | 253 | PA1 キー。 |
| OemClear | 254 | CLEAR キー。 |
| KeyCode | 65535 | キー値からキー コードを抽出するビットマスク。 |
| Shift | 65536 | Shift 修飾子キー。 |
| Control | 131072 | Ctrl 修飾子キー。 |
| Alt | 262144 | Alt 修飾子キー。 |
例
次のコード例では、 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)
{ // 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
注釈
Keys クラスには、キーボード入力を処理するための定数が含まれています。 Keys 列挙体のメンバーは、キー コードと 1 つの整数値に結合された修飾子のセットで構成されます。 Win32 アプリケーション プログラミング インターフェイス (API) では、キー値には 2 つの半分があり、上位ビットにはキー コード (Windows仮想キー コードと同じ) と、Shift キー、CONTROL キー、ALT キーなどのキー修飾子を表す下位ビットが含まれます。
Warning
この列挙体の値は、結合されたビットごとの演算には使用しないでください。 列挙体の値は相互に排他的ではありません。
Note
この列挙体では、CAPS LOCK キーまたは NUM LOCK キーが現在アクティブになっているかどうかをテストする方法はありません。 次のいずれかの手法を使用して、これらのキーがアクティブ化されているかどうかを判断できます。
IsKeyLocked クラスのControl メソッドを呼び出します。
より細かく制御するには、Windows API 関数
GetKeyState、GetAsyncKeyState、または user32.dllで定義されているGetKeyboardStateを使用します。 ネイティブ関数の呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。
次の表は、2 つの列挙値で表されるキー コード値を示しています。これは、一般的な OEM (Oem) キーと、より具体的な米国のキーボードの関連付けの両方を表しています。
| 16 進数の値 | 米国のキーボード | 一般 OEM |
|---|---|---|
| 文学士 | OemSemicolon | Oem1 |
| BF | OemQuestion | Oem2 |
| C0 | Oemtilde | Oem3 |
| DB | OemOpenBrackets | Oem4 |
| DC | OemPipe | Oem5 |
| DD | OemCloseBrackets | Oem6 |
| デ | OemQuotes | Oem7 |
| E2 | OemBackslash | Oem102 |
Caution
.NET Framework 2.0 では、前のエントリ (IMEAccept) よりも優先されるメンバー IMEAceept が追加されました。スペルが正しくありません。 旧バージョンは下位互換性のために保持されていますが、将来のバージョンの.NETで削除される可能性があります。