I have some code for a WPF trigger that checks for double-clicks:
private void HandleButtonUp(object sender, MouseButtonEventArgs mouseEventArgs)
{
if (mouseEventArgs.ChangedButton == MouseButton.Left &&
(mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime)
{
this.InvokeActions(mouseEventArgs);
_lastClick = 0; // Require 2 clicks again
}
else
_lastClick = mouseEventArgs.Timestamp;
}
This has worked well until now. But today, suddenly single-clicks are invoking the action. When I checked the code, I have found that the timestamp value is negative which results in it always being less than the SystemInfo.DoubleClickTime (500 is what mine is set to).
Is this normal? Why has this suddenly changed?
The InputEventArgs.Timestamp
property behaves like Environment.TickCount
, where you can find the following Remarks:
The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Consequently, if the system runs continuously, TickCount will increment from zero to Int32.MaxValue for approximately 24.9 days, then jump to Int32.MinValue, which is a negative number, then increment back to zero during the next 24.9 days.
TickCount is different from the Ticks property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am.
Use the DateTime.Now property to obtain the current local date and time on this computer.
Ignoring the rare case when the jump occurs (after 24.9 days, then every 49.7 days), you may check like this:
Math.Abs(mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With