标签:RegisterHotKey Handle 热键 系统 HotKey HotKeyId 注册 Msg ShowMessage
注册系统级热键
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; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var HotKeyId: array[0..12] of Integer; //热键数组, 这里准备定义 13 个热键 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); //F2 RegisterHotKey(Handle,HotKeyId[1],0,VK_UP); //Up RegisterHotKey(Handle,HotKeyId[2],0,VK_DOWN); //Down RegisterHotKey(Handle,HotKeyId[3],0,VK_LEFT); //Left RegisterHotKey(Handle,HotKeyId[4],0,VK_RIGHT); //Right RegisterHotKey(Handle,HotKeyId[5],0,VK_PRIOR); //PageUp RegisterHotKey(Handle,HotKeyId[6],0,VK_NEXT); //PageDown RegisterHotKey(Handle,HotKeyId[7],0,VK_OEM_PLUS); //+ RegisterHotKey(Handle,HotKeyId[8],0,VK_OEM_MINUS); //- RegisterHotKey(Handle,HotKeyId[9],0,$31); //1 RegisterHotKey(Handle,HotKeyId[10],0,$41); //a RegisterHotKey(Handle,HotKeyId[11],0,VK_RETURN); //Enter RegisterHotKey(Handle,HotKeyId[12],MOD_CONTROL,VK_RETURN); //Ctrl+Enter 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.posted on 2007-11-29 13:20 万一 阅读(8599) 评论(38) 编辑 收藏
标签:RegisterHotKey,Handle,热键,系统,HotKey,HotKeyId,注册,Msg,ShowMessage 来源: https://blog.51cto.com/u_14617575/2746762
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。