我从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);
}
它工作正常,但当我做一点改变时:
lParam.vkCode ++;
or
lParam.scanCode ++;
在返回 CallNextHookEx(...) 之前,原来的键仍然出现在记事本中。前任。如果我按“a”,我希望记事本中的字母是“b”,但它仍然是“a”。似乎“lParam”没有改变。无法理解为什么?