LCL Key Handling/ja
│
English (en) │
日本語 (ja) │
português (pt) │
キーを押し下げた (KeyDown)
widgetsetがキーを押されたことを受け取ると、次のようにふるまいます。 "ネイティブ"なwidgetにキーを処理させる前に、CN_KEYDOWNやCN_SYSKEYDOWNをLCLに送ります。(CN_SYSKEYDOWNはaltキーが押されたときに発生します。) これは、DoKeyDownBeforeInterfaceが次のようなフローでコールします。
- Application.NotifyKeyDownBeforeHandlerがコールされます。 (ハンドラの前に呼び出されます。)
- keypreviewがある親フォームを取得し、そのDoKeyDownBeforeInterfaceメソッドを呼び出します。
- 関連づけられているdragobjectにキーを処理させます。
- KeyDownBeforeInterfaceをコールします。 (もし、コントロールがcsNoStdEventsをControlStyleに持っていない場合):
- KeyDownをコールします。
- OnKeyDown ハンドラがあればコールします。
- KeyDownをコールします。
もし、キーが処理されなければ(すなわち、Message.Result=0)、widgetにキーを処理させます。もしwidgetが有意義なことをすることがなければ、LCLにLM_KEYDOWN/LM_SYSKEYDOWNメッセージを送ります。これは、DoRemainingKeyDownを次のようなフローでコールします。
- もしpopupmenuが割り当てられていれば、(それがポップアップされているかどうかにかかわらず)、ショートカットをチェックします。
- 親フォームを取得し、ショートカットが有効ならば処理させます。(TCustomForm.IsShortcut):
- フォームにOnShortcutイベントがあれば、それをコールします。
- フォームにMenuがあれば、そのショートカットをチェックします。:
- このメニューの全てのアイテムをイテレーションして、ショートカットをチェックして、該当するなら、そのアイテムの".Click"をコールします。
- もし、そのショートカットを処理しなかったり、後続のキー処理をさせたくない場合は、メニューアイテムのOnClickハンドラ内でメニューのShortcutHandledプロパティをfalseにします。
- アクションリストのショートカットをチェックして、一致するアクションの.Executeを実行します。
- アプリケーションにショートカットを処理させます。(Application.IsShortcut):
- もし、アプリケーションのOnShortcutが割り当てられていれ呼び出します。
- もし、モーダルフォームがアクティブになっている場合は、それにショートカットを処理させます。(上記の TCustomForm.IsShortcut を参照)
- そうでなくて、もしフォーカスされたフォームがある場合(Screen.ActiveCustomForm), そのフォームにショートカットを処理させます。
- そうではなくて、もし、メインフォームがあれば(Application.MainForm), そのフォームにショートカットを処理させます。
- もし、コントロールに親があれば、順にParent.ChildKeyを遡ってキーメッセージを処理します。
- これは、パネルの例のように、キーショットカットを確定したエリア内で処理する場合に利用します。
- TWinControlはその親のChildKeyを呼び出します。これが、順次遡って処理をするということです。
- TWinControl内でControlKeyDownよ呼び出すと、Application.ControlKeyDownを呼び出します。
- コントロールのためのタブナビゲーション処理
- もし、あなたの作ったカスタムコントロールがtabキーについて何も特別なことをしなければ、オーバーライドや禁止しなければ、たとえばTCustomMemoを例にとると..
- KeyDownAfterInterface; TWinControlはここでは何もしません。
- Applicationに、KeyDownAfterハンドラをコールさせます。
result(1か0をMessage.Resultで返します)は何かをすることに注意してください。たとえば、windows環境では、ただ、WM_KEYDOWNメッセージが来たときに、0を返すとキーのWM_CHARを送るだけです。
キーを押している, キャラクタが送られている(KeyPress)
widgetsetはCN_CHARメッセージを送るか、IntfUtf8KeyPressメソッドをコールすることができます。 CN_CHARはUTF-8キャラクタをサポートしませんのでIntfUtf8KeyPressが存在します。 CN_CHARは次のように扱われます。
- if widgetset (interface) does not send utf8 key presses, then call IntfUtf8KeyPress
- call DoKeyPress:
- get parent form, and if it has KeyPreview call it's DoKeyPress
- call KeyPress (if control does not have csNoStdEvents in ControlStyle):
- call OnKeyPress handler if any
IntfUtf8KeyPress (DoUtf8KeyPress) handling consists of:
- get parent form, and if it has KeyPreview call it's DoUtf8KeyPress
- call Utf8KeyPress (if control does not have csNoStdEvents in ControlStyle):
- call OnUtf8KeyPress handler if any
When unhandled, that is, Message.Result = 0, it lets the widget handle the key, and if the widget has not done anything useful, then send a LM_CHAR/LM_SYSCHAR message to the LCL, which calls SendDialogChar consisting of:
- get parent form and if found call it's .DialogChar:
- TWinControl broadcasts DialogChar to all it's children
- use it to implement accelerator shortcuts for controls "near" (on the same form) as the focused control
- example: TCustomLabel uses it to Focus the assigned .FocusControl when alt+accelerator is pressed
- TWinControl broadcasts DialogChar to all it's children
押されているキーを離した(KeyUp)
Releasing a key is very much, in the order of events happening, alike pressing a key, but some functions are missing. Again the widgetset will send a CN_KEYUP/CN_SYSKEYUP to the LCL before letting the widget handle the key, which will call DoKeyUpBeforeInterface consisting of:
- get parent form, if it has keypreview, call it's DoKeyUpBeforeInterface
- let the associated dragobject handle the key
- call KeyUpBeforeInterface (if control does not have csNoStdEvents in ControlStyle):
- call KeyUp:
- call OnKeyUp handler if any
- call KeyUp:
When unhandled, that is, Message.Result = 0, it lets the widget handle the key, and if the widget has not done anything useful, then send a LM_KEYUP/LM_SYSKEYUP message to the LCL, which calls DoRemainingKeyUp consisting of:
- call ControlKeyUp, which in TWinControl, calls Application.ControlKeyDown:
- handle Enter and Escape keys for forms
- if your custom control does something special with enter and escape, override and inhibit
- call KeyUpAfterInterface; TWinControl does nothing here