ShortCutToText , TextToShortCut 需 uses Menus;
typeTForm1 = class(TForm)HotKey1: THotKey;Button1: TButton;procedure
Button1Click(Sender: TObject);procedure
FormDestroy(Sender: TObject);private{ Private declarations }procedure
WMHotKey(var
Msg:TMessage);message WM_HOTKEY;public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}varKey, Shift: Word;Id: Integer;procedure
ShortCutToKey(ShortCut: TShortCut; var
Key: Word; var
Shift: TShiftState);beginKey := ShortCut and
not (scShift + scCtrl + scAlt);Shift := [];if ShortCut and
scShift <> 0
then Include(Shift, ssShift);if ShortCut and
scCtrl <> 0
then Include(Shift, ssCtrl);if ShortCut and
scAlt <> 0
then Include(Shift, ssAlt);end;function
ShiftStateToWord(TShift: TShiftState): Word;beginResult := 0;if ssShift in
TShift then
Result := MOD_SHIFT;if ssCtrl in
TShift then
Result := Result or
MOD_CONTROL;if ssAlt in
TShift then
Result:= Result or
MOD_ALT;end;procedure
TForm1.Button1Click(Sender: TObject);varT: TShiftState;beginId := GlobalAddAtom(‘MyHotKey‘) - $C000;ShortCutToKey(HotKey1.HotKey, Key, T);Shift := ShiftStateToWord(T);RegisterHotKey(Handle, Id, Shift, Key);end;procedure
TForm1.WMHotKey(var
Msg: TMessage);beginif (Msg.LparamLo = Shift) AND
(Msg.LParamHi = Key) thenShowMessage(‘This is HotKey‘);end;procedure
TForm1.FormDestroy(Sender: TObject);beginUnRegisterHotKey(Handle, Id);GlobalDeleteAtom(Id);end;end. |
原文地址:http://www.cnblogs.com/lifelog/p/3758581.html