[Delphi] 纯文本查看 复制代码
unit Unit4;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus,
Vcl.ComCtrls;
type
TForm4 = class(TForm)
HotKey1: THotKey;
function ShiftStateToWord(Shift: TShiftState): Word;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure HotKey1Change(Sender: TObject); //热键组合键分解
private
{ Private declarations }
var
aatom: ATOM;
Key, Shift: Word;
public
{ Public declarations }
procedure hotkey(var msg: TMessage); message WM_HOTKEY;//定义全局热键消息事件
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
function TForm4.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 TForm4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterHotKey(Handle, aatom);
GlobalDeleteAtom(aatom);
end;
procedure TForm4.hotkey(var msg: TMessage);
begin
if (msg.LparamLo = Shift) and (msg.LParamHi = Key) then
begin
ShowMessage('调用成功!');
end;
end;
procedure TForm4.HotKey1Change(Sender: TObject);
var
T: TShiftState;
begin
if FindAtom('ZWXhotKey') = 0 then
begin
aatom := GlobalAddAtom('ZWXhotKey');
end;
ShortCutToKey(HotKey1.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;
end.
|