Board index » delphi » Trapping Hot-Keys in Windows

Trapping Hot-Keys in Windows

Here is the scenario

I have a program running in the foreground (has focus).  There is another program running in the background (minimized).  I want to
Hot-Key to the other program using Alt-F6.  How do I do this?  I'm guessing that the minimized program must constantly scan the
windows message queue?  Is this the right path? Any code fragments would be appreciated.

 

Re:Trapping Hot-Keys in Windows


Quote
wl...@a.crl.com wrote:
>Here is the scenario
>I have a program running in the foreground (has focus).  There is another program running in the background (minimized).  I want to
>Hot-Key to the other program using Alt-F6.  How do I do this?  I'm guessing that the minimized program must constantly scan the
>windows message queue?  Is this the right path? Any code fragments would be appreciated.

The following are the hotkey procedures from a program I wrote to
access the printer while minimized.  The functions are API functions
and are described in Delphi help.

procedure TMainForm.FormCreate(Sender: TObject);
var CharacterString :PChar;
  DidWork : boolean;
begin                              
  CharacterString := 'Alt-P';
  HotKeyID := AddAtom(CharacterString);{An integer variable}
  try
    DidWork := RegisterHotKey(0,HotKeyID,MOD_ALT+MOD_CONTROL,$50);
       {This is for ctrl-alt-p but you can use anything here}
  except on EVariantError do ShowMessage(inttostr(GetLastError));
  end;
  Application.OnMessage := AppMessageHandler;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
  UnRegisterHotKey(0,HotKeyID); {Frees up the hot key}
  Action := caFree;
end;

Procedure TMainForm.AppMessageHandler(var Msg: TMsg; var
Handled:Boolean);
const numMessages: longint = 0;

begin
  if (Msg.message = wm_HotKey) then  begin
    {Put the procedure you want the hot key to access here}
    Inherited;
  end
  else Handled := FALSE;
end;
Rusty Campbell
Microsys Computer Solutions

Email: rus...@bright.net

Other Threads