| View previous topic :: View next topic |
| Author |
Message |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 28/02/06 08:08 Post subject: component key events not triggered? |
|
|
I have a problem with the keyevents when I use the SimpleGraph component in my plugin.
I have tested that they work in a normal Testapp with no problem.
The plugin is a DLL which is called by the host-app.
The DLL has form where the SG is on.
When I define a SG-OnKeyDown event I can see that it is called:
| Code: |
procedure ThpwForm.SimpleGraph1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key=VK_TAB then
showmessage('Key=Tab')
ELSE IF Key=VK_DELETE then
showmessage('Key=Delete')
ELSE IF Key=VK_LEFT then
showmessage('Key=Left')
ELSE IF Key=VK_RIGHT then
showmessage('Key=Right')
ELSE IF Key=VK_UP then
showmessage('Key=Up')
ELSE IF Key=VK_DOWN then
showmessage('Key=Down');
end;
|
Edit-mode is on cmEdit.
But why is the components key handling not called?
Any idea what can cause this?
_________________ Hans-Peter |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1113 Location: Tehran, Iran
|
Posted: 28/02/06 15:45 Post subject: |
|
|
For keys supported by the component, OnKeyDown event doesn't generate. It's because the default Delphi's event handler is very slow and it causes the objects receive key sequences with lot of delay delay.
If you want to manage all key events by yourself, set DefaultKeyMap property to False.
_________________ Kambiz |
|
| Back to top |
|
 |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 28/02/06 16:12 Post subject: |
|
|
>If you want to manage all key events by yourself, set DefaultKeyMap property to False.
I do not want to manage them myself, but your component's key events does not get triggered. Since it does work in standalone, it may not a problem with your component, instead it is my unusual use of it. I ask for ideas what can cause this behaviour.
_________________ Hans-Peter |
|
| Back to top |
|
 |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 01/03/06 06:36 Post subject: |
|
|
With the help from Dave from neosoft I got the problem solved.
Here his comment:
| Quote: |
In the SimpleGraph.pas file change the following two lines from:
procedure CNKeyDown(var Msg: TWMKeyDown); message CN_KEYDOWN;
procedure CNKeyUp(var Msg: TWMKeyUp); message CN_KEYUP;
to:
procedure CNKeyDown(var Msg: TWMKeyDown); message WM_KEYDOWN;
procedure CNKeyUp(var Msg: TWMKeyUp); message WM_KEYUP;
The CN_KEYDOWN or CN_KEYUP events don't seem to be documented, so I don't know why they would be using them.
However, changing the declaration to the more common WM_ equivalents seemed to solve the problem.
|
This change work for me. So any reason against it?
_________________ Hans-Peter |
|
| Back to top |
|
 |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 01/03/06 06:50 Post subject: |
|
|
Oops, just noticed that it does not work anymore in standalone!
So one configuration for standalone and one for plugin!
_________________ Hans-Peter |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1113 Location: Tehran, Iran
|
Posted: 01/03/06 07:49 Post subject: |
|
|
You found yourself why I've used CN_KEYDOWN and CNKEYUP messages.
Controls receive dialog keyboard messages. Using WM_KEYDOWN and WM_KEYUP messages cause default behavior of TAB and ARROW keys, but SimpleGraph needs these keys.
_________________ Kambiz |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 1113 Location: Tehran, Iran
|
Posted: 01/03/06 07:53 Post subject: |
|
|
If your host application is a Delphi application, and you have access to its TApplication.Handle property, I think the following assignment solves the problem.
| Code: | | Application.Handle := HostApplication.Handle; |
_________________ Kambiz |
|
| Back to top |
|
 |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 02/03/06 09:38 Post subject: |
|
|
| Quote: |
Application.Handle := HostApplication.Handle;
|
I tested it but it does not work for me.
Anyway with mychange above I get it working with arrows,tab and delete key.
But I still have problems to get CTRL-C,CTRL-V and CTRL-X to work.
Any idea?
Are they triggered by the component itself of how are this hotkeys attached to TSimpleGraph. In the demo I see them in the mainmenu, but my plugin has no mainmenu. In SimpleGraph.OnKeyDown I get all combinations with ALT+SHIFT but not with CTRL. I can make a ALT-C to copy to the clipboard, but not with CTRL-C. The CTRL-key alone gets through, but not the other key?
_________________ Hans-Peter |
|
| Back to top |
|
 |
HPW Senior Member
Joined: 25 Feb 2006 Posts: 131 Location: Germany
|
Posted: 02/03/06 10:25 Post subject: |
|
|
Oops, got it working. My error was is keycode-conversion.
_________________ Hans-Peter |
|
| Back to top |
|
 |
|