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