Sign in to follow this  
leiavoia

Implementing "Double Click"?

Recommended Posts

In programming my GUI, I've come across a little gotcha. I can implement pretty much everything i need, but i was wondering how other people detect a "double click" event. Theoretically, if you click the mouse once it sends a "button click" signal. If you detect another click within a certain time frame, you can call it a double click and send a double click message. But you can't take back the single click message you already sent. The alternative would be to NOT send a single click message within a certain time frame of the first click, just in case a second click comes down the pipe in short order. Once the double click wait time has expired without a second click, send the single click event. However, doing this puts a delayed reaction on all single clicks (and most clicks are singles anyway). Any ideas on how to do this nicely? I'm currently not in need of any double clicking so it's not a big issue. i was mostly just curious.

Share this post


Link to post
Share on other sites
I'm pretty sure most GUIs send the single-click message the first time, and then the double-click message if the button is clicked again with a short period of time. I don't see any other way of handling it, unless you want to delay the single-click, which would be annoying to most users.

Share this post


Link to post
Share on other sites
It depends what API you're using and what operating system you're in, I suppose. If you're in Windows and .NET, it's easy to capture.

Quote:
Original post by Zipster
I'm pretty sure most GUIs send the single-click message the first time, and then the double-click message if the button is clicked again with a short period of time. I don't see any other way of handling it, unless you want to delay the single-click, which would be annoying to most users.

Actually, I believe the events are raised in WinForms completely separately--if you double click, the single click event will never get raised. This means that there must be some delay, but people don't even notice it.

Share this post


Link to post
Share on other sites
No, you definitely get the single-click event 1st in windows then the double-click event. Just look at the behavior when you click on a desktop icon. 1st click highlights the icon, 2nd click executes it. It has to be this way b/c you can turn the "double-click" speed waaaaaay down so it's like 1 second between clicks still counts as a double click. In that slowed down case you'll notice that you still get instantaneous single-click behavior from the GUI.

-me

Share this post


Link to post
Share on other sites
In Win32 code, you must create your window class with the CS_DBLCLKS style in order for Windows to issue double click messages to your window. Without that style, the double clicks are not reported to the window.

Share this post


Link to post
Share on other sites
I'm actually doing the double-click routines from scratch. I'm not using a prebuilt GUI system. I'm using SDL for input. It would appear, though, that double-clicking usually sends a single click event message first, so it ends up getting both. You would just have to be carefull not to have two very different events wired up to single/double clicks (firing your gun and jumping for instance)

Share this post


Link to post
Share on other sites
I haven't tried this myself, but if you're going to do it manually...

What I would do is have the input system record a single-click, then wait for a certain length of time (however long it takes for a user to double click), and if it detects another click within that length of time, it sends a double-click message to the game logic. If it doesn't, then it sends a single-click message.

Of course, this introduces a bit of mouse latency, so you can skip the waiting bit and just send a single-click message right away, and then just screen for double-clicks afterward...

Share this post


Link to post
Share on other sites
Hint: the feel will be a lot less awkward if you do what pretty much all guis do, a click happens when RELEASE the mouse over the same element it was pressed over, a double click happens when you press it down again within a certain amount of time. If that time is set small enough you can delay a single click. You can also start the timer when you press it the first time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this