这个文章不错哦 让你的程序也来个自定义快捷键是不是很神奇?更多待研究 来自:万一博客
Delphi代码
- 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
- procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
-
- public
-
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
- var
- HotKeyId: array[0..12] of Integer;
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- i: Integer;
- begin
-
- for i := Low(HotKeyId) to High(HotKeyId) do
- HotKeyId[i] := GlobalAddAtom(PChar(IntToStr(i)));
- RegisterHotKey(Handle,HotKeyId[0],0,VK_F2);
- RegisterHotKey(Handle,HotKeyId[1],0,VK_UP);
- RegisterHotKey(Handle,HotKeyId[2],0,VK_DOWN);
- RegisterHotKey(Handle,HotKeyId[3],0,VK_LEFT);
- RegisterHotKey(Handle,HotKeyId[4],0,VK_RIGHT);
- RegisterHotKey(Handle,HotKeyId[5],0,VK_PRIOR);
- RegisterHotKey(Handle,HotKeyId[6],0,VK_NEXT);
- RegisterHotKey(Handle,HotKeyId[7],0,VK_OEM_PLUS);
- RegisterHotKey(Handle,HotKeyId[8],0,VK_OEM_MINUS);
- RegisterHotKey(Handle,HotKeyId[9],0,$31);
- RegisterHotKey(Handle,HotKeyId[10],0,$41);
- RegisterHotKey(Handle,HotKeyId[11],0,VK_RETURN);
- RegisterHotKey(Handle,HotKeyId[12],MOD_CONTROL,VK_RETURN);
- end;
-
-
- procedure TForm1.WMHotKey(var Msg: TWMHotKey);
- begin
- if Msg.HotKey = HotKeyId[0] then ShowMessage('F2');
- if (Msg.HotKey=HotKeyId[1]) then ShowMessage('Up');
- if (Msg.HotKey=HotKeyId[2]) then ShowMessage('Down');
- if (Msg.HotKey=HotKeyId[3]) then ShowMessage('Left');
- if (Msg.HotKey=HotKeyId[4]) then ShowMessage('Right');
- if Msg.HotKey = HotKeyId[5] then ShowMessage('PageUp');
- if Msg.HotKey = HotKeyId[6] then ShowMessage('PageDown');
- if Msg.HotKey = HotKeyId[7] then ShowMessage('+');
- if Msg.HotKey = HotKeyId[8] then ShowMessage('-');
- if Msg.HotKey = HotKeyId[9] then ShowMessage('1');
- if Msg.HotKey = HotKeyId[10] then ShowMessage('a');
- if Msg.HotKey = HotKeyId[11] then ShowMessage('Enter');
- if Msg.HotKey = HotKeyId[12] then ShowMessage('Ctrl+Enter');
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- var
- i: Integer;
- begin
-
- for i := Low(HotKeyId) to High(HotKeyId) do
- begin
- UnRegisterHotKey(handle,HotKeyId[i]);
- GlobalDeleteAtom(HotKeyId[i]);
- end;
- end;
-
- end.
阅读(599) | 评论(0) | 转发(0) |