While loop using a lot of CPU time

后端 未结 3 1599
無奈伤痛
無奈伤痛 2020-12-21 13:00

I am creating a keystroke logger for my personal interest, as well wanting to know how to capture and use them as functions (like key shortcuts).

I got the code to l

3条回答
  •  萌比男神i
    2020-12-21 13:14

    Basically, you want to use this function:

    HHOOK SetWindowsHookEx(
      __in  int idHook,
      __in  HOOKPROC lpfn,
      __in  HINSTANCE hMod,
      __in  DWORD dwThreadId
    );
    

    You can read up on what the parameters mean (and there's plenty of examples around) but the part that answers your question is the second parameter. You set lpfn to point to a callback function, and every time a key is pressed your function (the one that logs the keystroke) gets called.

    It's not just for the keyboard events either, check it out: SetWindowsHook()

提交回复
热议问题