How to distinguish keyboard keys with the same program code? For example, the "up arrow" on a standard keyboard and the number 8 on the numeric keypad on the right ("up arrow too!"). Here I am processing the key code in the hook in two ways:
1 way <structure PMsg>
function KeyBoardProc(ACode: Integer; AWParam :WParam; AMsg: PMsg): LRESULT; stdcall; begin ... form1.caption:=Inttostr(AMsg.message); // Структура PMsg ... result:=CallNextHookEx(hh,ACode,AWParam,LongInt(Amsg)); end;
2 way <remove (scan) the state of all virtual keys>
function KeyBoardProc(ACode: Integer; AWParam :WParam; AMsg: PMsg): LRESULT; stdcall; var state:TKeyBoardState; begin GetKeyboardState(State); for i:=1 to 255 do if((State[i] and 128) <> 0) then form1.caption:=Inttostr(i); // получаем нажатую клавишу result:=CallNextHookEx(hh,ACode,AWParam,LongInt(Amsg)); end;