Solved

HotKeys F10 / F11 if possible?

Posted on 2000-03-16
10
598 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

18 Experts available now in Live!

Get 1:1 Help Now