Is there a way to disable mouse input temporarily?

I think it’s straightforward with the title.. I want to temporarily make a button i made unclickable while i load something in- i was doing some play testing and noticed if i clicked the button a million times it would stop an event from fully completing and glitch out.

So basically just looking for a way to turn off mouse input and then turn it back on.
There are two approaches I can think of

1. Use a flag
You could use a switch (called Disable Input), then when while you load, turn the switch to ON.
Whatever event should be running can be put in the else branch or if switch is set to OFF.

Meaning, you would only trigger the event when clicking if the switch is set to OFF.

2. Overwrite the input
If you need something more robust, you could write a script call to temporarily overwrite the mouse input. (or keyboard input)
This snippet should do the job :

Disable input :
JavaScript:
Input._originalIsPressed = Input.isPressed;
TouchInput._originalIsPressed = TouchInput.isPressed;

Input.isPressed = function() { return false; };
TouchInput.isPressed = function() { return false; };

Enable input again :
JavaScript:
Input.isPressed = Input._originalIsPressed;
TouchInput.isPressed = TouchInput._originalIsPressed;

You can disable input in a script call wherever you want, then re-enable it wherever you want.
I have to do this quite a bit in my current Sudoku project.

So I pretty much use the first method outlined by @Artille above.

Technically, my button is still clickable and it still calls the Common Event it is linked to. But the difference is that the first step of the Common Event is to check to see if a Switch is On or Off. If On, it doesn't do anything and exits the Event Processing. If the Switch is Off, the Event does whatever it is supposed to do when the button is pushed.

So the player can click all they want on the button, but nothing seems to happen until the Switch gets turned off.

This has worked great for me so far.
There are two approaches I can think of

1. Use a flag
You could use a switch (called Disable Input), then when while you load, turn the switch to ON.
Whatever event should be running can be put in the else branch or if switch is set to OFF.

Meaning, you would only trigger the event when clicking if the switch is set to OFF.

2. Overwrite the input
If you need something more robust, you could write a script call to temporarily overwrite the mouse input. (or keyboard input)
This snippet should do the job :

Disable input :
JavaScript:
Input._originalIsPressed = Input.isPressed;
TouchInput._originalIsPressed = TouchInput.isPressed;

Input.isPressed = function() { return false; };
TouchInput.isPressed = function() { return false; };

Enable input again :
JavaScript:
Input.isPressed = Input._originalIsPressed;
TouchInput.isPressed = TouchInput._originalIsPressed;

You can disable input in a script call wherever you want, then re-enable it wherever you want.
thank you very much! you've saved me a great deal of stress 🙏 and also taught me a bit of javascript!

I have to do this quite a bit in my current Sudoku project.

So I pretty much use the first method outlined by @Artille above.

Technically, my button is still clickable and it still calls the Common Event it is linked to. But the difference is that the first step of the Common Event is to check to see if a Switch is On or Off. If On, it doesn't do anything and exits the Event Processing. If the Switch is Off, the Event does whatever it is supposed to do when the button is pushed.

So the player can click all they want on the button, but nothing seems to happen until the Switch gets turned off.

This has worked great for me so far.
oooh that seems like a great method! sorta relieving to know I'm not the only one with this button issue
I would be leery about overwriting the function back and forth during the game.

That's not really intended practice, and if you got into a situation where the player was able to save in an area that disabled the mouse, then came back into the game, that different code wouldn't be loaded with the save.

I would either do what @ZombieKidzRule suggested, incorporating it into the event commands; or I would outsource the code from @Artille into a proper plugin. e.g.
Code:
Input.isPressed = function(keyName) {
    if ($gameSwitches?.value(42))
        return false;

    if (this._isEscapeCompatible(keyName) && this.isPressed("escape")) {
        return true;
    } else {
        return !!this._currentState[keyName];
    }
};

TouchInput.isPressed = function() {
    if ($gameSwitches?.value(42))
        return false;

    return this._mousePressed || this._screenPressed;
};

That will disable input while switch 42 is on.
I would be leery about overwriting the function back and forth during the game.

That's not really intended practice, and if you got into a situation where the player was able to save in an area that disabled the mouse, then came back into the game, that different code wouldn't be loaded with the save.

I would either do what @ZombieKidzRule suggested, incorporating it into the event commands; or I would outsource the code from @Artille into a proper plugin. e.g.
Code:
Input.isPressed = function(keyName) {
    if ($gameSwitches?.value(42))
        return false;

    if (this._isEscapeCompatible(keyName) && this.isPressed("escape")) {
        return true;
    } else {
        return !!this._currentState[keyName];
    }
};

TouchInput.isPressed = function() {
    if ($gameSwitches?.value(42))
        return false;

    return this._mousePressed || this._screenPressed;
};

That will disable input while switch 42 is on.
noted! thanks for the heads up

just playtested
There are two approaches I can think of

1. Use a flag
You could use a switch (called Disable Input), then when while you load, turn the switch to ON.
Whatever event should be running can be put in the else branch or if switch is set to OFF.

Meaning, you would only trigger the event when clicking if the switch is set to OFF.

2. Overwrite the input
If you need something more robust, you could write a script call to temporarily overwrite the mouse input. (or keyboard input)
This snippet should do the job :

Disable input :
JavaScript:
Input._originalIsPressed = Input.isPressed;
TouchInput._originalIsPressed = TouchInput.isPressed;

Input.isPressed = function() { return false; };
TouchInput.isPressed = function() { return false; };

Enable input again :
JavaScript:
Input.isPressed = Input._originalIsPressed;
TouchInput.isPressed = TouchInput._originalIsPressed;

You can disable input in a script call wherever you want, then re-enable it wherever you want.
just playtested this, and while the code works perfectly (i am unable to move my character with mouse) it doesn't seem to work on the button? i am quite confused but maybe this is a conflict with the plugin i'm using... may have to just abandon this plugin for the buttons completely 😩
What does "it doesn't seem to work on the button" mean?

Please explain clearly what does or does not happen, and provide a screenshot of your event and any code you've added.
What does "it doesn't seem to work on the button" mean?

Please explain clearly what does or does not happen, and provide a screenshot of your event and any code you've added.

I've already gone ahead and abandoned the idea and deleted all the code... sorry 😅

i meant that the common event would still trigger when the button was clicked. it's no worries though since what i was doing (adding some sort of transition effect with animated pictures) would lag the game way too much. I might come back to this idea another day though. Thanks for the help anyways!

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-disable-mouse-input-temporarily.171935/