检测同时左,右鼠标点击? [英] Detect both left and right mouse click at the same time?

查看:205
本文介绍了检测同时左,右鼠标点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重塑扫雷艇(从XP)和东西,他们已列入的是,如果你点击与许多标志一个数字作为它与鼠标左右键的同时数,它揭示了所有其他隐藏平铺窗口围绕该号码。

I'm remaking windows Minesweeper (from XP) and something they had included was that if you click a number with as many flags as it's number with the left and right mouse button at the same time, it reveals every other hidden tile around that number.

我有一个很难当两个左,右鼠标按钮的确​​切同时按下告诉...我使用的是对布尔变量,一个用于与onmousedown事件和OnMouseUp事件的每个按钮,但如果2个按钮被点击的确切的同一时间(或非常接近),那么只有一个MouseDown事件熄灭,其他不...如果你点击按住其中一个按钮,然后单击并按住对方,代码工作虽然。

I'm having a hard time telling when both the Left and Right mouse buttons are pressed at the exact same time... I'm using a pair of bools, one for each button with the OnMouseDown and OnMouseUp events but if the 2 buttons are clicked at the exact same time (or really close), then only one MouseDown event goes off and the other does not... If you click and hold one of the buttons then click and hold the other, the code works though.

有没有更好的方法来检测这种双反点击?

Is there a better way to detect this kind of "dual" click?

编辑:

好吧,小故事,为什么我搞砸这件事(它的工作一直以来)。

Alright, small story for why I messed this up (it worked all along).

我有一个的MacBook Pro运行Windows 7对于那些你不知道是谁,MacBook Pro的有一个鼠标按键单栏通常左点击,但如果你把两个手指向下是正确的点击,所以你不能两者都做(没办法中间点击)。所以我建立我的应用程序,并把它发送给我的朋友,他告诉我,这是行不通的,所以我张贴了这个问题。我终于决定尝试一下我的其他笔记本电脑,戴尔XPS与2鼠标按钮......一旦它在那里工作我通过它传递给其他的朋友,他们证实了它的工作。我不知道我的第一个朋友是如何搞砸了,但故事的寓意是什么都不买苹果。至少这是我的道德。

I have a macbook pro running Windows 7. For those of you who don't know, the macbook pro has a single bar for a mouse button that normally left clicks, but if you place 2 fingers down it right clicks, so you can't do both (and no way to middle click). So I was building my app and sending it to my friend, he was telling me it wasn't working, so I posted this question. I finally decided to try it on my other laptop, a Dell XPS with 2 mouse buttons... Once it worked there I passed it along to other friends and they confirmed it worked. I don't know how my first friend messed it up, but moral of the story is don't buy anything Apple. At least that's the moral I got.

推荐答案

创建左一类布尔变量和右键默认为false。当鼠标按下事件触发设置变量设置为true,并检查是否都是真实的。当鼠标向上火灾变量设置为false

Create a class boolean variable for the left and right button defaulted to false. When the mouse down event fires set the variable to true and check if both are true. When the mouse up fires set the variable to false.

    public bool m_right = false;
    public bool m_left = false;

    private void MainForm_MouseDown(object sender, MouseEventArgs e)
    {
        m_objGraphics.Clear(SystemColors.Control);

        if (e.Button == MouseButtons.Left)
            m_left = true;
        if (e.Button == MouseButtons.Right)
            m_right = true;

        if (m_left == false || m_right == false) return;
        //do something here
    }

    private void MainForm_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
            m_left = false;
        if (e.Button == MouseButtons.Right)
            m_right = false;
     }

这篇关于检测同时左,右鼠标点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆