Low level keyboard input from Windows

后端 未结 5 1299
时光取名叫无心
时光取名叫无心 2021-01-06 01:19

What win32 calls can be used to detect key press events globally (not just for 1 window, I\'d like to get a message EVERY time a key is pressed), from a windows service?

5条回答
  •  时光说笑
    2021-01-06 02:07

    You want to use Win32 Hooks. In particular a keyboard hook.

    You can read more about it here

    The type of hook you want is WH_KEYBOARD and you can set it via the Win32 API SetWindowsHookEx.

    Basically windows will call a function in a dll that you create everytime a key is pressed in any application system wide.

    The hook will call your function which will have this interface:

    LRESULT CALLBACK KeyboardProc(      
        int code,
        WPARAM wParam,
        LPARAM lParam
    );
    

    More information about this callback here.

    With windows hooks you can not only track system wide events across all processes, but you can also filter them and stop them altogether.

提交回复
热议问题