MV Open and close inventory with "Tab"

First post, sorry if this is the wrong spot. I've been trying to find a way to make it so if I press the Tab key it will open my inventory, and if I press it a second time it will then close. I found many ways to open the inventory with the Tab key via plugins and scripts, but never one that would then let me close it using the same key. This issue has been driving me up the wall for a while, so any help is really appreciated.
I found many ways to open the inventory with the Tab key via plugins and scripts, but never one that would then let me close it using the same key
if you already have a plugin that lets tab open the inventory directly from the map, then try this
Code:
(() => {
    const listAlias = Window_ItemList.prototype.processHandling;
    Window_ItemList.prototype.processHandling = function() {
        listAlias.call(this);
        if (this.isOpenAndActive() && Input.isRepeated('tab')) {
            SceneManager._scene.popScene();
            SoundManager.playCancel();
        }
    }

    const catAlias = Window_ItemCategory.prototype.processHandling;
    Window_ItemCategory.prototype.processHandling = function() {
        catAlias.call(this);
        if (this.isOpenAndActive() && Input.isRepeated('tab')) {
            SceneManager._scene.popScene();
            SoundManager.playCancel();
        }
    }
})();
if you already have a plugin that lets tab open the inventory directly from the map, then try this
Code:
(() => {
    const listAlias = Window_ItemList.prototype.processHandling;
    Window_ItemList.prototype.processHandling = function() {
        listAlias.call(this);
        if (this.isOpenAndActive() && Input.isRepeated('tab')) {
            SceneManager._scene.popScene();
        }
    }

    const catAlias = Window_ItemCategory.prototype.processHandling;
    Window_ItemCategory.prototype.processHandling = function() {
        catAlias.call(this);
        if (this.isOpenAndActive() && Input.isRepeated('tab')) {
            SceneManager._scene.popScene();
        }
    }
})();
Sorry, I have a very bare bones understanding of javascript, so I'm not exactly sure exactly where to place this code. Also just to clarify, the method I'm currently using is the MK_Hotkeys plugin from this thread https://forums.rpgmakerweb.com/index.php?threads/open-and-close-inventory-easily-with-q.179416/
I have a very bare bones understanding of javascript, so I'm not exactly sure exactly where to place this code
open up a text editor like notepad, copy the code above, save it as a .js file, and add it to your project as you would any plugin.

Also just to clarify, the method I'm currently using is the MK_Hotkeys plugin from this thread
it should work then if youre pushing the scene from the map. the issue would have been if your plugin didnt directly open the item scene and faked it by doing something like opening the menu and triggering the item option from there instead.
open up a text editor like notepad, copy the code above, save it as a .js file, and add it to your project as you would any plugin.


it should work then if youre pushing the scene from the map. the issue would have been if your plugin didnt directly open the item scene and faked it by doing something like opening the menu and triggering the item option from there instead.
Okay it wasn't working at first but I figured out the problem, MK_Hotkeys was reopening the inventory the moment it was being closed so it looked like nothing was happening, I switched back to some script edits I found in a Reddit thread and now it finally works!!! Thank you so much!!! As one small final request, how would I make your plugin play a sound effect when backing out of the inventory menu?
just need to add a command to play a sound to the sections that happen when tab is pressed. ive gone back and edited in the cancel sound effect into the code from before
just need to add a command to play a sound to the sections that happen when tab is pressed. ive gone back and edited in the cancel sound effect into the code from before
Once again, thank you so much!!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/open-and-close-inventory-with-tab.182247/