MV Plugin that adds a state to the party members on button press

I guess I need to put my code in a function inside the BattleManager, but I have no idea how to do that.
In a battle
In the BattleManager, when
Window_PartyCommand, Window_BattleCommand, Window_ActorCommand
are opened.

Code:
/*:
* @plugindesc When E key is pressed, turn atutobattle on.
*/
(function() {  // IIFE for scope.
'use strict';  // Optional! Use strict-mode code evaluation within this IIFE.

  Input.keyMapper[69] = 'E';  // extend keymapper
if (Input.isTriggered('E')) {
$gameParty.members()[0].addState(82);
$gameParty.members()[1].addState(82);
$gameParty.members()[2].addState(82);
$gameParty.members()[3].addState(82);
};
})();
please take two steps back and describe what you want to do instead of how you want to do it.

adding asynchronous button presses inside the battleloop is a VERY bad idea for a lot of reasons.
you better find a different way to do whatever you want to achieve, and to help there we need to know the purpose behind this bad idea.
I want to be able to turn Autobattle on and off in a battle. I am using Yanfly ATB Battle System and Yanfly Actor Auto Battle AI.
By adding/removing the state #82 autobattle is turned on/off, because the state 82 has the special flag 'Auto battle'. If removing the state is too difficult, it would be ok to just add the state. In the dev console inside a battle this works:
$gameParty.members()[0].addState(82);
$gameParty.members()[1].addState(82);
$gameParty.members()[2].addState(82);
$gameParty.members()[3].addState(82);
you completely misunderstood - the problem has absolutely nothing to do with adding or removing an autobattle state.
the problem is doing so with a button press, because the button press will always by asynchron to the rest of the battle.

I would suggest you make a skill to add that state to all actors and then use a command manager type plugin to add that skill to the party menu. Then the autobattle is started when the skill autobattle is used from the party menu.

Original thread: https://forums.rpgmakerweb.com/threads/plugin-that-adds-a-state-to-the-party-members-on-button-press.149842/