キー コードと修飾子を指定します。
この列挙体には、メンバ値のビットごとの組み合わせを可能にする
FlagsAttribute
属性が含まれています。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
Public Enumeration Keys
[ComVisibleAttribute(true)]
[FlagsAttribute]
public enum Keys
[ComVisibleAttribute(true)]
[FlagsAttribute]
public enum class Keys
/** @attribute ComVisibleAttribute(true) */
/** @attribute FlagsAttribute() */
public enum Keys
ComVisibleAttribute(true)
FlagsAttribute
public enum Keys
| | メンバ名 | 説明 |
|---|
.gif) | A | A キー |
.gif) | Add | Add キー |
.gif) | Alt | Alt 修飾子キー |
.gif) | Apps | アプリケーション キー (Microsoft Natural Keyboard) |
.gif) | Attn | Attn キー |
.gif) | B | B キー |
.gif) | Back | BackSpace キー |
| BrowserBack | 戻るキー (Windows 2000 以降) |
| BrowserFavorites | お気に入りキー (Windows 2000 以降) |
| BrowserForward | 進むキー (Windows 2000 以降) |
| BrowserHome | ホーム キー (Windows 2000 以降) |
| BrowserRefresh | 更新キー (Windows 2000 以降) |
| BrowserSearch | 検索キー (Windows 2000 以降) |
| BrowserStop | 中止キー (Windows 2000 以降) |
.gif) | C | C キー |
.gif) | Cancel | Cancel キー |
.gif) | Capital | CapsLock キー |
.gif) | CapsLock | CapsLock キー |
.gif) | Clear | Clear キー |
.gif) | Control | Ctrl 修飾子キー |
.gif) | ControlKey | Ctrl キー |
.gif) | Crsel | Crsel キー |
.gif) | D | D キー |
.gif) | D0 | 0 キー |
.gif) | D1 | 1 キー |
.gif) | D2 | 2 キー |
.gif) | D3 | 3 キー |
.gif) | D4 | 4 キー |
.gif) | D5 | 5 キー |
.gif) | D6 | 6 キー |
.gif) | D7 | 7 キー |
.gif) | D8 | 8 キー |
.gif) | D9 | 9 キー |
.gif) | Decimal | 小数点キー |
.gif) | Delete | Del キー |
.gif) | Divide | 除算記号 (/) キー |
.gif) | Down | ↓ キー |
.gif) | E | E キー |
.gif) | End | End キー |
.gif) | Enter | Enter キー |
.gif) | EraseEof | EraseEof キー |
.gif) | Escape | Esc キー |
.gif) | Execute | Execute キー |
.gif) | Exsel | Exsel キー |
.gif) | F | F キー |
.gif) | F1 | F1 キー |
.gif) | F10 | F10 キー |
.gif) | F11 | F11 キー |
.gif) | F12 | F12 キー |
.gif) | F13 | F13 キー |
.gif) | F14 | F14 キー |
.gif) | F15 | F15 キー |
.gif) | F16 | F16 キー |
.gif) | F17 | F17 キー |
.gif) | F18 | F18 キー |
.gif) | F19 | F19 キー |
.gif) | F2 | F2 キー |
.gif) | F20 | F20 キー |
.gif) | F21 | F21 キー |
.gif) | F22 | F22 キー |
.gif) | F23 | F23 キー |
.gif) | F24 | F24 キー |
.gif) | F3 | F3 キー |
.gif) | F4 | F4 キー |
.gif) | F5 | F5 キー |
.gif) | F6 | F6 キー |
.gif) | F7 | F7 キー |
.gif) | F8 | F8 キー |
.gif) | F9 | F9 キー |
| FinalMode | IME Final モード キー |
.gif) | G | G キー |
.gif) | H | H キー |
| HanguelMode | IME ハングル モード キー(互換性を保つために保持されています。HangulMode を使用します) |
| HangulMode | IME ハングル モード キー |
| HanjaMode | IME Hanja モード キー |
.gif) | Help | Help キー |
.gif) | Home | Home キー |
.gif) | I | I キー |
| IMEAccept | IME Accept キー (IMEAceept の代わりに使用します) |
| IMEAceept | IME Accept キー互換性を維持するために残されています。代わりに IMEAccept を使用してください。 |
| IMEConvert | IME 変換キー |
| IMEModeChange | IME モード変更キー |
| IMENonconvert | IME 無変換キー |
.gif) | Insert | Ins キー |
.gif) | J | J キー |
| JunjaMode | IME Junja モード キー |
.gif) | K | K キー |
| KanaMode | IME かなモード キー |
| KanjiMode | IME 漢字モード キー |
.gif) | KeyCode | キー値からキー コードを抽出するビット マスク。 |
.gif) | L | L キー |
| LaunchApplication1 | カスタム ホット キー 1 (Windows 2000 以降) |
| LaunchApplication2 | カスタム ホット キー 2 (Windows 2000 以降) |
| LaunchMail | メール ホット キー (Windows 2000 以降) |
.gif) | LButton | マウスの左ボタン |
.gif) | LControlKey | 左の Ctrl キー |
.gif) | Left | ← キー |
.gif) | LineFeed | ライン フィード キー |
.gif) | LMenu | 左の Alt キー |
.gif) | LShiftKey | 左の Shift キー |
.gif) | LWin | 左の Windows ロゴ キー (Microsoft Natural Keyboard) |
.gif) | M | M キー |
.gif) | MButton | マウスの中央ボタン (3 ボタン マウスの場合) |
| MediaNextTrack | 次のトラック キー (Windows 2000 以降) |
| MediaPlayPause | 再生/一時停止キー (Windows 2000 以降) |
| MediaPreviousTrack | 前のトラック キー (Windows 2000 以降) |
| MediaStop | 停止キー (Windows 2000 以降) |
.gif) | Menu | Alt キー |
.gif) | Modifiers | キー値から修飾子を抽出するビット マスク。 |
.gif) | Multiply | 乗算記号 (*) キー |
.gif) | N | N キー |
.gif) | Next | PageDown キー |
.gif) | NoName | 今後使用するために予約されている定数 |
.gif) | None | キー入力なし |
.gif) | NumLock | NumLock キー |
.gif) | NumPad0 | 数値キーパッドの 0 キー |
.gif) | NumPad1 | 数値キーパッドの 1 キー |
.gif) | NumPad2 | 数値キーパッドの 2 キー |
.gif) | NumPad3 | 数値キーパッドの 3 キー |
.gif) | NumPad4 | 数値キーパッドの 4 キー |
.gif) | NumPad5 | 数値キーパッドの 5 キー |
.gif) | NumPad6 | 数値キーパッドの 6 キー |
.gif) | NumPad7 | 数値キーパッドの 7 キー |
.gif) | NumPad8 | 数値キーパッドの 8 キー |
.gif) | NumPad9 | 数値キーパッドの 9 キー |
.gif) | O | O キー |
| Oem1 | OEM 1 キー |
| Oem102 | OEM 102 キー |
| Oem2 | OEM 2 キー |
| Oem3 | OEM 3 キー |
| Oem4 | OEM 4 キー |
| Oem5 | OEM 5 キー |
| Oem6 | OEM 6 キー |
| Oem7 | OEM 7 キー |
| Oem8 | OEM 8 キー |
| OemBackslash | RT 102 キーのキーボード上の OEM 山かっこキーまたは円記号キー (Windows 2000 以降) |
.gif) | OemClear | Clear キー |
| OemCloseBrackets | 米国標準キーボード上の OEM 右角かっこキー (Windows 2000 以降) |
| Oemcomma | 国または地域別キーボード上の OEM コンマ キー (Windows 2000 以降) |
| OemMinus | 国または地域別キーボード上の OEM マイナス キー (Windows 2000 以降) |
| OemOpenBrackets | 米国標準キーボード上の OEM 左角かっこキー (Windows 2000 以降) |
| OemPeriod | 国または地域別キーボード上の OEM ピリオド キー (Windows 2000 以降) |
| OemPipe | 米国標準キーボード上の OEM Pipe キー (Windows 2000 以降) |
| Oemplus | 国または地域別キーボード上の OEM プラス キー (Windows 2000 以降) |
| OemQuestion | 米国標準キーボード上の OEM 疑問符キー (Windows 2000 以降) |
| OemQuotes | 米国標準キーボード上の OEM 一重/二重引用符キー (Windows 2000 以降) |
| OemSemicolon | 米国標準キーボード上の OEM セミコロン キー (Windows 2000 以降) |
| Oemtilde | 米国標準キーボード上の OEM ティルダ キー (Windows 2000 以降) |
.gif) | P | P キー |
.gif) | Pa1 | PA1 キー |
| Packet | Unicode 文字がキーストロークであるかのように渡されます。Packet のキー値は、キーボード以外の入力手段に使用される 32 ビット仮想キー値の下位ワードです。 |
.gif) | PageDown | PageDown キー |
.gif) | PageUp | PageUp キー |
.gif) | Pause | Pause キー |
.gif) | Play | Play キー |
.gif) | Print | Print キー |
.gif) | PrintScreen | PrintScreen キー |
.gif) | Prior | PageUp キー |
.gif) | ProcessKey | ProcessKey キー |
.gif) | Q | Q キー |
.gif) | R | R キー |
.gif) | RButton | マウスの右ボタン |
.gif) | RControlKey | 右の Ctrl キー |
.gif) | Return | Return キー |
.gif) | Right | → キー |
.gif) | RMenu | 右の Alt キー |
.gif) | RShiftKey | 右の Shift キー |
.gif) | RWin | 右の Windows ロゴ キー (Microsoft Natural Keyboard) |
.gif) | S | S キー |
.gif) | Scroll | ScrollLock キー |
.gif) | Select | Select キー |
| SelectMedia | メディア キー (Windows 2000 以降) |
.gif) | Separator | 区切り記号キー |
.gif) | Shift | Shift 修飾子キー |
.gif) | ShiftKey | Shift キー |
| Sleep | コンピュータのスリープ キー |
.gif) | Snapshot | PrintScreen キー |
.gif) | Space | Space キー |
.gif) | Subtract | 減算記号 (-) キー |
.gif) | T | T キー |
.gif) | Tab | Tab キー |
.gif) | U | U キー |
.gif) | Up | ↑ キー |
.gif) | V | V キー |
| VolumeDown | 音量 - キー (Windows 2000 以降) |
| VolumeMute | ミュート キー (Windows 2000 以降) |
| VolumeUp | 音量 + キー (Windows 2000 以降) |
.gif) | W | W キー |
.gif) | X | X キー |
.gif) | XButton1 | x マウスの 1 番目のボタン (5 ボタン マウスの場合) |
.gif) | XButton2 | x マウスの 2 番目のボタン (5 ボタン マウスの場合) |
.gif) | Y | Y キー |
.gif) | Z | Z キー |
.gif) | Zoom | Zoom キー |
Keys クラスには、キーボード入力を処理するために使用する定数が含まれています。Keys 列挙体のメンバは、キー コードと修飾子を組み合わせて生成した 1 つの整数値で構成されます。Win32 アプリケーション プログラミング インターフェイス (API: Application Programming Interface) では、キーの値は、キー コードを含んだ上位ビット (これは Windows の仮想キー コードと同じです)、および Shift、Control、Alt の各キーなどのキー修飾子を表す下位ビットの 2 つに分けられます。
メモ |
|---|
| この列挙体には、CapsLock キーや NumLock キーが現在アクティブになっているかどうかをテストする手段は用意されていません。これらのキーがアクティブになっているかどうかを確認するには、次のいずれかの手法を使用します。 |
2 つの列挙値によって表されるキー コード値を次の表に示します。これらは、一般的な相手先ブランド供給 (OEM: Original Equipment Manufacturer) キーと、より固有な英語版キーボードの両方の関連付けを表しています。
注意 |
|---|
| .NET Framework 2.0 では、スペルに間違いがあった以前のエントリ IMEAceept に代わる IMEAccept メンバが追加されました。古いバージョンも下位互換性を維持するために残されていますが、.NET Framework の将来バージョンでは削除される可能性があります。 |
' 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
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
End Class 'Form1
// 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;
}
}
}
}
// 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:
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;
}
}
}
}
// 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 boolean 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.get_KeyCode().CompareTo(Keys.D0)) < 0
|| (e.get_KeyCode().CompareTo(Keys.D9) > 0)) {
// Determine whether the keystroke is a number from the keypad.
if ((e.get_KeyCode().CompareTo(Keys.NumPad0) < 0
|| (e.get_KeyCode().CompareTo(Keys.NumPad9)) > 0)) {
// Determine whether the keystroke is a backspace.
if (!(e.get_KeyCode().Equals(Keys.Back))) {
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
} //textBox1_KeyDown
// 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.set_Handled(true);
}
} //textBox1_KeyPress
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0