- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一个用 VB.NET 编写的代码示例,以使用 user32.dll 和 的低级 Hook 捕获表单外的鼠标滚轮滚动事件 WM_MOUSEWHEEL 就像 Hans Passant 在我的其他问题中回答的那样:Record mouse Middle button and wheel scroll
这是我需要做的伪示例:
Dim mousewheel_up as boolean
Dim mousewheel_down as boolean
Sub that Overides the windows messages to set the mousewheel booleans
If mousewheel_up then msgbox("MouseWheel up")
If mousewheel_down then msgbox("MouseWheel down")
End sub
UPDATE
试过了,但它只在表单内有效,而且我不知道如何获取增量值:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Application.AddMessageFilter(New MouseWheelMessageFilter())
End Sub
Public Class MouseWheelMessageFilter : Implements IMessageFilter
Public Function PreFilterMessage1(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
' Filter out WM_MOUSEWHEEL messages, which raise the MouseWheel event,
' whenever the Ctrl key is pressed. Otherwise, let them through.
Const WM_MOUSEWHEEL As Integer = &H20A
'If m.Msg = WM_MOUSEWHEEL & My.Computer.Keyboard.CtrlKeyDown Then
If m.Msg = WM_MOUSEWHEEL Then
' Process the message here.
If Form.ActiveForm IsNot Nothing Then
MsgBox("Mouse scrolled!")
' TODO: Insert your code here to adjust the size of the active form.
' As shown above in the If statement, you can retrieve the form that
' is currently active using the static Form.ActiveForm property.
' ...
End If
Return True ' swallow this particular message
End If
Return False ' but let all other messages through
End Function
End Class
最佳答案
您需要使用 SetWindowsHookEx函数并将 Hook 类型指定为 *WH_MOUSE_LL* (14)。有以下声明。
Public Structure Point
Public X As Integer
Public Y As Integer
End Structure
Public Structure Msllhookstruct
Public Location As Point
Public MouseData As Integer
Public Flags As Integer
Public Time As Integer
Public ExtraInfo As Integer
End Structure
Private Delegate Function HookProc(nCode As Integer, wParam As Integer, ByRef lParam As Msllhookstruct) As Integer
<DllImport("user32.dll", SetLastError:=True)> _
Private Function SetWindowsHookEx(ByVal hookType As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByRef lParam As Msllhookstruct) As IntPtr
End Function
Private Hook As IntPtr
在您的初始化例程中,按如下方式使用它
Hook = SetWindowsHookEx(14, AddressOf Proc, Process.GetCurrentProcess().MainModule.BaseAddress.ToInt32(), 0)
其中 Proc
是一个函数回调,如下所示:
Private Function Proc(nCode As Integer, wParam As Integer, ByRef lParam As Msllhookstruct) As IntPtr
If wParam = 522 Then
Dim Delta = CShort(lParam.MouseData >> 16)
If Delta > 0 Then
' Up
ElseIf Delta < 0 Then
' Down
End If
End If
Return CallNextHookEx(Hook, nCode, wParam, lParam)
End Function
关于.net - 为 WM_MOUSEWHEEL 设置 WindowsHookEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16857370/
我需要一个用 VB.NET 编写的代码示例,以使用 user32.dll 和 的低级 Hook 捕获表单外的鼠标滚轮滚动事件 WM_MOUSEWHEEL 就像 Hans Passant 在我的其他问题
我手上有一些代码可以全局打印鼠标坐标(使用 WH_MOUSE_LL)。我的目标是使用 WH_MOUSE 而不是 WH_MOUSE_LL 因为(根据我的阅读)它更快。我在论坛上读到,当使用 WH_MOU
Windows Hook 允许您深入了解其他进程,有时还可以改变它们的行为。 Mac OS X 有这样的东西吗? 谢谢! 最佳答案 SetWindowsHookEx 更像是旧的 InputManage
我正在尝试创建一个 Electron node.js 应用程序,它可以使用全局键绑定(bind)执行某些功能。不幸的是,Electron 中的全局键绑定(bind) API 在游戏中不起作用,因此我需
我是一名优秀的程序员,十分优秀!