Hello!

Here is the function of handling the hook to the keyboard:

function KeyboardProc(nCode: Integer; wParam: wParam; lParam:lParam ): LParam; stdcall; begin messagebeep(1000,100); //for example end; 

And how can you handle the pressed key and make the speaker peep when you press a certain key? For example, on "1" or "2". Tried to do all this with the help

 GetAsyncKeyState 

and

 GetKeyState 

But the complete nonsense came out, because the first function determines the state not at the current moment, but for the entire time of operation (roughly speaking). So how can you get the key code in the hook? Thank!

  • @Asen When formatting a code, it is not necessary to add a quotation mark> at the beginning of a line, 4 spaces or tabs are enough. - Nicolas Chabanovsky

1 answer 1

It's simple - read the KeyboardProc (MSDN) documentation carefully.

wParam [in] Type: WPARAM

The keystroke message.

- from wParam and take the key code ...

  • It does not work. It turned out to be done using the PMsg structure. - AseN
  • 2
    @ 0xFFh: Maybe write a canonical answer and accept it? For future generations. - VladD