Solved

register a global hotkey?

Posted on 2011-02-28
4
517 Views
Last Modified: 2012-05-11
how do I register a global hotkey?

like CTRL+ALT+F5??
0
Comment
Question by:eNarc
4 Comments
 
LVL 3

Assisted Solution

by:maosalah
maosalah earned 250 total points
Comment Utility
try to change this example

register a global hotkey Ctrl+A

unit Unit1;
 
interface
 
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
 
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
hotkey1: Integer;
procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.WMHotKey (var Msg : TWMHotKey);
begin
if msg.HotKey = hotkey1 then ShowMessage('Ctrl + A pressed');
end;
 
procedure TForm1.FormCreate(Sender: TObject);
const MOD_CONTROL = 2;
VK_A = 65;
begin
hotkey1 := GlobalAddAtom('Hotkey1');
RegisterHotKey(handle, hotkey1, MOD_CONTROL,VK_A);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle, hotkey1);

end;
 
end.

Open in new window

0
 
LVL 24

Accepted Solution

by:
jimyX earned 250 total points
Comment Utility
Just completing Maosalah's input:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    id: Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = id then
    begin
      //Alt-Ctrl-F5 are pressed, do whatever you want here
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  id := GlobalAddAtom('Hotkey');
  RegisterHotKey(Handle, id, MOD_ALT + MOD_CONTROL, VK_F5);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, id);
  GlobalDeleteAtom(id);
end;

end.

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

10 Experts available now in Live!

Get 1:1 Help Now