How to make the window ignore mouse if not clamped key shift?

There is a window, something like a widget hangs on the top of the screen and shows the image with transparency. It is necessary as that to make so that were pressed only with a pressed shift and simple clicks are transferred to the Windows below.
March 19th 20 at 09:13
1 answer
March 19th 20 at 09:15
Solution
If we talk about Windows, then:

Create a window with extended styles WS_EX_LAYERED | WS_EX_TRANSPARENT|WS_EX_TOPMOST
Set window transparency:
SetLayeredWindowAttributes(hWnd, 0, 100, LWA_ALPHA);

Set the hook on the keyboard:
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KeyboardEvent, hInstance, NULL);

The processing function of the keyboard events (example):

code
LRESULT CALLBACK KeyboardEvent(int nCode, WPARAM wParam, LPARAM lParam)
{
 if ((nCode == HC_ACTION))
{
 KBDLLHOOKSTRUCT* hooked_key = (KBDLLHOOKSTRUCT*)lParam; 
 if (hooked_key->vkCode == VK_LSHIFT || hooked_key->vkCode == VK_RSHIFT) {
 bool shiftPressed = (wParam == WM_KEYDOWN);
 LONG oldStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
 if (shiftPressed) {
 SetWindowLong(hWnd, GWL_EXSTYLE, oldStyle & (~WS_EX_TRANSPARENT));
}
 else {
 SetWindowLong(hWnd, GWL_EXSTYLE, oldStyle | WS_EX_TRANSPARENT);
}
}
}
 return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}

It is dynamically set and reset the extended style WS_EX_TRANSPARENT.

At the exit take the hook:
UnhookWindowsHookEx(hKeyboardHook);
Don't know how to do without the hook, because an inactive window does not come keyboard events.

Find more questions by tags C++