JavaScript simulate key input for behaviors


#1

I have a PlatformerObject on my player and I want to use JavaScript to simulate a key press. Like this:


I have read the documentation on RuntimeBehaviors as well as RuntimeObjects and have come up empty handed.
Is there anything that I am missing?
Any incite would be greatly appreciated.


#2

For the condition, you can search “pressed” in the documentation.
image
For the action, it’s based on an extension, so it’s not on that page, you need to go to the github and search for platformer and jump.
I see a “this._jumping = false;”, I guess it will jump if you set it to true.

I don’t know js, so all this is an educated guess at best. :sweat_smile:


#3

Thanks!

I just needed to set the _jumpKey of the PlatformerObject behavior to true.

if(runtimeScene._runtimeGame.getInputManager().isKeyPressed(32))// Spacebar
    playerBehavior["_jumpKey"] = true;
}

#4

Is there a way to simulate a left arrow (for example) press on the page? I searched a bit, and only found .click(), but that is a mouse click.
9Apps Showbox