1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include <Windows.h>
- #include <Stdio.h>
- HHOOK hHook;
- LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
- {
- // Åñëè ñîáûòèå - íàæàòèå êëàâèøè
- if (nCode == HC_ACTION && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
- {
- KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
- // Ïîëó÷àåì íàçâàíèå íàæàòîé êëàâèøè
- TCHAR szKeyName[256];
- DWORD iKey = MapVirtualKey(p->vkCode, NULL) << 16;
- if (!((p->vkCode <= 32))) {
- iKey |= 0x1 << 24;
- }
- GetKeyNameText(iKey, szKeyName, 256);
- // Âûâîäèì íàçâàíèå êëàâèøè â MessageBox
- MessageBox(NULL, szKeyName, "Key Pressed", MB_OK);
- }
- return CallNextHookEx(hHook, nCode, wParam, lParam);
- }
- int main()
- {
- // Óñòàíàâëèâàåì õóê íà îáðàáîòêó ñîáûòèé êëàâèàòóðû
- hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);
- // Îáðàáàòûâàåì ñîîáùåíèÿ îêíà
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- // Óäàëÿåì õóê
- UnhookWindowsHookEx(hHook);
- return 0;
- }
|