System.Windows.Forms 名前空間


.NET Framework クラス ライブラリ
Keys 列挙体

更新 : 2007 年 11 月

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

この列挙体には、メンバ値のビットごとの組み合わせを可能にする ComVisibleAttribute 属性が含まれています。

名前空間 :  System.Windows.Forms
アセンブリ :  System.Windows.Forms (System.Windows.Forms.dll 内)

構文

Visual Basic (宣言)
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
<TypeConverterAttribute(GetType(KeysConverter))> _
Public Enumeration Keys
Visual Basic (使用法)
Dim instance As Keys
C#
[ComVisibleAttribute(true)]
[FlagsAttribute]
[TypeConverterAttribute(typeof(KeysConverter))]
public enum Keys
Visual C++
[ComVisibleAttribute(true)]
[FlagsAttribute]
[TypeConverterAttribute(typeof(KeysConverter))]
public enum class Keys
J#
/** @attribute ComVisibleAttribute(true) */
/** @attribute FlagsAttribute */
/** @attribute TypeConverterAttribute(KeysConverter) */
public enum Keys
JScript
public enum Keys
メンバ

メンバ名説明
KeyCodeキー値からキー コードを抽出するビット マスク。
Modifiersキー値から修飾子を抽出するビット マスク。
Noneキー入力なし
LButtonマウスの左ボタン
RButtonマウスの右ボタン
CancelCancel キー
MButtonマウスの中央ボタン (3 ボタン マウスの場合)
XButton1x マウスの 1 番目のボタン (5 ボタン マウスの場合)
XButton2x マウスの 2 番目のボタン (5 ボタン マウスの場合)
BackBackSpace キー
TabTab キー
LineFeedライン フィード キー
ClearClear キー
ReturnReturn キー
EnterEnter キー
ShiftKeyShift キー
ControlKeyCtrl キー
MenuAlt キー
PausePause キー
CapitalCapsLock キー
CapsLockCapsLock キー
KanaModeIME かなモード キー
HanguelModeIME ハングル モード キー(互換性を保つために保持されています。HangulMode を使用します)
HangulModeIME ハングル モード キー
JunjaModeIME Junja モード キー
FinalModeIME Final モード キー
HanjaModeIME Hanja モード キー
KanjiModeIME 漢字モード キー
EscapeEsc キー
IMEConvertIME 変換キー
IMENonconvertIME 無変換キー
IMEAcceptIME Accept キー (IMEAceept の代わりに使用します)
IMEAceeptIME Accept キー互換性を維持するために残されています。代わりに IMEAccept を使用してください。
IMEModeChangeIME モード変更キー
SpaceSpace キー
PriorPageUp キー
PageUpPageUp キー
NextPageDown キー
PageDownPageDown キー
EndEnd キー
HomeHome キー
Left← キー
Up↑ キー
Right→ キー
Down↓ キー
SelectSelect キー
PrintPrint キー
ExecuteExecute キー
SnapshotPrintScreen キー
PrintScreenPrintScreen キー
InsertIns キー
DeleteDel キー
HelpHelp キー
D00 キー
D11 キー
D22 キー
D33 キー
D44 キー
D55 キー
D66 キー
D77 キー
D88 キー
D99 キー
AA キー
BB キー
CC キー
DD キー
EE キー
FF キー
GG キー
HH キー
II キー
JJ キー
KK キー
LL キー
MM キー
NN キー
OO キー
PP キー
QQ キー
RR キー
SS キー
TT キー
UU キー
VV キー
WW キー
XX キー
YY キー
ZZ キー
LWin左の Windows ロゴ キー (Microsoft Natural Keyboard)
RWin右の Windows ロゴ キー (Microsoft Natural Keyboard)
Appsアプリケーション キー (Microsoft Natural Keyboard)
Sleepコンピュータのスリープ キー
NumPad0数値キーパッドの 0 キー
NumPad1数値キーパッドの 1 キー
NumPad2数値キーパッドの 2 キー
NumPad3数値キーパッドの 3 キー
NumPad4数値キーパッドの 4 キー
NumPad5数値キーパッドの 5 キー
NumPad6数値キーパッドの 6 キー
NumPad7数値キーパッドの 7 キー
NumPad8数値キーパッドの 8 キー
NumPad9数値キーパッドの 9 キー
Multiply乗算記号 (*) キー
AddAdd キー
Separator区切り記号キー
Subtract減算記号 (-) キー
Decimal小数点キー
Divide除算記号 (/) キー
F1F1 キー
F2F2 キー
F3F3 キー
F4F4 キー
F5F5 キー
F6F6 キー
F7F7 キー
F8F8 キー
F9F9 キー
F10F10 キー
F11F11 キー
F12F12 キー
F13F13 キー
F14F14 キー
F15F15 キー
F16F16 キー
F17F17 キー
F18F18 キー
F19F19 キー
F20F20 キー
F21F21 キー
F22F22 キー
F23F23 キー
F24F24 キー
NumLockNumLock キー
ScrollScrollLock キー
LShiftKey左の Shift キー
RShiftKey右の Shift キー
LControlKey左の Ctrl キー
RControlKey右の Ctrl キー
LMenu左の Alt キー
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 以降)
Oem1OEM 1 キー
Oemplus国または地域別キーボード上の OEM プラス キー (Windows 2000 以降)
Oemcomma国または地域別キーボード上の OEM コンマ キー (Windows 2000 以降)
OemMinus国または地域別キーボード上の OEM マイナス キー (Windows 2000 以降)
OemPeriod国または地域別キーボード上の OEM ピリオド キー (Windows 2000 以降)
OemQuestion米国標準キーボード上の OEM 疑問符キー (Windows 2000 以降)
Oem2OEM 2 キー
Oemtilde米国標準キーボード上の OEM ティルダ キー (Windows 2000 以降)
Oem3OEM 3 キー
OemOpenBrackets米国標準キーボード上の OEM 左角かっこキー (Windows 2000 以降)
Oem4OEM 4 キー
OemPipe米国標準キーボード上の OEM Pipe キー (Windows 2000 以降)
Oem5OEM 5 キー
OemCloseBrackets米国標準キーボード上の OEM 右角かっこキー (Windows 2000 以降)
Oem6OEM 6 キー
OemQuotes米国標準キーボード上の OEM 一重/二重引用符キー (Windows 2000 以降)
Oem7OEM 7 キー
Oem8OEM 8 キー
OemBackslashRT 102 キーのキーボード上の OEM 山かっこキーまたは円記号キー (Windows 2000 以降)
Oem102OEM 102 キー
ProcessKeyProcessKey キー
PacketUnicode 文字がキーストロークであるかのように渡されます。Packet のキー値は、キーボード以外の入力手段に使用される 32 ビット仮想キー値の下位ワードです。
AttnAttn キー
CrselCrsel キー
ExselExsel キー
EraseEofEraseEof キー
PlayPlay キー
ZoomZoom キー
NoName今後使用するために予約されている定数
Pa1PA1 キー
OemClearClear キー
ShiftShift 修飾子キー
ControlCtrl 修飾子キー
AltAlt 修飾子キー
解説

Keys クラスには、キーボード入力を処理するために使用する定数が含まれています。Keys 列挙体のメンバは、キー コードと修飾子を組み合わせて生成した 1 つの整数値で構成されます。Win32 アプリケーション プログラミング インターフェイス (API: Application Programming Interface) では、キーの値は、キー コードを含んだ上位ビット (これは Windows の仮想キー コードと同じです)、および Shift、Control、Alt の各キーなどのキー修飾子を表す下位ビットの 2 つに分けられます。

メモ :

この列挙体には、CapsLock キーや NumLock キーが現在アクティブになっているかどうかをテストする手段は用意されていません。これらのキーがアクティブになっているかどうかを確認するには、次のいずれかの手法を使用します。

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

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

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 イベントを使用して、コントロールに入力された文字の種類を判断するコード例を次に示します。

Visual Basic
' 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
C#
// 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;
    }
}

Visual C++
   // 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;
      }
   }
J#
// 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
参照

参照

タグ :


Page view tracker