Spacebar to open and close Items window

Hi, this is my first post here so I'm sorry if I mess up anything! :'-)

My problem: I want to map the Spacebar button to immediately open the Items window (no going through the default main menu, just the Items window), and also want Spacebar to close that window.

I need to do this without remapping the 'X' key, because that opens the default main menu of my game.

To summarize:
SPACEBAR = open / close Items window (I need this).
X = open / close main menu (which is already in MV).

How should I do it? I don't mind plugins or editing the code of the engine myself. I just don't know what I should edit. Any help would be very very appreciated!
Hello,
It's not that easy, because spacebar is also X and ENTER, in RPG Maker all of them are ok/confirm buttons, so first you need to do the mapping for just the spacebar, this should help.
Second, to open the item menu, it's easy, you just need to disable default menu (one of the event panels can do this), and later make a parallel common event with condition when spacebar is pressed, then do the script call: SceneManager.push(Scene_Item).
The problem is with closing it with space, because...why? How to use item if confirm/spacebar will close the menu? I don't get it and have no idea for this. @ATT_Turan gave you solution below for the exit.
You would have to add a new command to the keyMapper then also add a handler for that command to the Item scene.

So paste the below into a text editor, save as a *.js file, include as a plugin.
Code:
Input.keyMapper[32] = "space";

var origItemCreateItemWindow = Scene_Item.prototype.createItemWindow;
Scene_Item.prototype.createItemWindow = function()
{
    origItemCreateItemWindow.call(this);
    this._itemWindow.setHandler("space", this.onItemCancel.bind(this));
};
You would have to add a new command to the keyMapper then also add a handler for that command to the Item scene.

So paste the below into a text editor, save as a *.js file, include as a plugin.
Code:
Input.keyMapper[32] = "space";

var origItemCreateItemWindow = Scene_Item.prototype.createItemWindow;
Scene_Item.prototype.createItemWindow = function()
{
    origItemCreateItemWindow.call(this);
    this._itemWindow.setHandler("space", this.onItemCancel.bind(this));
};

So I made a .js file with this exact code.

1725551635212.png




Imported it as a plugin in MV.

1725551668270.png



And it doesn't do anything. No errors, no menus, nothing.

I also tried changing the key to 67 which would be "c", since I know Spacebar can be a little bit wonky, and still nothing happens.

Am I doing something wrong? Could some Yanfly plugins be conflicting with this? I'm only using YEP_MainMenuManager, YEP_CoreEngine, and YEP_MessageCore.

Oh and if there are difficulties with Spacebar, I'm totally fine using another key.
Did you also do what @fizzly told you? The only thing that code I gave you should do is cause space bar to exit out of the item menu, as you asked.
So I'm very confused with what @fizzly told me to do, but I think I've gotten that part done in another way.

I managed to make the game OPEN the Items tab using Spacebar by editing/adding some lines in the engine (ChatGPT suggested a couple of these, so it's all very iffy).

Now I imported @ATT_Turan's plugin, and it still doesn't do anything.

These are the lines I edited, so maybe you can spot some issue in the code or something I could change to get Spacebar to close the Items menu.

This is from the rpg_core.js file, where I've added the 'space' key:
JavaScript:
Input.keyMapper = {
    9: 'tab',       // tab
    13: 'ok',       // enter
    16: 'shift',    // shift
    17: 'control',  // control
    18: 'control',  // alt
    27: 'escape',   // escape
    32: 'space',    // space
    33: 'pageup',   // pageup
    34: 'pagedown', // pagedown
    37: 'left',     // left arrow
    38: 'up',       // up arrow
    39: 'right',    // right arrow
    40: 'down',     // down arrow
    45: 'escape',   // insert
    81: 'pageup',   // Q
    87: 'pagedown', // W
    88: 'escape',   // X
    90: 'ok',       // Z
    96: 'escape',   // numpad 0
    98: 'down',     // numpad 2
    100: 'left',    // numpad 4
    102: 'right',   // numpad 6
    104: 'up',      // numpad 8
    120: 'debug'    // F9
};

This is from the rpg_scenes.js file:
JavaScript:
Scene_Map.prototype.updateCallMenu = function() {
    if (this.isMenuEnabled()) {

        if (this.isMenuCalled()) {
            this.menuCalling = true;
        }

        // Check if SPACEBAR is pressed
        if (Input.isTriggered('space')) {
            this.menuCalling = false;       // Prevent default menu from opening
            this.callItemsMenu();           // Call items menu directly
        }

        if (this.menuCalling && !$gamePlayer.isMoving()) {
            this.callMenu();
        }

    } else {
        this.menuCalling = false;
    }
};

Also from rpg_scenes.js, this is a completely new method I think:
JavaScript:
// Call Items menu directly.
Scene_Map.prototype.callItemsMenu = function() {
    SoundManager.playOk();
    SceneManager.push(Scene_Item);
    Window_MenuCommand.initCommandPosition();
    $gameTemp.clearDestination();
    this._mapNameWindow.hide();
    this._waitCount = 2;
};


Got any idea what I should do next? All of this code works to open the items tab, but now I need to close it. Oh and thanks to both of you because you are being very available to help! 🙂
So I'm very confused with what @fizzly told me to do
Then you might ask for clarification/help. It's a pretty basic concept, using a parallel event to check for a key press.


|I managed to make the game OPEN the Items tab using Spacebar by editing/adding some lines in the engine
You should never do that. That's the whole point of plugins, to never edit the core scripts.

(ChatGPT suggested a couple of these, so it's all very iffy).
I think you'll have a hard time finding anyone willing to help you fix broken AI code.
I completely misread @fizzly's reply this morning, sorry. That's why I was confused. I went back, AI code is all gone (I had a backup before changing the engine code).

The only edit remaining is in the rpg_core.js file, where key 32 is still mapped to the 'space' command. I think that's the first step that @fizzly suggested doing too.

JavaScript:
Input.keyMapper = {
    9: 'tab',       // tab
    13: 'ok',       // enter
    16: 'shift',    // shift
    17: 'control',  // control
    18: 'control',  // alt
    27: 'escape',   // escape
    32: 'space',    // space
    33: 'pageup',   // pageup
    34: 'pagedown', // pagedown
    37: 'left',     // left arrow
    38: 'up',       // up arrow
    39: 'right',    // right arrow
    40: 'down',     // down arrow
    45: 'escape',   // insert
    81: 'pageup',   // Q
    87: 'pagedown', // W
    88: 'escape',   // X
    90: 'ok',       // Z
    96: 'escape',   // numpad 0
    98: 'down',     // numpad 2
    100: 'left',    // numpad 4
    102: 'right',   // numpad 6
    104: 'up',      // numpad 8
    120: 'debug'    // F9
};

As @fizzly suggested for the second step, I made the parallel event to open the Items tab directly with spacebar.

1725579203136.png


This works perfectly, totally right that it's much simpler to do it through script calls. Probably needs something to avoid triggering during dialogues, but I can add that later.



Now, I import @ATT_Turan's plugin, and it still doesn't close the Items tab.
I don't know what to do. >_>

Original thread: https://forums.rpgmakerweb.com/threads/spacebar-to-open-and-close-items-window.171687/