Set global shortcut

zhaozj2021-02-16  53

type TForm1 = class (TForm) procedure FormCreate (Sender: TObject); procedure FormDestroy (Sender: TObject); protected procedure hotykey (var msg: TMessage); message WM_HOTKEY; end; var Form1: TForm1; id, id2: Integer; implementation {$ R * .dfm} Procedure TFORM1.HOTYKEY (VAR MSG: TMESSAGE); begin if (msg.lparamlo = mod_control) and (msg.lparamhi = 81) THEN BEGIN SHOWMESAGE ('Ctrl Q'); END; IF msg.LParamLo = MOD_CONTROL) and (msg.LParamHi = 82) then begin ShowMessage ( 'Ctrl R'); end; end; procedure TForm1.FormCreate (Sender: TObject); begin id: = GlobalAddAtom ( 'hotkey'); RegisterHotKey (handle, id, mod_control, 81); id2: = GlobalAddAtom ( 'hotkey2'); RegisterHotKey (handle, id2, mod_control, 82); end; procedure TForm1.FormDestroy (Sender: TObject); begin UnRegisterHotKey (handle, id UnregisterhotKey (Handle, ID2); END;

转载请注明原文地址:https://www.9cbs.com/read-27135.html

New Post(0)