Hi, @Ash13
The hook works for me:
#include <iostream>
#include <Windows.h>
HHOOK hookHandle;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION) {
KBDLLHOOKSTRUCT* kbStruct = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
if (wParam == WM_KEYDOWN && kbStruct->vkCode == VK_TAB &&
GetAsyncKeyState(VK_CONTROL) & 0x8000 && GetAsyncKeyState(VK_MENU) & 0x8000) {
std::cout << "Ctrl+Alt+Tab combination intercepted!" << std::endl;
return 1;
}
}
return CallNextHookEx(hookHandle, nCode, wParam, lParam);
}
int main() {
hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);
if (hookHandle == NULL) {
std::cerr << "Failed to install keyboard hook" << std::endl;
return 1;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hookHandle);
return 0;
}
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.