拦截和禁用全局鼠标事件

发布于 2024-12-18 17:56:33 字数 176 浏览 1 评论 0原文

我的鼠标有问题。当我只单击一次时,它时不时会双击。我知道这是鼠标的问题,我已经联系了制造商,仍在等待答复。但与此同时,我想知道是否有一种方法可以找出在很短的时间内(可能是 1-10 毫秒)内单击鼠标左键两次的时间,并禁用第二次单击。

我主要知道如何使用钩子,所以这不是问题,我的主要问题是如何阻止事件发生(如果可能的话)。

I have a problem with my mouse. Every now and then it will double click when I only single click. I know this is a problem with the mouse, and I've contacted the manufacturer, still waiting for a reply. But in the meantime I was wondering if there was a way that I could find out when the left mouse button had been clicked twice within a very short period (probably 1-10 milliseconds) of time, and disable the second click.

I mostly know how to use hooks, so that's not the problem, my main question is how to stop an event from happening, if that's possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光匆匆的小流年 2024-12-25 17:56:33

关于如何阻止鼠标消息被处理的信息在MSDN中的“LowLevelMouseProc回调函数”的文档中:
http://msdn.microsoft。 com/en-us/library/windows/desktop/ms644986(v=vs.85).aspx
具体来说,它说:“如果钩子过程处理了消息,它可能会返回一个非零值,以防止系统将消息传递给钩子链的其余部分或目标窗口过程。”所以,如果你了解 windows hooks,你就知道如何去做。

编辑:实际上,现在我想得更多了,你不想丢弃任何事件。您只想将双击事件转换为另一个左键按下事件。我相信您可以在钩子处理程序中完成此操作,并且它会起作用。你尝试过吗?

The information on how to prevent the mouse message from being processed is in the documentation of the "LowLevelMouseProc callback function" in MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986(v=vs.85).aspx
Specifically, it says: "If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure." So, if you know about windows hooks, you know how to do it.

EDIT: Actually, now that I think more about it, you don't want to discard any event. You simply want to transform the doubleclick event into just another left-button-down event. I believe you can do it from within the hook handler, and it will work. Have you tried it?

少女七分熟 2024-12-25 17:56:33

在 C# 的 WinForms 中,您编写一个涉及鼠标接收 MouseEventArgs 对象的事件处理程序。在其中,您可以访问某些信息,例如单击的次数。

protected void RowClicked(object sender, MouseEventArgs evt)
{
    // Trigger it when the mouse was clicked only once
    if( evt.Button.Clicks == 1 ) {
        // ... more things ...
    }

    return;
}

其他 GUI 库还有其他可能性。也就是说,您的问题与 GUI 库无关。您必须在操作系统的配置选项中更改鼠标的灵敏度。例如,在 Windows 的控制面板中,您可以更改一次单击与另一次单击之间需要经过多长时间才能被视为双击。在lUbuntu中,你可以做同样的事情,在系统菜单>>首选项>>键盘和鼠标。

In C#'s WinForms, you write an event handler involving the mouse receiving a MouseEventArgs object. Inside it, you can access certain info such as the number of times it was clicked, for example.

protected void RowClicked(object sender, MouseEventArgs evt)
{
    // Trigger it when the mouse was clicked only once
    if( evt.Button.Clicks == 1 ) {
        // ... more things ...
    }

    return;
}

Other GUI libraries have other possibilities. That said, your problem has nothing to do with GUI libraries. You have to change the sensitivity of your mouse, in the configuration options of your operating system. For example, in the Windows' control panel, you can change how much time has to pass between a click and another one to be considered a doble-click. In lUbuntu, you can do the very same, in System menu >> Preferences >> Keyboard and Mouse.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文