component key events not triggered?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

component key events not triggered?

Postby HPW » February 28th, 2006, 8:08 am

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: Select all
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
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby Kambiz » February 28th, 2006, 3:45 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby HPW » February 28th, 2006, 4:12 pm

>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
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby HPW » March 1st, 2006, 6:36 am

With the help from Dave from neosoft I got the problem solved.

Here his comment:

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
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby HPW » March 1st, 2006, 6:50 am

Oops, just noticed that it does not work anymore in standalone!
So one configuration for standalone and one for plugin!
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby Kambiz » March 1st, 2006, 7:49 am

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Kambiz » March 1st, 2006, 7:53 am

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: Select all
Application.Handle := HostApplication.Handle;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby HPW » March 2nd, 2006, 9:38 am

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
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby HPW » March 2nd, 2006, 10:25 am

Oops, got it working. My error was is keycode-conversion.
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 230
Joined: February 25th, 2006, 10:19 am
Location: Germany


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron