C# keyhook question

Posted by user203123 on Stack Overflow See other posts from Stack Overflow or by user203123
Published on 2010-04-10T10:59:10Z Indexed on 2010/04/10 11:03 UTC
Read the original article Hit count: 141

Filed under:
|

I copied the following code from http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx,

public int hookProc(int code, int wParam, ref keyboardHookStruct lParam) 
{
    if (code >= 0) 
    {
     Keys key = (Keys)lParam.vkCode;
     if (HookedKeys.Contains(key)) 
        {
         KeyEventArgs kea = new KeyEventArgs(key);
         if((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null)) 
            {KeyDown(this, kea) ;} 
            else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null)) 
            {KeyUp(this, kea); }
            if (kea.Handled)
            {return 1;}
      }
     }
     lParam.vkCode ++;
     lParam.scanCode ++;
     return CallNextHookEx(hhook, code, wParam, ref lParam);
}

It works fine but when I make a little change:

lParam.vkCode ++;
or
lParam.scanCode ++;

right before the return CallNextHookEx(...), the original keys still appears in Notepad. Ex. If I press "a", I expect the letter in Notepad will be "b" but it still "a". It seems like "lParam" doesn't change. Couldn't understand why?

© Stack Overflow or respective owner

Related posts about c#

Related posts about keyhook