MZ VisuStella Core Engine - Game Losing Partial Keyboard/Controller Input when Opening a URL

Greetings all!

I am having an issue that I've been completely stumped on this afternoon.

What I am trying to do is create a title command button that opens up an external URL, so a player can quickly see the latest patch notes.

------------------

This can be accomplished with the following JS code using VisuStella's Core Engine:

const url = "put your URL here";

VisuMZ.openURL(url);

However, after selecting the option on the title screen that runs the above code using the confirm/select key on my keyboard, the following happens:

1. The URL opens in a new browser tab just fine.

2. I alt-tab or click to get back into the game.

3. Keyboard functionality is partially lost. I can move between options with the arrow keys or joystick, but I cannot select any options with the confirm key.

4. The only way I can regain the functionally of the confirm/select key is to click on a title screen option with my mouse (For example, clicking Load Game). After Scene_Load opens, I now have the functionality of select/confirm returned to me, and the game operates as normal.

-------------------

Does anyone know why keyboard functionality is being lost when opening an external website from the game, and how I could go about preventing this from happening / changing the above code so that this does not happen?

Note: This is not being done through a Title Picture Button, but a Title Command. The reason is because Title Picture Buttons are not selectable using gamepad input.

Note 2: If I run the following code:

SceneManager.push(Scene_Title);

Immediately after the VisuMZ code shared above, then keyboard functionality is never lost. However, this causes the title screen to reload itself when the button is selected, which doesn't look the greatest, so it's not an ideal solution. Just sharing this here in case this knowledge has any value in the discussion.
Have you tried turning off all plugins except VisuStella Core Engine to see if that helps? (Remember to save your project to apply Plugin Manager changes before testing.)

I wonder if it's related to what CasperGaming mentioned here, needing to reactivate the command window:
CasperGaming said:
JavaScript:
Scene_Title.prototype.commandOpenURL = function() {
    const url = "https://forums.rpgmakerweb.com";
    (Utils.isNwjs()) ? require('nw.gui').Shell.openExternal(url) : window.open(url);
    this._commandWindow.activate();
};
If you can still OK stuff with touch/mouse input, though, then it may well be something else...if the window were deactivated then by default (i.e. without plugins) it wouldn't be interactive at all. Still worth trying the activate line, though, just in case one of your plugins is doing something odd.

Otherwise, I would suggest SceneManager.goto(Scene_Title) instead. push stores the previous scene class, e.g. for use with pop to "go back" one scene.
@caethyril Thank you so much for the reply!

I tried adding the this._commandWindow.activate(); line by itself (throws an undefined error), but there is no crash if I add the entire function.

However the problem is still the same, if I click the button with my mouse, there's no issue whatsoever. If I use the keyboard to select it, then the web page is loaded just fine, but the confim/select button becomes disabled in-game until I click another choice with my mouse, and then the keyboard works correctly again.

Note: I also tried this in a fresh project with only the Visustella Core Engine active as you suggested, but it totally freezes just like the guy in the thread you linked said if I do that. The solutions Casper and you provided actually do not appear to help when it freezes on the fresh project either, the window is still totally frozen. So I'm not entirely sure what's going on.

It may not be totally freezing normally because much of the title screen is created using Mog_TitleCommands. I should have mentioned that in the first post for clarity's sake. There are 5 plugins i'm using for modifying the title screen:

VisuStella Core Engine
Mog_TitleCommands
Mog_TitleLayers
Ritter_TitleMovie
Ramza_PreTitleSplash_MZ


Note 2: I am so sorry, I am a baddie that did not call the function properly after implementing it. The following code works:


const url = "https://forums.rpgmakerweb.com";

Scene_Title.prototype.commandOpenURL = function () {
require('nw.gui').Shell.openExternal(url);
this._commandWindow.activate();
};

SceneManager._scene.commandOpenURL();

This code properly opens up the web page, AND stops the bug from happening where keyboard input was partially disabled. You were exactly right, it seems to be a matter of the game window becoming deactivated, which in my case was masked because of the Mog_TitleCommands plugin (except for keyboard inputs not working).

As to why Mouse inputs still worked, I have no idea why that was the case for me. In a fresh project, mouse inputs did not work either. Could be something to do with a Mog plugin, I'm not sure.

Either way, the problem is now solved for me, thank you so much 🙂.
Great! 😂

Spoiler: notes
I tried adding the this._commandWindow.activate(); line by itself (throws an undefined error)
I assume the error was something like "cannot read property activate of undefined", i.e. this._commandWindow is not defined. That would suggest this is not the scene, in which case one of these may have been a better option:
  1. Assuming this is the command window:
    JavaScript:
    VisuMZ.openURL("https://forums.rpgmakerweb.com");
    this.activate();

  2. Inelegant but should work for any scope/this:
    JavaScript:
    VisuMZ.openURL("https://forums.rpgmakerweb.com");
    SceneManager._scene._commandWindow.activate();

You were exactly right, it seems to be a matter of the game window becoming deactivated,
Just to be clear: it's the in-game title command window that gets deactivated: the core scripts deactivate a command window when one of its commands is OK'd. The game is fine, it's just that if the command window is deactivated, the player (by default) has no way to get the title scene to respond to input.

Your Open URL command has no in-game effect: it doesn't activate a different command window or go to a different scene. So it will soft-lock unless the command reactivates the window. 😮‍💨

(SceneManager.goto(Scene_Map) also works because that creates a new scene with a new command window that is initially activated/responsive. Not very efficient, though.)

As to why Mouse inputs still worked, I have no idea why that was the case for me. In a fresh project, mouse inputs did not work either. Could be something to do with a Mog plugin,
Almost certainly a plugin, yes~

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/visustella-core-engine-game-losing-partial-keyboard-controller-input-when-opening-a-url.182100/