I have an application for which I want to implement user definable HotKeys for a number of procedures. I've used the RegisterHotKeys methods in a procedure that can be called with true to register them, false to unregister.
The HotKey sequences are stored in the applications registry and applied to the HotKeys through the use of an integer array.
I want to be a good neighbor to other applications that may be running, so I wanted my HotKeys active only when my app has focus. So I call the HotKeys(true) in an application.OnActivate event and turn them off in an Application.OnDeactivate event.
Now, if the user chooses to assign something to. for instance, Control-S, everything seems to be working properly. When my app has focus, Control-S does what it is supposed to do, but if WordPad, for instance, is focused, Control-S does the proper file save operation.
So what I've done seems to work, But I made all this up myself and I know from sad experience that just because I can make something work doesn't mean I've done it right. Is what I've done the best way to do this? Is there a more proper way? Am I being a good neighbor?
In the main form class methods section:
procedure AppOnActivate(Sender: TObject);
procedure AppDeActivate(Sender: TObject);
procedure HotKey(onoff: boolean);
kid4 : Integer;
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
In OnCreate procedure for Main form
Definitions of procedures:
procedure T_form.WMHotKey(var Msg: TWMHotKey);
if Msg.HotKey = kid4 then ToggleInOut;
procedure T_form.HotKeys(onoff: Boolean);
if onoff then
kid4 := GlobalAddAtom('hk3');
BK:=RegisterHotKey(Handle, kid4, HK[3,0]+HK[3,1],HK[3,2]);
procedure T_form.AppOnActivate(Sender: TObject);
procedure T_form.AppDeActivate(Sender: Tobject);