Discussion:
TActionList Custom Shortcuts
(too old to reply)
Don Payette
2003-06-24 18:20:16 UTC
Permalink
I have an application that was developed starting in the days
of Delphi 2. It is an MDI application and has a TActionList
on the main form with a TMainMenu and a TControlBar with TToolButtons.
We developed our own toolbar customizer, since TActionManager wasn't around
(or we didn't notice it).

Now I am at a point where I am adding a Macro capability to my
app and I want users to be able to specify their own keyboard
shortcuts to run a macro.

I've created a TAction descendent that has the info I need
(Macro file name, etc), set the shortcut property and add
it to the main forms action list. I then run my app and
press the shortcut key and it works. However, if I then
create an MDIChild, the shortcut no longer works. If I
close the child, it works again. It seems like the child
form isn't inheriting my custom actions.

The static pre-defined actions that are put in the action
list at design time work fine when a child is open.

Any ideas?

How difficult would it be to switch to TActionManager and
would that solve my problem?

Don Payette
Unisys Corporation
Don Payette
2003-06-25 16:57:42 UTC
Permalink
Gee, did I stump the experts? :-)
Post by Don Payette
I have an application that was developed starting in the days
of Delphi 2. It is an MDI application and has a TActionList
on the main form with a TMainMenu and a TControlBar with TToolButtons.
We developed our own toolbar customizer, since TActionManager wasn't around
(or we didn't notice it).
Now I am at a point where I am adding a Macro capability to my
app and I want users to be able to specify their own keyboard
shortcuts to run a macro.
I've created a TAction descendent that has the info I need
(Macro file name, etc), set the shortcut property and add
it to the main forms action list. I then run my app and
press the shortcut key and it works. However, if I then
create an MDIChild, the shortcut no longer works. If I
close the child, it works again. It seems like the child
form isn't inheriting my custom actions.
The static pre-defined actions that are put in the action
list at design time work fine when a child is open.
Any ideas?
How difficult would it be to switch to TActionManager and
would that solve my problem?
Don Payette
Unisys Corporation
Don Payette
Unisys Corporation
Peter Below (TeamB)
2003-06-25 21:27:53 UTC
Permalink
Post by Don Payette
Gee, did I stump the experts? :-)
You had this three letter swear word in you message: MDI <g>. Check if the
main forms OnShortcut event sees the shortcut.


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Don Payette
2003-06-26 16:57:58 UTC
Permalink
Thanks, Peter.

I put this code in:

procedure TmdiMain.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
trace ('Main.OnShortcut' +
', Msg ' + WmToString (Msg.Msg) +
', CharCode ' + inttostr (Msg.CharCode) +
', KeyData ' + format ('%X', [Msg.KeyData]));
end;

The shortcut that I defined is Shift+Ctrl+F6, with no MDI child open I
get this:

DISPLAY {9:44:09 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 17, KeyData 1D0001
DISPLAY {9:44:09 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 1D0001
DISPLAY {9:44:09 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 17, KeyData 401D0001
DISPLAY {9:44:09 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 401D0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 17, KeyData 401D0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 401D0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 16, KeyData 2A0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 2A0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 16, KeyData 402A0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
<repeated many times>
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 16, KeyData 402A0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
DISPLAY {9:44:10 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xBD04), CharCode 117, KeyData 400001
DISPLAY {9:44:10 AM} {MDIControl} Busy FALSE - Do action
DIALOG {9:44:10 AM} {TUserAction} OnActionExecute, Name "", MacroFile C:\DOCUMENTS AND SETTINGS\PAYETTDJ\MY

The CharCode 17 is the Ctrl, 16 is the Shift, and 117 is F6.
With an MDIChild open, I get this:

DISPLAY {9:44:29 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 1D0001
DISPLAY {9:44:29 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 401D0001
DISPLAY {9:44:29 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 401D0001
DISPLAY {9:44:29 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 17, KeyData 401D0001
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 2A0001
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
<repeated many times>
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001
DISPLAY {9:44:30 AM} {MDIControl} Main.OnShortcut, Msg WM_APP (0xB016), CharCode 16, KeyData 402A0001


Notice I didn't get the CharCode 117 (the F6), I just got the 17 for the Ctrl, and the 16 for the shift.
Post by Peter Below (TeamB)
Post by Don Payette
Gee, did I stump the experts? :-)
You had this three letter swear word in you message: MDI <g>. Check if the
main forms OnShortcut event sees the shortcut.
Don Payette
Unisys Corporation
Peter Below (TeamB)
2003-06-26 18:23:36 UTC
Permalink
Post by Don Payette
Notice I didn't get the CharCode 117 (the F6), I just got the 17 for the Ctrl, and the 16 for the shift.
Weird. I have no idea why this happens, sorry. The MDI frame window does usually
gets first dibs at shortcuts, otherwise the menu would not work when a child form has
focus. Does the active childs forms OnShortcut see the key?

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Don Payette
2003-06-26 20:21:13 UTC
Permalink
Very interesting stuff happening. I figured out what is going on.

TApplication.IsMDIMsg returns true for Shift+Ctrl+F6, which means
that the Win32 call TranslateMDISysAccel is returning true. I changed
my shortcut to Shift+Ctrl+F7, and it now works fine.

MSDN mentions this:
Accelerator keys on the window menu for an MDI child window are
different from those for a non-MDI child window. In an MDI child window,
the ALT+ – (minus) key combination opens the window menu, the CTRL+F4
key combination closes the active child window, and the CTRL+F6 key
combination activates the next child window.
Post by Peter Below (TeamB)
Post by Don Payette
Notice I didn't get the CharCode 117 (the F6), I just got the 17 for the Ctrl, and the 16 for the shift.
Weird. I have no idea why this happens, sorry. The MDI frame window does usually
gets first dibs at shortcuts, otherwise the menu would not work when a child form has
focus. Does the active childs forms OnShortcut see the key?
Don Payette
Unisys Corporation
Peter Below (TeamB)
2003-06-27 17:05:30 UTC
Permalink
Post by Don Payette
Accelerator keys on the window menu for an MDI child window are
different from those for a non-MDI child window. In an MDI child window,
the ALT+ – (minus) key combination opens the window menu, the CTRL+F4
key combination closes the active child window, and the CTRL+F6 key
combination activates the next child window.
Doh, yes, now that you mention it memory comes back. Shift-Ctrl-F6 activates
the prior child window.


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Loading...