Mega Code Archive

 
Categories / Delphi / System
 

Creating hot keys with Windows Messages

Title: Creating hot-keys with Windows Messages Question: How i can create an hot-key, receiving Windows Messages and programming final action. Answer: In USES: Windows, Dialogs First, put this small code in OnCreate from your form: procedure TForm1.FormCreate(Sender: TObject); begin if not RegisterHotkey(Handle, 1, MOD_CONTROL or MOD_ALT, VK_F11) then ShowMessage('Error registering Ctrl+Alt+F11'); if not RegisterHotkey(Handle, 2, MOD_CONTROL or MOD_ALT, VK_F12) then ShowMessage('Error registering Ctrl+Alt+F12'); end; and in OnDestroy event put: procedure TForm1.FormDestroy(Sender: TObject); begin UnRegisterHotkey(Handle, 1); UnRegisterHotkey(Handle, 2); end; Declare the procedure below in private section from Form: private procedure WMHotkey(var Msg: TWMHotkey); message WM_HOTKEY; Below Implementation clause, put: procedure TForm1.WMHotkey(var Msg: TWMHotkey); begin case Msg.HotKey of 1: WinExec('write.exe', SW_SHOW); 2: ShowMessage('Ctrl+Alt+F12 pressed!'); end; end; YOUR KEYS NOT WILL BE DISPONIBLE IF A WINDOWS LINK HAS THE HOT-KEY!