Please avoid using this for this purpose. This is a very useful option when we want continuously change to a parameter or a command execution mainly with buttons. For example, I’m using this for triggering the bar ± command with buttons and it works great.
Now, to your question. As you most probably found out already, there is no “sleep” functionality embedded in the API. So we need to workaround this a bit.
Here’s a snippet based on my Komplete Kontrol MK2 script where I needed to implement double-clicking:
var pseudoTimer=surface.makeCustomProcessVariable("pseudoTimer")
var pseudoTimerPosition=0
var delayMS=500
//Here we trigger the timer, this can be done for example inside the mOnProcessValueChange of our first custom var
var initTime = new Date().getTime()
pseudoTimerPosition=initTime
pseudoTimer.setProcessValue(activeDevice,1)
pseudoTimer.mOnProcessValueChange=function(activeDevice,value,diff){
if(value!=0){
var currentTime=new Date().getTime()
if(currentTime<pseudoTimerPosition+delayMS){
//we retrigger here
pseudoTimer.setProcessValue(activeDevice,1)
}
else {
//trigger here whichever custom var you want
//---------------------------------------------
pseudoTimer.setProcessValue(activeDevice,0)
}
}
}
Note that most probably this function will not be of the best accuracy, but I guess it’s ok.