disable double click?

Nov 1, 2011 at 10:33 PM

 

I know how to disable say right clicks:

 

        void _mouseHookListener_MouseDownExt(object sender, MouseEventExtArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Debug.WriteLine("Right Click Disabled");
                e.Handled = true;
            }
        }


But how would you disable double clicks, the MouseEventArgs do not have the Handled property?:


        void _mouseHookListener_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("Double Click");
            // IFREQ: How to disable double click?
        }

 

Thanks for amazing work!

Nov 2, 2011 at 1:31 AM

Unfortunately, it's not built into the library due to the differences between Local Hooks and Global Hooks.

To implement the functionality, modify this code to suit your needs.

private MouseHookListener m_mouseHookListener;
private int m_timestamp = 0;

[DllImport("user32")]
private static extern int GetDoubleClickTime();

private void Form1_Load(object sender, EventArgs e)
{
    m_mouseHookListener = new MouseHookListener(new GlobalHooker());
    m_mouseHookListener.Enabled = true;
    m_mouseHookListener.MouseDownExt += m_mouseHookListener_MouseDownExt;
}

void m_mouseHookListener_MouseDownExt(object sender, MouseEventExtArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        if ((e.Timestamp - m_timestamp) < GetDoubleClickTime())
        {
            e.Handled = true;
        }
        m_timestamp = e.Timestamp;
    }
}

Hope that helps.

Nov 2, 2011 at 10:44 AM

Thanks a lot!!! Maybe would even make sense to stick this code in the library itself and pass MouseEventExtArgs for DoubleClick as well - I havent thought it through in terms of any other requirements this move might have though :)

Nov 2, 2011 at 12:35 PM

Thanks for the suggestion.