13LogKeyCounClick.c 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include <Windows.h>
  3. #include <stdlib.h>
  4. HHOOK hHook = NULL;
  5. int count;
  6. WPARAM ButtonCode;
  7. LPWSTR str[256];
  8. LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
  9. {
  10. if (nCode == HC_ACTION)
  11. {
  12. switch (wParam)
  13. {
  14. case WM_LBUTTONDOWN:
  15. if (ButtonCode != wParam)
  16. count = 0;
  17. ButtonCode = wParam;
  18. count++;
  19. swprintf_s(str, 256, L"Левая клавиша мыши нажата %d раз", count);
  20. MessageBox(NULL, str, L"Оповещение", MB_OK);//Дальше по аналогии
  21. break;
  22. }
  23. }
  24. return CallNextHookEx(hHook, nCode, wParam, lParam);
  25. }
  26. int main()
  27. {
  28. hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0);
  29. MSG msg;
  30. while (GetMessage(&msg, NULL, 0, 0))
  31. {
  32. TranslateMessage(&msg);
  33. DispatchMessage(&msg);
  34. }
  35. UnhookWindowsHookEx(hHook);
  36. return 0;
  37. }