[英]Creating new MouseWheelEventArgs for Global Mouse Hook
As per MSDN below is the MouseWheelEventArgs constructor 根据MSDN,下面是MouseWheelEventArgs构造函数
public MouseWheelEventArgs(
MouseDevice mouse,
int timestamp,
int delta
)
This is a method from my Global Mouse Hook that I am trying to complete: 这是我试图完成的Global Mouse Hook中的一种方法:
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && MouseMessages.WM_MOUSEWHEEL == (MouseMessages)wParam)
{
MouseDevice mouseDev = InputManager.Current.PrimaryMouseDevice;
MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
//Initializes a new instance of the MouseWheelEventArgs class using the specified MouseDevice, timestamp, and delta.
MouseAction(null, new MouseWheelEventArgs(mouseDev, timestamp, delta));
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
What I'm looking for is: 我正在寻找的是:
Timestamp - it is fine to just generate current date time on the fly? 时间戳 - 只需动态生成当前日期时间即可?
delta - you must be able to programmatically get this from the mouse device somehow, but how? delta - 您必须能够以某种方式以编程方式从鼠标设备获取此信息,但如何?
The Reference Source can show you that the timestamp
is retrieved from "Environment.TickCount`. 参考源可以显示从“Environment.TickCount”中检索timestamp
。
The MSDN Library article for MSLLHOOKSTRUCT can show you that the delta
is passed as the upper word of the MSLLHOOKSTRUCT.mouseData element. MSLLOOKSTRUCT的MSDN Library文章可以向您显示delta
作为MSLLHOOKSTRUCT.mouseData元素的高位字传递。 Make sure that you declared that member as int , not as uint , so that sign extension works properly. 确保您将该成员声明为int而不是uint ,以便符号扩展正常工作。
Thus: 从而:
int timestamp = Environment.TickCount;
int delta = hookStruct.mouseData >> 16;
MouseAction(null, new MouseWheelEventArgs(mouseDev, timestamp, delta));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.