• 将本文章摘录到:

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息
    http://blog.bloodbird.com/tianwufengBlogs/Technology/200904/20090419231950.Html

    程序经常用到全局热键今天简单记录一下

    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.     { Private declarations }
    15.      procedure OnHotKey(var Msg: Tmessage); message WM_HOTKEY;
    16.   public
    17.     { Public declarations }
    18.   end;
    19.  
    20. var
    21.   Form1: TForm1;
    22.   idHotKey: WORD;
    23.  
    24. implementation
    25.  
    26. uses Unit2;
    27.  
    28. {$R *.dfm}
    29.  
    30. procedure TForm1.OnHotKey(var Msg: Tmessage);
    31. begin
    32.   {f12键被按下}
    33.   if Msg.LParamHi = vk_home then begin
    34.     Msg.result := 1//该消息已经被处理
    35.     try
    36.       if form2 <> nil then form2.show else form2.hide;
    37.     finally
    38.     end;
    39.   end;     
    40. end;
    41.  
    42. procedure TForm1.FormCreate(Sender: TObject);
    43. begin
    44. if idHotKey <> 0 then exit;
    45.   idHotKey := GlobalAddAtom('EmuMouse'); //给热键取得一个唯一的标识
    46.   RegisterHotKey(handle, idHotKey, 0, vk_home); //注册热键
    47. end;
    48.  
    49. procedure TForm1.FormDestroy(Sender: TObject);
    50. begin
    51.   UnRegisterHotKey(handle, idHotKey); // 释放热键
    52.   GlobalDeleteAtom(idHotKey); //
    53. end;
    54.  
    55. end.


     

    Tag:热键
    引用地址:

    评论

    正在读取日志的评论数据,请稍后……
    正在加载日志评论签写框,请稍后……