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;
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。