How to get shortcut event in winform plugin

I have a Delphi host and a winform visual plugin. The visual plugin need get shortcuts do work from delphi host. How to do this? thanks.

Hello

Could you provide a testcase and a more detailed description of this?

Thanks in advance

In host application, press CTRL+F1 key, and I want get it in winform plugin Keydown event.

Please take a look at this: http://stackoverflow.com/questions/3172731/forms-not-responding-to-keydown-events

Thanks very much!

I try this solution, my plugin is base on UserControl or VisualPlugin. the KeyPreview set to true, and I can’t take the keyDown result in plugin.

Please send a testcase to support@

Winform plugin keydown.zip (897.7 KB)

If focus on form, I can take keydown event, but focus on button, can’t take any keydown. is it correct ?

Technically it is correct amd t is how Windows handles events. Setting KeyPress to true on the plugin window affects only keypresses sent to its content. So when you press a button outside of the plugin - host form’s controlls can swallow it.

You need to either:

  • set the parent form’s property KeyPreview to true, handle this event in the Delphi code and call methods of the plugin
  • use some different approach, not based on the KeyDow / KeyUp events

Winform plugin keydown.zip (943.3 KB)

This is new case. I added some controls in plugin container, and focus any control, I have not take anything key message. I think this is normally requirement for plugin. pls help.

Please read again my answer above. Plugin cannot handle any event message if Windows doesn’t even send this event message to this plugin because this event message is already processed on the parent level.

If you want to add a hotkey functionality to your app then this should be done in completely different way.

Also this approach won’t work anyway even if you will explicitly reroute keyboard events from VCL parent form. VCL doesn’t generate keyboard events for certain cases:

Navigation keys (Tab, BackTab, the arrow keys, and so on) are unaffected by KeyPreview because they do not generate keyboard events. Similarly, when a button has focus or when its Default property is true, the Enter key is unaffected by KeyPreview because it does not generate a keyboard events.