Reputation: 63816
Our application supports single click and double-click events on a window which do different things. However we always get a single-click event during the double-click which causes undesired effects.
Our application is in Qt but really this is a question about underlying Windows/Mac APIs - is this a fundamental detail that the OS detects a single click as soon as you lift your finger since it can't possibly know you are going to click a second time, or can it be prevented?
If it can't be prevented, is their an accepted best practice how to handle it?
Upvotes: 0
Views: 284
Reputation: 25388
Start a timer when you get WM_LBUTTONDOWN
(or Qt equivalent). If you get WM_LBUTTONDBLCLK
(or Qt equivalent) before the timer expires, cancel the timer and execute your double-click action. Otherwise, when the timer expires, execute your single-click event.
On Windows, you can get the double-click time using GetDoubleClickTime()
.
That's about the best you can do - you can't prevent the single click message being generated in the first place on either platform.
Upvotes: 4