0

The code below opens a window.

What I want:

After the NameEdit window opens for 20 seconds, automatically press the "Alt" key on the keyboard.

How do I do this? Any help is appreciated Thanks in advance

//Window Base
//The superclass of all windows within the game.
function Window_Base() {
    this.initialize.apply(this, arguments);
}

Window_Base.prototype = Object.create(Window.prototype);
Window_Base.prototype.constructor = Window_Base;

Window_Base.prototype.initialize = function(x, y, width, height) {
    Window.prototype.initialize.call(this);
    this.loadWindowskin();
    this.move(x, y, width, height);
    this.updatePadding();
    this.updateBackOpacity();
    this.updateTone();
    this.createContents();
    this._opening = false;
    this._closing = false;
    this._dimmerSprite = null;
};

W
////////////Name Window

function Window_NameEdit() {
    this.initialize.apply(this, arguments);
}

Window_NameEdit.prototype = Object.create(Window_Base.prototype);
Window_NameEdit.prototype.constructor = Window_NameEdit;

Window_NameEdit.prototype.initialize = function(actor, maxLength) {
    var width = this.windowWidth();
    var height = this.windowHeight();
    var x = (Graphics.boxWidth - width) / 2;
    var y = (Graphics.boxHeight - (height + this.fittingHeight(9) + 8)) / 2;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._actor = actor;
    this._name = actor.name().slice(0, this._maxLength);
    this._index = this._name.length;
    this._maxLength = maxLength;
    this._defaultName = this._name;
    this.deactivate();
    this.refresh();
    ImageManager.reserveFace(actor.faceName());
};
Tosps
  • 73
  • 7
  • Possible duplicate of [Is it possible to simulate key press events programmatically?](https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically) – cb64 Mar 08 '19 at 22:09
  • will it work in my case? how would I implement that in my case? and the 20 seconds? – Tosps Mar 08 '19 at 23:03
  • From most of what I've read and tried about this there are security issues related to allowing javascript to inject inputs in a browser. Ideally all key events should be tied to a user input. I tried a few different things, like `var e = $.Event("keydown", { keyCode: 70}); $("body").trigger(e);` but I haven't been successful in a browser. Can I ask what you're achieving by pressing alt? is there a way you can call this action without it being tied to a keypress (e.g. if alt is tied to a function, just call the function after 20 seconds instead of simulating the keypress) – cb64 Mar 08 '19 at 23:48
  • its a game, based on java script, that EditName window is for players to enter their names. Pressing alt will run this code "this.popScene()" in that game. That "this.popScene()" code will close that EditName window. I want it to automatically click that Alt key in 20 seconds, so it can close that EditName window in 20 seconds. – Tosps Mar 09 '19 at 01:03
  • you just have to invoke a function at the start of the game that counts for 20 seconds and then runs `this.popScene()`. If pressing alt calls the function, then you can just call the function after 20 seconds without pressing alt. You will probably want to use something like a [timeout function](https://www.w3schools.com/jsref/met_win_settimeout.asp) but there are many varieties. I will post an example as an answer in a moment. – cb64 Mar 11 '19 at 15:19

0 Answers0