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

后端 未结 4 1188
借酒劲吻你
借酒劲吻你 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:11

    MouseHookProc should reside in dll, otherwise you can not capture "global" input ( http://msdn.microsoft.com/en-us/library/ms997537.aspx )

    About the loop - you can modify it like this:

    while(true) {
      MSG msg;
      while (PeekMessage(&msg,0,0,0,PM_REMOVE)) {
        printf("msg recvd\n");
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    #ifdef TEST
      DoStuff();
      Sleep(50);
    #endif
    }
    

提交回复
热议问题