Solved

HotKeys F10 / F11 if possible?

Posted on 2000-03-16
10
630 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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