Link to home
Start Free TrialLog in
Avatar of craig_capel
craig_capel

asked on

HotKeys F10 / F11 if possible?

Ok think i am going about this the wrong way.... All i need to know is Am i?...

unit exbook1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
     function AppHookFunc(var Message : TMessage) : Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
type
 TWindowHook = function(var Message : TMessage) : Boolean of object;

function TForm1.AppHookFunc(var Message : TMessage) : Boolean;
                   begin
                     Result := False; //I just do this by default
                     if Message.Msg = Wm_hotkey  then
                       begin
                         ShowMessage('Bingo');
                         Result := True;
                       end;
                   end;


procedure TForm1.Button1Click(Sender: TObject);
begin
{BOOL RegisterHotKey(

    HWND  hwnd,      // window to receive hot-key notification
    int  idHotKey,      // identifier of hot key
    UINT  fuModifiers,      // key-modifier flags
    UINT  uVirtKey       // virtual-key code
   );}

registerhotkey(form1.handle,$dead,mod_control,VkKeyScan('B'));

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.HookMainWindow(AppHookFunc);
end;

end.


I am trying to hook the message since....

hwnd

Identifies the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.

Ok this is what i am doing, i want to be able to hit F10 or F11, i can do it by accessing port 60, but this time i need to do it properly, so i can use it in NT too.... Anyone know a better way of going about this?... or is this the correct way? hook wm_???...

Thanks All.

Craig C.
Avatar of Lischke
Lischke

Hi Craig,

ahem.... I can't really follow you. I just tried (to be sure) to set an applications main from to KeyPreview and attached an OnKeyDown event handler. I get VK_F10 as I expected. So, what is the point in your question? (Is it that you want to hook F10/F11 systemwide, for all applications? Then you need of course a hook).

Ciao, Mike
Are you wanting to be able to hit F10/F11 from outside your app and then do something like capture the screen?

If NOT then just check for VK_F10 or VK_F11 in the OnKeyUp or OnKeyDown methods.

That's far too simple an answer and you'd never ask for help on something like that in a million years and I'm rambling on and on and maybe I should clear off and do some work

The Neil =:(
Avatar of craig_capel

ASKER

yeah i'm not totally stupid :) nope, i know that the form has a property for keyb shortcuts, but have you Seen PSP?... you can by hitting F10 or whatever, Capture the screen..., Yes System Wide thats why i am trying to get a hook to work...

I could use this method and it works great until you hit NT and thats this...

var
  result: byte;

asm
 in al,60h;
 mov result, al;
end;

And if Result=$3b You Just hit F1, but As NT restricts the use of ports, forget it, i need to catch F10 somehow, i will be using IE or Netscape when i press F10, at which point, i will grab the bookmark address, yes i can do it this way, but i may as well learn the harder way as well :)

Hope that cleared that up :)  Thanks all....
Right, we are half the way down :-) RegisterHotKey is then the better choice I think, so you don't need to hook the system. You already tried it as I can see from the code above but you gave it up. Why?

Ciao, Mike
Are you looking something like this?

--------------------
const id_YourCode = $1111; //  0000 .. $BFFF - your choice


procedure TMainForm.FormCreate(Sender: TObject);
begin
   RegisterHotKey(Handle,  id_YourCode, MOD_CONTROL,VK_F11);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
   UnRegisterHotKey (Handle, id_YourCode);
end;

procedure TMainForm.WMHotKey (var Msg : TWMHotKey);
begin
   case Msg.HotKey of
   // do something here
   end;
end;
-----------------

Best regards,
Igor.
I forgot about...
change MOD_CONTROL to 0, then you don't need hold [Ctrl].

Igor.


                   procedure TMainForm.WMHotKey (var Msg : TWMHotKey);
                   begin
                      case Msg.HotKey of
                      // do something here
                      end;
                   end;


will not work, i think your missing something/..... Thanks :)
unit exbook1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure WMHotKey(var Msg : TWMHotKey);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  const id_YourCode = $1111; //  0000 .. $BFFF - your choice

implementation

{$R *.DFM}


procedure TForm1.FormCreate(Sender: TObject);
begin
      RegisterHotKey(Handle,  id_YourCode, 0,VK_F11);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey (Handle, id_YourCode);
end;



 procedure  TForm1.WMHotKey(var Msg : TWMHotKey);
     begin
     case Msg.HotKey of
      vk_f11: messagedlg('Ha!',mtconfirmation,[mbok],0);
       // do something here
     end;
    end;

end.


I added that to make it compile, Does it work for you?....
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Gracias Senor.....

Thank - you....

Craig C.