Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect double click in Windows Store apps?

In C++ Windows Store apps, there is an event on the main window called PointerPressed. I'm trying to find how to detect double click as opposed to single click. I don't see an equivalent event to PointerPressed that would trigger upon mouse double click.

I also checked the PointerPressed event arguments and it doesn't seems to contain information about whether or not it is a single or double click.

Its easy to perform it using the DoubleTapped property on the GestureRecognizer, but what if I don't use the gesture recognizer? Is there no way to detect a simple mouse double-click???

Thank you.

Edit: Its a pure C++ Direct3D application targetted for the Windows Store, not using XAML or any user interface thing like that.

like image 377
Deathicon Avatar asked Apr 11 '14 17:04

Deathicon


3 Answers

There is a DoubleTapped event on a UIElement. No need to use a GestureRecognizer.

like image 148
Filip Skakun Avatar answered Oct 17 '22 16:10

Filip Skakun


Make use of the Pointer.Timestamp property, and check if the time since last mouse press event received is less or equal than you double-click time.

Here is the pseudo-code:

static unsigned long long LastTimestamp = 0;
static unsigned long long DoubleClickTimeMS = 250;
if( event == mouse_down )
{
    if( (Pointer->Timestamp - LastTimestamp) / 1000 <= DoubleClickTimeMS )
    {
        //switch event for a double-click
        event = double_click;
    }
    LastTimestamp = Pointer->Timestamp;
}
like image 29
Deathicon Avatar answered Oct 17 '22 15:10

Deathicon


This is probably a bad answer as it doesn't answer the question but, conceptually, a click is an event. A doubleclick consists of two clicks which are, respectively, two events. Since a gesture consists of multiple such events, we see that a doubleclick is actually a gesture. Hence, you probably should use the gesture recognizer.

like image 1
Kristaps A. Avatar answered Oct 17 '22 16:10

Kristaps A.