Solved

HotKeys F10 / F11 if possible?

Posted on 2000-03-16
10
604 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:craig_capel
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2623209
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
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2623239
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 =:(
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2623322
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....
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2623341
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
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2623345
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ITugay
ID: 2623360
I forgot about...
change MOD_CONTROL to 0, then you don't need hold [Ctrl].

Igor.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2623588


                   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 :)
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2623665
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?....
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 2623749
You miss very important:
-------------------------------
TForm1 = class(TForm)
  procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
....
-------------------------------


and

-------------------------------
....
   case Msg.HotKey of
   id_YourCode : messagedlg('Ha!',mtconfirmation,[mbok],0);
....
-------------------------------  

Change it and it will work for you, like for me;)

Igor.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2623801
Gracias Senor.....

Thank - you....

Craig C.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to define IfThen functions in one common unit? 4 45
how to update exe applicatio from internet ? 6 68
DBGrid or StringGrid ? 6 72
RESTRequest Parameter 4 15
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now