unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
id:integer; //熱鍵id
procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Const
{ALT、CTRL和F12鍵的虛擬鍵值}
MOD_ALT = 1;
MOD_CONTROL = 2;
VK_R = 82;
begin
if GlobalFindAtom('MyHotkey') = 0 then
begin
{註冊全局熱鍵Ctrl + Alt + R}
id:=GlobalAddAtom('MyHotkey');
RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R);
end else
halt;
end;
procedure TForm1.WMHotKey (var Msg : TWMHotKey);
begin
if msg.HotKey = id then
ShowMessage('Ctrl+Alt+R 鍵被按下!');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,id);
GlobalDeleteAtom(id);
end;
end.
星期三, 9月 12, 2007
跟系統註冊一個hotkey (隨時能偵測按鍵及滑鼠)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言