Solved

capture onKeyDown

Posted on 2001-08-26
3
284 Views
Last Modified: 2010-04-06
How do i capture onKeyDown events that are triggered outside my program?
Say i wanted to make a program that beeps or something everytime a certain key is pressed in any other program i might be using.

Any help appreciated :)
0
Comment
Question by:psogaa
[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
3 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6426129
Hi psogaa,

here is it.

It show message if you press Ctrl+F8 or Alt+F12.

-----
Igor.

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  public
    procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const
  AltF12_HotKey = 1110;
  CtrlF8_HotKey = 1111;

procedure TForm1.FormCreate(Sender: TObject);
begin
   RegisterHotKey(Handle,AltF12_HotKey,MOD_ALT,VK_F12);
   RegisterHotKey(Handle,CtrlF8_HotKey,MOD_CONTROL,VK_F8);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnregisterHotKey(Handle,AltF12_HotKey);
  UnregisterHotKey(Handle,CtrlF8_HotKey);
end;

procedure TForm1.WMHotKey(var Msg : TWMHotKey);
begin
  case MSG.HotKey of
  AltF12_HotKey:
    begin
      Application.BringToFront;
      ShowMessage('Alt-F12');
    end;
  CtrlF8_HotKey:
    begin
      Application.BringToFront;
      ShowMessage('Ctrl-F8');
    end;
  end;
end;


end.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6426156
Hello

  This article will help you to do that

Hooks: Capture keys in all Windows applications  
http://www.q3.nu/trucomania/truco.cgi?408&ing

and this article to help you to understand the hook in windows

An introduction to hook procedures
http://delphi.about.com/library/bluc/text/uc063001a.htm

Best regards
Mohammed
0
 
LVL 2

Author Comment

by:psogaa
ID: 6426581
Thank you both, it works great :)
0

Featured Post

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!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

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