Preventing Button Double Action

How can I make sure a button is not clicked twice? I would need a similar behavior to temporarily disabling a button in a web form to prevent sending a post twice.

If you have a button named myButton you could put this in the Code pane of the Properties panel and it will disable the button for 5 seconds:

changeobject "myButton", "Disabled","1"
starttimer "buttonDelay",
    "code", {changeobject "myButton", "Disabled","0"},

You can name the button as you like and change the 5 second delay to anything that works for your situation.

1 Like

In the code for the button, start with this:

if doubleclick()
... rest of code to be triggered by single click

Or, you can use info("modifiers") contains "double"

Gary’s suggestion is quite clever. However, one problem would occur if during the 5 second delay another window is brought to the front. If that happens, the button will wind up stuck in a disabled state.

If you wanted to disable a button for 5 seconds, this might be a more reliable way to do it:

if catcherror(supernow(), myButtonClickTime)>supernow()-5
    return // ignore clicks within 5 seconds
letfileglobal myButtonClickTime = supernow()
... rest of code to be triggered by normal click