Quick Press Functionality from Fader

Hello again,

I am trying to design a Fader that has 3 parts to its functionality. The first two parts are pretty standard: "drag" the fader to set a certain value, and "double tap" to reset the fader to a default value.

The third part that I would like the fader to do is to change the value of a variable whenever the fader is quickly pressed one time. I figure that anything less than 10ms would be fine, however I may tweak that number as I see fit.

You'll see in my code example that I am trying to change the variable 'Controls' to 3. This is to change the tab on a panel. I have tried several implementations, but have not been able to create the kind of functionality that I desire from the fader.

Also, all of the code that I have tried has been put into the onValue section of the fader.
Please let me know if I need to clarify more. I look forward to sharing my preset with the community soon!

var touchStartTime;
function handleTouchStart() {
  event.stopPropagation();
  touchStartTime = new Date().getTime();
  
}
function handleTouchEnd() {
  var touchEndTime = new Date().getTime();
  var touchDuration = touchEndTime - touchStartTime;
  if (touchDuration < 10) {
    var tab_index = 3;
    set('Controls', 3);
    }
  
}
this.addEventListener('touchstart', handleTouchStart);
this.addEventListener('touchend', handleTouchEnd);

You can't add event listeners with this.addEventListener, the underlying DOM element is not exposed. You need to use onTouch instead and use the locals object to store persistent values between events:

if (event.type === 'start') {
  locals.touchStartTime = Date.now()
} else {
  var delta = Date.now() - locals.touchStartTime
  if (delta < 100) { // 10ms is very short
    console.log('click')
  }
}