problem with setwindowshookex
Hi guys,
I want to disable any key press and mouse move.
For that purpose i use SetWindowsHookEx on WH_KEYBOARD_LL & WH_MOUSE_LL, the problem is, that after I unhook thos functions with UnhookWindowsHookEx, all the keys that were pressed and the mouse moves that were made before i installed my hook, happens.
here is my hook function of the keyboard:
Code:
__declspec(dllexport)LRESULT CALLBACK KeyboardHookProc(
int code,
WPARAM wParam,
LPARAM lParam
)
{
if(code==HC_ACTION)
{
if(wParam==WM_KEYDOWN || wParam==WM_KEYUP || wParam==WM_SYSKEYDOWN ||
wParam==WM_SYSKEYUP)
{
return 1;
}
}
return CallNextHookEx(hKeyboard,code,wParam,lParam);
}
any idea how to block this operation from occuring even after I unhook the keyboard?
thanks in advance.
Re: problem with setwindowshookex
When you unhook, your code is no longer running.
Then how do you expect to block keyboard operations.
You could trick the user to pull out the keyboard cable.
Re: problem with setwindowshookex
Hi,
thanks for the comment, but you didn't understand me fully.
the keys that were pressed when i hooked the keyboard, are being "pressed" after i unhooked the keyboard.
so if while the keyboard is hooked i wrote "hello world", nothing will happen, untill i will unhook the keyboard, and then "hello world" will be written on the screen, even though i haven't touched the keyboard.
Re: problem with setwindowshookex
Now I understand your question.
Before return 1; you could add the following line.
while (PeekMessage(&msg, hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
Re: problem with setwindowshookex
And what if the window thet recieves the keyboard events dose't belong to the current thread?
Isn't there a way to tell windows to drop thos keys through the hook procedure?