I need to block keys from a certain input device and I use a keyboard hook to do that, here it the hook function
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (SendMessage(targetWindow, WM_HOOK, wParam, lParam)) {
return 1;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
because the keyboard hook is not able to receive the device handle, I use windows messaging system to message to a custom case called WM_HOOK, this case PeekMessage the WM_INPUT to see which device handle from RAWINPUT is creating the input, then returns an integer as it is the device handle that keys should be blocked or not
the whole hook works correctly except when I use SendMessage, the keydown event will be produced no matter what, the function waits for the return and does not execute anything until there is a return from message (tested with std::cout) but when I'm using SendMessage in my hook the keydown event is being produced even when hook returns 1, So I have no idea what causes this behavior.
the whole program is in the same process and communication of 2 functions are successful but windows is not waiting for hook when messaging is involved and I don't know what causes it?