Disable hotkey "ctrl + alt + tab"

Ash13 0 Reputation points
2024-02-21T04:46:40.5066667+00:00

I tried to disable the hotkey "ctrl + alt + tab" with a LL keyboard hook,but looks like this key combination cannot be intercepted by LL keyboard hook. Is there any way I can disable it with registry ?

Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2024-02-21T07:00:32.3266667+00:00

    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.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.