include iostream include windows.h using namespace std; HHOOK hHook = 0; LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam; if (p->vkCode == VK_LMENU) // VK_LMENU = ALT key { switch (wParam){ case WM_SYSKEYDOWN :{ // use SYSKEYDOWN cout << "Key down" << endl; keybd_event(VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0 ); break; } case WM_KEYUP: // use regular keyup { cout << "Key up" << endl; keybd_event( VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); return 1; break; } default: wParam = WM_SYSKEYDOWN; // if you do not specify it changes back to alt break; } return 1; } } return CallNextHookEx(hHook, nCode, wParam, lParam); } int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { hHook = SetWindowsHookEx(WH_KEYBOARD_LL, &LowLevelKeyboardProc, hThisInstance, NULL); if (hHook == NULL) { cout << "Error" << endl; return 1; } MSG messages; while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; }
转载于:https://qa.1r1g.com/sf/ask/1219369371/
标签:wParam,lParam,映射,windows,nCode,按键,include,SYSKEYDOWN From: https://www.cnblogs.com/tingtaishou/p/17359788.html