Source.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <Windows.h>
  2. #include <Stdio.h>
  3. HHOOK hHook;
  4. LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
  5. LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
  6. {
  7. // Åñëè ñîáûòèå - íàæàòèå êëàâèøè
  8. if (nCode == HC_ACTION && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
  9. {
  10. KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
  11. // Ïîëó÷àåì íàçâàíèå íàæàòîé êëàâèøè
  12. TCHAR szKeyName[256];
  13. DWORD iKey = MapVirtualKey(p->vkCode, NULL) << 16;
  14. if (!((p->vkCode <= 32))) {
  15. iKey |= 0x1 << 24;
  16. }
  17. GetKeyNameText(iKey, szKeyName, 256);
  18. // Âûâîäèì íàçâàíèå êëàâèøè â MessageBox
  19. MessageBox(NULL, szKeyName, "Key Pressed", MB_OK);
  20. }
  21. return CallNextHookEx(hHook, nCode, wParam, lParam);
  22. }
  23. int main()
  24. {
  25. // Óñòàíàâëèâàåì õóê íà îáðàáîòêó ñîáûòèé êëàâèàòóðû
  26. hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);
  27. // Îáðàáàòûâàåì ñîîáùåíèÿ îêíà
  28. MSG msg;
  29. while (GetMessage(&msg, NULL, 0, 0))
  30. {
  31. TranslateMessage(&msg);
  32. DispatchMessage(&msg);
  33. }
  34. // Óäàëÿåì õóê
  35. UnhookWindowsHookEx(hHook);
  36. return 0;
  37. }