Understanding the low-level mouse and keyboard hook (win32)

后端 未结 4 1180
借酒劲吻你
借酒劲吻你 2020-12-05 05:50

I\'m trying to capture global mouse and keyboard input.

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
  if (nCode >= 0) {
            


        
4条回答
  •  [愿得一人]
    2020-12-05 06:04

    The problem is your message loop, it burns 100% CPU cycles because you use PeekMessage(). Windows knows how to keep the hook alive even if you don't poll for messages, use GetMessage() to solve your problem. Using Sleep(1) will solve your problem too but is not necessary here.

    Why must SetWindowsHookEx be used with a windows message queue

提交回复
热议问题