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.
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;