本文介绍了使用WH_MOUSE_LL的SetWindowsHookEx会使鼠标减速几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取有关当前进程的鼠标消息.

I am using the following code to get mouse messages on the current process.

using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
    return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}

出于某些原因,运行此代码时,鼠标会变慢几秒钟,然后恢复正常.

For some reason when this code runs the mouse get slow for several seconds and then back to normal.

有什么想法吗?
谢谢

Any ideas?
Thanks

编辑-挂钩方法

private static IntPtr mouseEvent(int nCode, IntPtr wParam, IntPtr lParam)
{
    if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
    {
        MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
        LastLeftClick = new ClickInfo { Time = DateTime.Now, X = hookStruct.pt.x, Y = hookStruct.pt.y };
    }
    return CallNextHookEx(hookID, nCode, wParam, lParam);
}

public class ClickInfo
{
    public int X { get; set; }
    public int Y { get; set; }
    public DateTime Time { get; set; }
}

推荐答案

您的钩子过程是什么样的?

What does your hook procedure look like?

如果您的进程只有一个UI线程,请改用消息过滤器: http://msdn.microsoft.com/zh-cn/library/system.windows.forms.application.addmessagefilter.aspx

If your process only has one UI thread, use a Message Filter instead:http://msdn.microsoft.com/en-us/library/system.windows.forms.application.addmessagefilter.aspx

这篇关于使用WH_MOUSE_LL的SetWindowsHookEx会使鼠标减速几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 22:39