Delphi全局注册自定义快捷建功能

方法一

procedure hotykey(var msg:TMessage); message WM_HOTKEY;

var

F1_ID,F2_ID,F3_ID,F4_ID,F5_ID,F6_ID,F7_ID,F8_ID,F9_ID,F10_ID,F11_ID,F12_ID,DCP_Key1,DCP_Key2,DCP_Key3,DCP_KeyQ:integer; //注册全局快捷键


procedure TDcpSSC.FormCreate(Sender: TObject);
begin

    if GlobalFindAtom('MyDCP_Key1HotKey') > 0 then
    begin
    DCP_Key1:=GlobalAddAtom('MyDCP_Key1HotKey');
    RegisterHotKey(handle,DCP_Key1,MOD_CONTROL,Ord('1'));
    end ;
    if GlobalFindAtom('MyDCP_Key2HotKey') > 0 then
    begin
    DCP_Key2:=GlobalAddAtom('MyDCP_Key1HotKey');
    RegisterHotKey(handle,DCP_Key2,MOD_CONTROL,Ord('2'));
    end ;
    if GlobalFindAtom('MyDCP_Key3HotKey') > 0 then
    begin
    DCP_Key3:=GlobalAddAtom('MyDCP_Key1HotKey');
    RegisterHotKey(handle,DCP_Key3,MOD_CONTROL,Ord('3'));
    end ;
    if GlobalFindAtom('MyDCP_KeyQHotKey')> 0 then
    begin
    DCP_KeyQ:=GlobalAddAtom('MyDCP_KeyQHotKey');
    RegisterHotkey(Handle,DCP_KeyQ,MOD_CONTROL,Ord('Q'));
    end ;

end;


 procedure TDcpSSC.hotykey(var msg:TMessage);
 begin
      if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('1')) then
         begi

            ShowMessage('哈哈,按下了CTRL+1');
         end;
      if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('2')) then
         begin

            ShowMessage('哈哈,按下了CTRL+2');
         end;
      if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =51) then
         begin

            ShowMessage('哈哈,按下了CTRL+3');
         end;
      if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('Q')) then
         begin

            ShowMessage('哈哈,按下了CTRL+Q');
         end;

    end;

procedure TDcpSSC.FormDestroy(Sender: TObject);
begin
    UnRegisterHotKey(handle,DCP_Key1);
    GlobalDeleteAtom(DCP_Key1);
    UnRegisterHotKey(handle,DCP_Key2);
    GlobalDeleteAtom(DCP_Key2);
    UnRegisterHotKey(handle,DCP_Key3);
    GlobalDeleteAtom(DCP_Key3);
    UnRegisterHotKey(handle,DCP_KeyQ);
    GlobalDeleteAtom(DCP_KeyQ);
end;

 

 

方法二

procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;

 if GlobalFindAtom('MyF1HotKey') = 0 then
    begin
    F1_ID:=GlobalAddAtom('MyF1HotKey');
    RegisterHotKey(handle,F1_id,0,VK_F1);
    end;
    if GlobalFindAtom('MyF2HotKey') = 0 then
    begin
    F2_ID:=GlobalAddAtom('MyF2HotKey');
    RegisterHotKey(handle,F2_id,0,VK_F2);
    end;
    if GlobalFindAtom('MyF3HotKey') = 0 then
    begin
    F3_ID:=GlobalAddAtom('MyF3HotKey');
    RegisterHotKey(handle,F3_id,0,VK_F3);
    end;
    if GlobalFindAtom('MyF4HotKey') = 0 then
    begin
    F4_ID:=GlobalAddAtom('MyF4HotKey');
    RegisterHotKey(handle,F4_id,0,VK_F4);
    end;
    if GlobalFindAtom('MyF6HotKey') = 0 then
    begin
    F5_ID:=GlobalAddAtom('MyF5HotKey');
    RegisterHotKey(handle,F5_id,0,VK_F5);
    end;
    if GlobalFindAtom('MyF6HotKey') = 0 then
    begin
    F6_ID:=GlobalAddAtom('MyF6HotKey');
    RegisterHotKey(handle,F6_id,0,VK_F6);
    end;
    if GlobalFindAtom('MyF7HotKey') = 0 then
    begin
    F7_ID:=GlobalAddAtom('MyF7HotKey');
    RegisterHotKey(handle,F7_id,0,VK_F7);
    end;
    if GlobalFindAtom('MyF8HotKey') = 0 then
    begin
    F8_ID:=GlobalAddAtom('MyF8HotKey');
    RegisterHotKey(handle,F8_id,0,VK_F8);
    end ;
    if GlobalFindAtom('MyF9HotKey') = 0 then
    begin
    F9_ID:=GlobalAddAtom('MyF9HotKey');
    RegisterHotKey(handle,F9_id,0,VK_F9);
    end;
    if GlobalFindAtom('MyF10HotKey') = 0 then
    begin
    F10_ID:=GlobalAddAtom('MyF10HotKey');
    RegisterHotKey(handle,F10_id,0,VK_F10);
    end ;
    if GlobalFindAtom('MyF11HotKey') = 0 then
    begin
    F11_ID:=GlobalAddAtom('MyF11HotKey');
    RegisterHotKey(handle,F11_id,0,VK_F11);
    end ;
    if GlobalFindAtom('MyF12HotKey') = 0 then
    begin
    F12_ID:=GlobalAddAtom('MyF12HotKey');
    RegisterHotKey(handle,F12_id,0,VK_F12);
    end ;

procedure TDcpSSC.WMHotKey(var Msg: TWMHotKey);
begin
      //ABCDEF做单获取编辑框坐标
      if msg.HotKey = F1_id then
      begin
      ButtonAzuClick(nil);
      end;
      if msg.HotKey = F2_id then
      begin
      ButtonBzuClick(nil);
      end;
      if msg.HotKey = F3_id then
      begin
      ButtonCzuClick(nil);
      end;
      if msg.HotKey = F4_id then
      begin
      ButtonDzuClick(nil);
      end;
      if msg.HotKey = F5_id then
      begin
      ButtonEzuClick(nil);
      end;
      if msg.HotKey = F6_id then
      begin
      ButtonFzuClick(nil);
      end;
      //获取编辑框坐标
      if msg.HotKey = F7_id then
      begin
      TimerXy.enabled:=true;
      end;
      if msg.HotKey = F8_id then
      begin
      TimerXy.enabled:=false;
      end;

      //获取按钮坐标
      if msg.HotKey = F9_id then
      begin
      TimerbtnXy.enabled:=true;
      end;
      if msg.HotKey = F10_id then
      begin
      TimerbtnXy.enabled:=false;
      end;
      //点击下注按钮
      if msg.HotKey = F11_id then
      begin
      ButtonVrSendClick(nil);
      end;
      //点击测试按钮
      if msg.HotKey = F12_id then
      begin
      ButtonVrSendTestClick(nil);
      end;
end;

procedure TDcpSSC.FormDestroy(Sender: TObject);
begin
    UnRegisterHotKey(handle,F1_id);
    GlobalDeleteAtom(F1_id);
    UnRegisterHotKey(handle,F2_id);
    GlobalDeleteAtom(F2_id);
    UnRegisterHotKey(handle,F3_id);
    GlobalDeleteAtom(F3_id);
    UnRegisterHotKey(handle,F4_id);
    GlobalDeleteAtom(F4_id);
    UnRegisterHotKey(handle,F5_id);
    GlobalDeleteAtom(F5_id);
    UnRegisterHotKey(handle,F6_id);
    GlobalDeleteAtom(F6_id);
    UnRegisterHotKey(handle,F7_id);
    GlobalDeleteAtom(F7_id);
    UnRegisterHotKey(handle,F8_id);
    GlobalDeleteAtom(F8_id);
    UnRegisterHotKey(handle,F9_id);
    GlobalDeleteAtom(F9_id);
    UnRegisterHotKey(handle,F10_id);
    GlobalDeleteAtom(F10_id);
    UnRegisterHotKey(handle,F11_id);
    GlobalDeleteAtom(F11_id);
    UnRegisterHotKey(handle,F12_id);
    GlobalDeleteAtom(F12_id);
end;

个要喜欢用方案二

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

再创世纪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值