Click to See Complete Forum and Search --> : problem with setwindowshookex


skval
May 6th, 2009, 03:22 PM
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:


__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.

_Superman_
May 7th, 2009, 10:18 AM
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.

skval
May 8th, 2009, 03:09 AM
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.

_Superman_
May 8th, 2009, 03:17 AM
Now I understand your question.

Before return 1; you could add the following line.
while (PeekMessage(&msg, hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));

skval
May 8th, 2009, 04:12 AM
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?