ackh
ackh

Reputation: 2052

How to query the double-tap duration time from Windows UWP apps?

In my Windows UWP app I have a component that reacts on double-taps. I've implemented this by reacting to the PointerPressed event of the CoreIndependentInputSource. In the event handler I got the following code:

if((e->CurrentPoint->Timestamp - _lastTimestamp) < _doubleClickDuration)
{
  Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
  {
    // Do whatever needs to be done on double-taps
  }));
}

_lastTimestamp = e->CurrentPoint->Timestamp;

_doubleClickDuration is the variable that defines the duration of the double-tap.

The code works as expected but the problem that I'm facing is that I need to set _doubleClickDuration to a "reasonable" value. What is reasonable for one person might not be for another which is why Windows lets you configure the duration of the double-tap in the Control Panel.

There is a Windows API function named GetDoubleClickTime that seems to return the value configured in Windows. However, that function is marked as "[desktop apps only]" which means I cannot call that function from a Windows UWP app.

What is the Windows UWP equivalent to that function or how would I figure out what the configured duration time of a double-tap is?

Upvotes: 1

Views: 266

Answers (1)

ackh
ackh

Reputation: 2052

As stated in the comments below my question, the double-tap duration of Windows can be accessed via UISettings. First, an object of object of that class must be constructed. I do this as a class member using the following line of code:

Windows::UI::ViewManagement::UISettings _uiSettings;

The double-tap duration, which I think is the same as the double-click duration, can be accessed via property DoubleClickTime of the _uiSettings object. It returns an unsigned int that expresses the double-tap duration in milliseconds.

Because the line e->CurrentPoint->Timestamp of the code in my question returns the time in microseconds, it is necessary to multiply DoubleClickTime with 1000 in order to be able to compare those values.

So, the full code now looks like this:

if((e->CurrentPoint->Timestamp - _lastTimestamp) < (_uiSettings.DoubleClickTime * 1000))
{
  Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
  {
    // Do whatever needs to be done on double-taps
  }));
}

_lastTimestamp = e->CurrentPoint->Timestamp;

Changing the double-tap duration in the Mouse Settings of Windows' Control Panel will also change the return value of the DoubleClickTime property.

Mouse Settings

Note that changing the value that way changes the value of DoubleClickSpeed in the registry key HKEY_CURRENT_USER\Control Panel\Mouse. The default value there is 500 (milliseconds).

enter image description here

Upvotes: 1

Related Questions