timer.stopTimer element

getTimer(id).stop() (since version 1.1)

Stops the timer early. Nothing happens if the timer has already elapsed.

When timers are stopped early, the script proceeds in the same way as if they had elapsed on their own: any callback command associated to the timer is executed and any wait command on the timer is resolved.

newText("instructions", "Wait 3s or press Space")
    .print()
,
newTimer("delay", 3000)
    .start()
,
newKey("stop early", " ")
    .settings.callback( getTimer("delay").stop() )
,
getTimer("delay")
    .wait()

Will wait 3 seconds before proceeding, or will proceed if the space bar is pressed in the meantime.