VB用键盘全局HOOK的问题
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim blnHook As Boolean
Dim p As KBDLLHOOKSTRUCT
Dim IsbKeyUp As Boolean
Dim AltKey As Boolean
Call CopyMemory(p, ByVal lParam, Len(p))
AltKey = ((GetKeyState(18) And &H4000) = &H4000) ''''''''''ALT键
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
IsbKeyUp = False
ElseIf wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
IsbKeyUp = True
End If
If AltKey And main.AltChk.Value Then
Debug.Print "1" & AltKey
If p.vkCode = vbKeyQ Then Call keybd_event(103, 0, IIf(IsbKeyUp, 2, 0), 0): blnHook = True
End If
If blnHook Then
LowLevelKeyboardProc = 1
Else
Call CallNextHookEx(WH_KEYBOARD_LL, nCode, wParam, lParam)
End If
End Function
这是我拦截键盘按键的函数。
我要实现“将按ALT+Q改成按小键盘7”
这样为什么不行呢?我debug.print发现是改过的,但是在其它地方按ALT+Q却打不出7,求高手解答
[解决办法]
原来那个代码没找到,自己写了一下,发现写回缓冲区也无法改键.
貌似这招不管用了......有些怪,记得以前看那份代码时是可以的.得再找找.
目前看来你还是得用模拟键盘了.