问题描述
同一个HOOK类,在winform程序中一切正常,到wpf程序中鼠标按键,键盘HOOK都正常,就是没有mousewheel滚轮方向,不论鼠标滚轮向哪个方向滚向,一直都是正数,无法判断滚轮方向了,找了几天找不到原因,有人碰到过类似的没?'设置HOOKMouseHookProcedure=NewHookProc(AddressOfMouseHookProc)hMouseHook=SetWindowsHookEx(WH_MOUSE_LL,MouseHookProcedure,IntPtr.Zero,Hwnd)'HOOK类的mousewheel事件PrivateFunctionMouseHookProc(ByValnCodeAsInteger,ByValwParamAsInteger,ByVallParamAsIntPtr)AsIntegerIfnCode>=0ThenStaticmouseHookStructAsMouseLLHookStructStaticmouseDeltaAsInteger:mouseDelta=0'滚轮值SelectCasewParamCaseWM_MOUSEWHEELmouseHookStruct=DirectCast(Marshal.PtrToStructure(lParam,GetType(MouseLLHookStruct)),MouseLLHookStruct)StaticintAsInteger:int=(mouseHookStruct.MouseData>>16)And&HFFFF'Ifint>Short.MaxValueThenmouseDelta=int-65536ElsemouseDelta=intRaiseEventMouseWheel(mouseDelta)EndSelectEndIfReturnCallNextHookEx(hMouseHook,nCode,wParam,lParam)'激活下一个钩子endfunction
解决方案
解决方案二:
用spy++调试下你的消息