Answer the question
In order to leave comments, you need to log in
How to make a window ignore mouse clicks if the shift key is not pressed?
There is a window, something like a widget, hanging on top of the screen and showing a picture with transparency. It is necessary to somehow make it so that the clicks pass only with the shift pressed, and simple clicks are transmitted to the windows from below.
Answer the question
In order to leave comments, you need to log in
If we talk about Windows, then:
Create a window with extended styles WS_EX_LAYERED | WS_EX_TRANSPARENT|WS_EX_TOPMOST
Set the window's transparency:
Install the hook on the keyboard:
Keyboard event handling function (sample view):
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);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question