I'm looking for a way to cach a global hotkey in firemonkey app (windows only, at least for now). After some frustration and googling this is supposed to work: register hotkey with winapi call
RegisterHotKey(FmxHandleToHWND(form1.Handle), 0 , MOD_CONTROL, $41);
it returns true.
and then catch the hotkey in a forms' procedure
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
but this one is never called. I've used to do that in vcl apps before so my guess is that firemonkey handles messages in different way. So the question is: How do I catch global hotkeys in firemonkey app?
edit: some example of applying that solution. I've created an unit with little class
unit fire_hotkey;
interface
uses windows, messages,allocatehwnd;
type
TMsgHandler = procedure (var Msg: TMessage) of object;
THotClass = class(TObject)
fMsgHandlerHWND : HWND;
proc:TMsgHandler;
constructor Create;
procedure init;
destructor Destroy; override;
end;
implementation
{ hotClass }
constructor THotClass.Create;
begin
inherited;
end;
destructor THotClass.Destroy;
begin
ThreadDeallocateHWnd(fMsgHandlerHWND);
inherited;
end;
procedure THotClass.init;
begin
fMsgHandlerHWND := ThreadAllocateHWnd(proc,true);
end;
end.
then my main form has a procedure for processing hotkey events:
procedure TformEditor.WMHotKey(var Msg: TMessage);
begin
if Msg.Msg = WM_HOTKEY then
begin
//call lua function or sth
//...
end
else
Msg.Result := DefWindowProc(hotkeyGrabber.fMsgHandlerHWND, Msg.Msg, Msg.wParam, Msg.lParam);
end;
and there is a global hotkeyGrabber:THotClass; that gets initialized on form create:
hotkeyGrabber:=THotClass.Create;
hotkeyGrabber.proc:=WMHotKey;
hotkeyGrabber.init;
after that you should register hotkeys like in usual vcl app and they will be cought http://www.swissdelphicenter.ch/torry/showcode.php?id=147 hope it makes sense