Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1300855
  • 博文数量: 436
  • 博客积分: 7854
  • 博客等级: 少将
  • 技术积分: 3225
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-18 16:30
文章分类

全部博文(436)

文章存档

2013年(2)

2012年(56)

2011年(70)

2010年(308)

分类:

2010-06-22 23:55:20

这个文章不错哦 让你的程序也来个自定义快捷键是不是很神奇?更多待研究 来自:万一博客

Delphi代码
  1. unit Unit1;   
  2.   
  3. interface  
  4.   
  5. uses  
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   
  7.   Dialogs;   
  8.   
  9. type  
  10.   TForm1 = class(TForm)   
  11.     procedure FormCreate(Sender: TObject);   
  12.     procedure FormDestroy(Sender: TObject);   
  13.   private  
  14.     procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;   
  15.     { Private declarations }  
  16.   public  
  17.     { Public declarations }  
  18.   end;   
  19.   
  20. var  
  21.   Form1: TForm1;   
  22.   
  23. implementation  
  24.   
  25. {$R *.dfm}  
  26.   
  27. var  
  28.   HotKeyId: array[0..12of Integer;  //热键数组, 这里准备定义 13 个热键   
  29.   
  30. procedure TForm1.FormCreate(Sender: TObject);   
  31. var  
  32.   i: Integer;   
  33. begin  
  34.   //注册热键   
  35.   for i := Low(HotKeyId) to High(HotKeyId) do  
  36.     HotKeyId[i] := GlobalAddAtom(PChar(IntToStr(i)));  //热键命名可随意   
  37.   RegisterHotKey(Handle,HotKeyId[0],0,VK_F2);                //F2   
  38.   RegisterHotKey(Handle,HotKeyId[1],0,VK_UP);                //Up   
  39.   RegisterHotKey(Handle,HotKeyId[2],0,VK_DOWN);              //Down   
  40.   RegisterHotKey(Handle,HotKeyId[3],0,VK_LEFT);              //Left   
  41.   RegisterHotKey(Handle,HotKeyId[4],0,VK_RIGHT);             //Right   
  42.   RegisterHotKey(Handle,HotKeyId[5],0,VK_PRIOR);             //PageUp   
  43.   RegisterHotKey(Handle,HotKeyId[6],0,VK_NEXT);              //PageDown   
  44.   RegisterHotKey(Handle,HotKeyId[7],0,VK_OEM_PLUS);          //+   
  45.   RegisterHotKey(Handle,HotKeyId[8],0,VK_OEM_MINUS);         //-   
  46.   RegisterHotKey(Handle,HotKeyId[9],0,$31);                  //1   
  47.   RegisterHotKey(Handle,HotKeyId[10],0,$41);                 //a   
  48.   RegisterHotKey(Handle,HotKeyId[11],0,VK_RETURN);           //Enter   
  49.   RegisterHotKey(Handle,HotKeyId[12],MOD_CONTROL,VK_RETURN); //Ctrl+Enter   
  50. end;   
  51.   
  52. //热键   
  53. procedure TForm1.WMHotKey(var Msg: TWMHotKey);   
  54. begin  
  55.   if Msg.HotKey = HotKeyId[0then ShowMessage('F2');   
  56.   if (Msg.HotKey=HotKeyId[1]) then ShowMessage('Up');   
  57.   if (Msg.HotKey=HotKeyId[2]) then ShowMessage('Down');   
  58.   if (Msg.HotKey=HotKeyId[3]) then ShowMessage('Left');   
  59.   if (Msg.HotKey=HotKeyId[4]) then ShowMessage('Right');   
  60.   if Msg.HotKey = HotKeyId[5then ShowMessage('PageUp');   
  61.   if Msg.HotKey = HotKeyId[6then ShowMessage('PageDown');   
  62.   if Msg.HotKey = HotKeyId[7then ShowMessage('+');   
  63.   if Msg.HotKey = HotKeyId[8then ShowMessage('-');   
  64.   if Msg.HotKey = HotKeyId[9then ShowMessage('1');   
  65.   if Msg.HotKey = HotKeyId[10then ShowMessage('a');   
  66.   if Msg.HotKey = HotKeyId[11then ShowMessage('Enter');   
  67.   if Msg.HotKey = HotKeyId[12then ShowMessage('Ctrl+Enter');   
  68. end;   
  69.   
  70. procedure TForm1.FormDestroy(Sender: TObject);   
  71. var  
  72.   i: Integer;   
  73. begin  
  74.   //注销热键   
  75.   for i := Low(HotKeyId) to High(HotKeyId) do  
  76.   begin  
  77.     UnRegisterHotKey(handle,HotKeyId[i]);   
  78.     GlobalDeleteAtom(HotKeyId[i]);   
  79.   end;   
  80. end;   
  81.   
  82. end.   
阅读(571) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~