windows – How to get the code of the pressed key in a Delphi hook.

Question:

Hello. There is a function for handling keyboard hooks:

function KeyBoardProc(ACode: Integer; AWParam :WParam; AMsg: PMsg): LRESULT; stdcall;
begin
if AWPARAM = WM_KEYUP then
form1.Caption:=Inttostr(AMSG.message);
result:=CallNextHookEx(hh,ACode,AWParam,LongInt(Amsg));
end;

This function does not handle the hook correctly, because the PMsg structure does not return the ordinal number of the ASCII character, but its ordinal number on the keyboard … what to do? I ask for help. Thank you…


I have 25 points =)

Answer:

Yes, the same thing, but instead of WH_KEYBOARD put WH_GETMESSAGE

function GetMsgProc()(Code: Integer; wParam, lParam: Longint): Longint;

MSDN – GetMsgProc

I found a link with an example. There are sources too. I think you can figure it out.

Scroll to Top