CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Posts
    33

    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.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Dec 2007
    Posts
    33

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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));
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  5. #5
    Join Date
    Dec 2007
    Posts
    33

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured