CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jul 2006
    Posts
    19

    Low Level Keyboard Hook problem

    Hi Folks,

    I'm currently writting a LLKeyboard hook, my goal is to redirect all inputs just to one window, regardless what other applications are running.
    I made it acutall working so my problem is more trivial:

    ------SNIPPET-------

    Code:
    LRESULT CALLBACK LLHook(int nCode, WPARAM wParam, LPARAM lParam){
    	  KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lParam;
    	  BOOL bCtrl 	= GetAsyncKeyState(VK_CONTROL)>>((sizeo(SHORT) * 8) - 1);
    	  BOOL bShift	= GetAsyncKeyState(VK_SHIFT)>>((sizeof(SHORT) * 8) - 1);
    		
    	  if (nCode==HC_ACTION) {
    		    if(GetFocus() == hWndredirect){
    			    if(!bCtrl && !bShift){				
    				   PostMessage(GetFocus(),WM_KEYDOWN,pkh->vkCode,pkh->scanCode);
    				   //PostMessage(GetFocus(),WM_KEYUP,pkh->vkCode,(LPARAM)0);				
    			    }			
    		    }
    		    else SetFocus(hWndredirect);
    	    }
    	   return(-1);
    }
    ------SNIPPET-------


    This code works well, my only problem is that hWndredirect receives all keys twice. You type "a", "aa" appears and so on, I outcommented the WM_KEYUP message already, without that it was "aaaa".
    My guess is that there probably something is wrong with the scanCode but I can't figure out the problem really.

    Thanks in Advance, Andy
    Last edited by AndyTheAce; April 3rd, 2007 at 06:17 AM.

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