We help IT Professionals succeed at work.
Get Started

hotkey on formless application

lobo_estepario
on
334 Views
Last Modified: 2010-04-05
Well, i made an app like this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Edit1: TEdit;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
     Procedure WMHotkey( Var msg: TWMHotkey ) ;
       message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 Handle:THandle;
implementation

{$R *.dfm}
Procedure TForm1.WMHotkey( Var msg: TWMHotkey ) ;
   Begin
     If msg.hotkey = 1 Then Begin
 If timer1.enabled then timer1.enabled:=False else
       begin
       //timer1.Interval:=strtoint(edit1.text);
       timer1.Enabled:=True;
       end;
     End;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
If not RegisterHotkey
    (Handle, 1, MOD_SHIFT, VK_F11) Then
     ShowMessage('Unable to assign hotkey.') ;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   UnRegisterHotkey( Handle, 1 ) ;
end;
end.


I got that code from a website and it works just fine.
Now i would like to have a formless app that would do the same  thing, but i don't know how to catch the hotkey message. It should be like this:


program project1;
uses
windows;
var
Msn: TMsg;
begin
RegisterHotkey
    (Handle, 1, MOD_SHIFT, VK_F11);
  while True do
  begin
WaitForSingleObject(GetCurrentProcess,1);

    if PeekMessage(Msn, 0, 0, 0, PM_REMOVE) then
    begin
      if Msn.Message <> $0012 then
      begin
        TranslateMessage(Msn);
        DispatchMessage(Msn);
      end
      else
begin
        UnRegisterHotkey( Handle, 1 ) ;
        Break;
end;
    end;
end.


So, ill wait for some help.
Thanks.
Comment
Watch Question
Software Engineer, Advisory
CERTIFIED EXPERT
Top Expert 2005
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE