/// <summary> /// Handler for holding the button. /// </summary> private void StartHoldingHandler(object?state) { _holdingTimer?.Dispose(); _holdingTimer = null; _holdingState = ButtonHoldingState.Started; Holding?.Invoke(this, new ButtonHoldingEventArgs { HoldingState = ButtonHoldingState.Started }); }
/// <summary> /// Handler for releasing the button. /// </summary> protected void HandleButtonReleased() { if (_debounceTime.Ticks > 0 && !IsPressed) { return; } _debounceStartTicks = DateTime.UtcNow.Ticks; _holdingTimer?.Dispose(); _holdingTimer = null; IsPressed = false; ButtonUp?.Invoke(this, new EventArgs()); Press?.Invoke(this, new EventArgs()); if (IsHoldingEnabled && _holdingState == ButtonHoldingState.Started) { _holdingState = ButtonHoldingState.Completed; Holding?.Invoke(this, new ButtonHoldingEventArgs { HoldingState = ButtonHoldingState.Completed }); } if (IsDoublePressEnabled) { if (_lastPress == DateTime.MinValue.Ticks) { _lastPress = DateTime.UtcNow.Ticks; } else { if (DateTime.UtcNow.Ticks - _lastPress <= _doublePressTicks) { DoublePress?.Invoke(this, new EventArgs()); } _lastPress = DateTime.MinValue.Ticks; } } }