Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HotKeys F10 / F11 if possible?

Posted on 2000-03-16
10
Medium Priority
?
645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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