zoukankan      html  css  js  c++  java
  • 转:快捷键

    unit Unit5;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, RzButton;

    type
      TForm5 = class(TForm)
        btn1: TRzButton;
        HotKey1: THotKey;
        procedure HotKey1Enter(Sender: TObject);
        procedure btn1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;

        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form5: TForm5;

    implementation

    {$R *.dfm}
    var
      HotKeyId: array[0..12] of Integer;  //热键数组, 这里准备定义 13 个热键

    procedure TForm5.btn1Click(Sender: TObject);
    begin
      ShowMessage('HotKey');
    end;

    procedure TForm5.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_F1);                //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 TForm5.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;

    procedure TForm5.HotKey1Enter(Sender: TObject);
    begin
      //btn1Click(nil);
    end;

    procedure TForm5.WMHotKey(var Msg: TWMHotKey);
    begin
      if Msg.HotKey = HotKeyId[0] then btn1Click(nil);//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;

    end.

  • 相关阅读:
    【网络流24题】魔术球问题(最小不相交路径覆盖)
    【网络流24题】搭配飞行员(太空飞行计划问题)(最大闭合图)
    【网络流24题】搭配飞行员(飞行员配对方案问题)(网络流)
    bzoj 1664 (贪心)
    关于正方形类问题
    就代码格式化问题
    提高组2017游记
    线程同步
    线程的优先级
    线程的常用方法
  • 原文地址:https://www.cnblogs.com/huking/p/1790205.html
Copyright © 2011-2022 走看看