problem with input.isTriggered/isPressed?

I'm trying to make a status window in my game that pops up when the player press TAB.
My code is as follows:

Code:
var $tab=undefined
var keyconfig_alias = Scene_Map.prototype.updateScene;
   Scene_Map.prototype.updateScene = function() {
        keyconfig_alias.call(this);
        if((Input.isTriggered('tab') || Input.isPressed('tab')) && !$tab){
        $tab = new Bitmap(250, 200);
        $tab.fillAll("black")
        $tabs = new Sprite($tab);
        $tabs.x=5
        $tabs.y=5
        $tabs.alpha=0.5
        $tab.fontSize=22
        $tab.drawText("Name:"+localStorage.myname+"   ID:"+(playerid-100),9,140,200,0.5,"left")
        $tab.drawText("Enemies Killed:"+$enemieskilled,9,165,200,0.5,"left")
        SceneManager._scene.addChild($tabs);
    }else if(!Input.isPressed('tab') && !Input.isTriggered('tab') && $tab){
        $tab.clear()
        $tab=undefined
    }
}

It works mostly fine, but there are a few problems: When I first press tab, it doesn't show anything. If I hold tab, it takes a second to show at first. If I alt tab to another window then back again, both problems happen again.

Anyone has any guesses as to why?
Don't know, but maybe it is something related to the button press. Instead of making the tab disappear when the player is not pressing the button, why don't you try a fade after a few seconds? Or even, a toggle function: player press or trigger Tab and the window appears. Player press again, the window disappears.

I already have strange issues with custom inputs too.
Also, I think you can try in the update function, instead of update scene.

Well, that is just hints. I don't know exactly the problem
It might be due to you messing up 'istriggered' and 'ispressed'.
There is a reason why there are two different functions like that, and it has to do with how the hardware of the keyboard works internally.
I can't tell you which one is which from the javascript side, I only know what the difference is on the hardware side.

The hardware has no register "key x is down" at all, it only gives two signals "key x goes down" and "key x is released", and it is the duty of the software/system to remember the state of each key. That is why it was possible before Windows and in early Windows versions to get your keys "stuck", especially if a DOS-game tried to accellerate everything by directly reading the keyboard on those old and slow computers.

One of the two functions returns true is the "key is going down" signal was received but not the "key is released". The other function remembers and returns true if both signals "key is going down" AND "key is released" have been given for the same key - which includes a wait between the two as the player has to press and release the key.

And with this explanation it should be obvious that they can't be both true at the same time, and that one of them already contains the requirement to have the key released.
Using both functions in the same condition will often mess up your timing as the second function specifically waits for the release of the key if it is used to scan the keyboard.

If my assumption is correct, you'll need to use only the function that scans for "key goes down" without calling the function that waits for a full keypress and release, as you want the screen to only show while the tab is pressed.
But as said I don't know enough of javascript to know if my knowledge on the hardware has been transfered to the commands that way and which one is which.
@Andar Nope, I don't think that's not the issue. The same thing happens to me. For some reason, the first time I'm trying to press Tab it doesn't work. I assume it probably has something to do with RPG Maker already having some assigned function for the Tab key.
And it becomes a serious issue cause it happens always when you use the "Transfer Player" command.
@Andar Nope, I don't think that's not the issue. The same thing happens to me. For some reason, the first time I'm trying to press Tab it doesn't work. I assume it probably has something to do with RPG Maker already having some assigned function for the Tab key.
And it becomes a serious issue cause it happens always when you use the "Transfer Player" command.
I came back to this recently(I'm still having problems with it) and I found the source of the problem: When the game loses focus, all inputs are cleared (because of the function Input._onLostFocus in rpg_core.js)

This is a good thing, since if you remove that and you are walking then minimize the game your character walks forever, but it still breaks my script. Anyone has any idea on how to work around this?


also what Andar said is wrong. "||" equals to "OR" not "AND", so as long as one of them is true this should be triggered.
The issue seems to only be on the TAB key. Changing it to any other "fixes it".

Anyone has any idea why? I would like to keep TAB as the default for what I'm making.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-input-istriggered-ispressed.121291/