Delphi 搭配HotKeyEdit控件来解决问题


本文整理自网络,侵删。

 
function ShiftStateToWord(Shift: TShiftState): Word; //热键组合键分解
   private
     { Private declarations }
     var
       aatom: ATOM;
       Key, Shift: Word;
   public
     { Public declarations }
     procedure hotkey(var msg: TMessage); message WM_HOTKEY;//定义全局热键消息事件
function TForm1.ShiftStateToWord(Shift: TShiftState): Word;
begin
  if ssShift in Shift then
    Result := MOD_SHIFT;
  if ssCtrl in Shift then
    Result := Result or MOD_CONTROL;
  if ssAlt in Shift then
    Result := Result or MOD_ALT;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnregisterHotKey(Handle, aatom);
  GlobalDeleteAtom(aatom);
end;
procedure TForm1.RzBitBtnSetHotKeyClick(Sender: TObject);
var
  T: TShiftState;
begin
  if FindAtom('ZWXhotKey') = 0 then
  begin
    aatom := GlobalAddAtom('ZWXhotKey');
  end;
  ShortCutToKey(RzHotKeyEditSys.HotKey, Key, T);
  Shift := ShiftStateToWord(T);

  try
    if RegisterHotKey(Handle, aatom - $C000, Shift, Key) then
    begin
      ShowMessage('注册成功');
    end;
  except
    on e: Exception do
      ShowMessage(e.Message);

  end;

end;
procedure TForm1.hotkey(var msg: TMessage);
begin
  if (msg.LparamLo = Shift) and (msg.LParamHi = Key) then
  begin
    ShowMessage('OK');
  end;

end;

相关阅读 >>

Delphi 高亮选中memo某一行

embarcadero开源项目赞助

Delphi关于小数位精度的问题

Delphi编程之win10桌面图标设置

Delphi 设置系统静音取消系统静音

Delphi 让子窗体显示在任务栏上

Delphi远程线程注入获取qq密码

Delphi tclientdataset用法详解

Delphi sqlite实现加密

Delphi对access文件加密

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...