Logic Machine Forum
Determine short/long pushbutton press from script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Determine short/long pushbutton press from script (/showthread.php?tid=94)



Determine short/long pushbutton press from script - edgars - 05.10.2015

In case a pushbutton doesn't have a long press feature or you need to be more flexible with long press time, here is a script which will do the job.
In the settings specify "Send 1" on rising edge, "Send 0" on falling edge. And add the following event-based script:

Code:
resolution = 0.25 -- short press check resolution
longpress = 5 -- long press time in seconds

value = event.getvalue()
if value then
  timeout = longpress / resolution

  -- wait for timeout or OFF signal
  while timeout > 0 do
     os.sleep(resolution)
     timeout = timeout - 1
 
     value = grp.getvalue(event.dst)
     if not value then
        break
     end
   end

  if timeout > 0 then
     alert('short press')
  else
     alert('long press')
  end
end



RE: Determine short/long pushbutton press from script - gjniewenhuijse - 12.12.2017

I think the second event.getvalue() needs to be replaced by grp.getvalue(event.dst), else the button release object is never received.


RE: Determine short/long pushbutton press from script - admin - 12.12.2017

True, though at the time of writing this script event.getvalue was an alias to grp.getvalue(event.dst). Later it was modified to make sure that original event value is returned to prevent race conditions.