Register hotkey!

xiaoxiao2021-03-06  35

1. Define hotkey ID variables

Private {private declarations}}}}}}} {private; // Global variable, define hot key ID variable Procedure Shorcut (var msg: tMessage); // Define Windows message WM_HOTKEY HOOK Chain Message WM_HOTKEY;

2. Register hotkey:

HotKeyID: = GlobalAddatom ('Hotkey'); RegisterhotKey (Handle, HotKeyID, Mod_Control, 88);

3. Message Response:

Procedure tform1.shorcut (var msg: tMessage); beginmsg.result: = 1; // indicates that the message has been used! Application.BringTofront; Application.MessageBox ('hotkey has played!', 'prompt', MB_OK MB_ICONITIONMATION END;

4. Release Resources:

Procedure TForm1.FormDestroy (Sender: TOBJECT); Beginunregisterhotkey; deletetom (HotKeyID); end; 5.registerhotKey function protests as follows

Bool RegisterhotKey (HWND HWND, // Connecting the Hotkey Window Handle

INT ID, // Global Atom Handle

Uint fsmodifiers, / / ​​hotkey modified logo

UINT VK / / Virtual Keyboard Code

);

Looking for virtual key values, you can search for Virtual Key in Delphi Help

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

New Post(0)