Hotkey problem lazarus / 13-General ---------------------------------------------------------------------- Cz-David · 2008-02-05 11:47 I'am trying to make windows wide hotkey using register hot key... but declaration in private Code: [Select]Procedure WMHotkey( Var msg: TWMHotkey );     message WM_HOTKEY; gives this Code: [Select]main.pas(41,44) Error: Identifier not found "TWMHotkey" so i've checked the messages.inc and there is no hotkey what so ever. then i tried using google... nothing useful for lazarus... in this forum i've found usage of "TMessage" instead of twmhotkey... it does not show any error message but it doesn't work either... Code: [Select]procedure Tmain_form.FormCreate(Sender: TObject); begin   registerhotkey(handle, 1, mod_control or mod_shift, vk_f2); end; Code: [Select]procedure Tmain_form.wmhotkey(var msg:TMessage); //TWMHotkey   begin     showmessage('Byla stisknuta klávesová zkratka');     msg.Result:=0;   end; ---------------------------------------------------------------------- Phil · 2008-02-05 18:45 Quote from: "Cz-David"Code: [Select]main.pas(41,44) Error: Identifier not found "TWMHotkey" Take a look at this: http://www.bitwisemag.com/copy/delphi/delphi3.html TWMHotKey does not appear to be declared in any FPC or LCL unit, but you should be able to use TMessage. The hotkey is passed in the WParam field of the TMesage record. Thanks. -Phil ---------------------------------------------------------------------- Cz-David · 2008-02-05 20:59 OK. I've read it... but it doesnt help... I have tried Code: [Select]procedure Tmain_form.wmhotkey(var msg:TMessage); begin   if msg.wparam = 1 then   begin     showmessage('Byla stisknuta klávesová zkratka');     msg.Result:=0;   end; end; but it still does not work... I think I need more "step by step" help... but thanks anyway ---------------------------------------------------------------------- Leledumbo · 2008-02-06 06:25 Maybe LCL has its cross-platform alternative named as TLMHotKey. Remember, in Lazarus all messages are prefixed with LM not WM. Maybe you can find it in LCLType or LCLIntf. ---------------------------------------------------------------------- Cz-David · 2008-02-06 09:03 Still same error. I found this Code: [Select]  ICC_HOTKEY_CLASS       = $00000040; in LCLType but this is not very helpful... Are you trying to tell me that no one has ever actually made a working hotkey? ---------------------------------------------------------------------- Leledumbo · 2008-02-11 10:02 I've checked LMessages as in Delphi TWMHotKey is defined there. It looks like currently LCL doesn't have such a thing. Your code: Code: [Select] procedure Tmain_form.FormCreate(Sender: TObject); begin   registerhotkey(handle, 1, mod_control or mod_shift, vk_f2); end; Seems to work fine. Have you checked the result of registerhotkey? ---------------------------------------------------------------------- Cz-David · 2008-02-11 14:38 Code: [Select] if not registerhotkey(handle, 1, mod_control or mod_shift, vk_f2) then showmessage('hotkey error'); work fine ---------------------------------------------------------------------- Cz-David · 2008-02-18 10:28 User mishob gave me an answer. Working answer. It is kinda bypass for the message function but it works... The virtual hotkey number can be find very easily. Code: [Select] type   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);     procedure FormDestroy(Sender: TObject);   private     procedure Hook;     procedure Unhook;   public     procedure ProcessHotKey(HK: LongInt);   end; var   Form1: TForm1; type   TMWndProc = Windows.WNDPROC; var   OldProc: TMWndProc; function MsgProc(Handle: HWnd; Msg: UInt; WParam: Windows.WParam;                  LParam: Windows.LParam): LResult; stdcall; implementation procedure TForm1.FormCreate(Sender: TObject); begin   RegisterHotKey(Handle, 0, MOD_WIN, VK_A);   Hook; end; procedure TForm1.FormDestroy(Sender: TObject); begin   Unhook;   UnregisterHotKey(Handle, 0); end;   procedure TForm1.Hook; begin   OldProc := TMWndProc(Windows.GetWindowLong(Handle, GWL_WNDPROC));   Windows.SetWindowLong(Handle, GWL_WNDPROC, LongInt(@MsgProc)); end; procedure TForm1.Unhook; begin   if Assigned(OldProc) then     Windows.SetWindowLong(Handle, GWL_WNDPROC, LongInt(OldProc));   OldProc := nil; end;       procedure TForm1.ProcessHotKey(HK: LongInt); begin   // HK is a virtual key code, process it here end; function MsgProc(Handle: HWnd; Msg: UInt; WParam: Windows.WParam;     LParam: Windows.LParam): LResult; stdcall; begin   with Form1 do   begin     if Msg = WM_HOTKEY then       ProcessHotKey(HIWORD(LParam))     else       Result := Windows.CallWindowProc(OldProc, Handle, Msg, WParam, LParam);   end; end;