?
Solved

capture onKeyDown

Posted on 2001-08-26
3
Medium Priority
?
287 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 400 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

Technology Partners: 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

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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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