Manually trigger keypress

hello
do u know how to trigger keypress event for specific key (e.g. key “c”), so it can pass this.app.keyboard.wasPressed(…)?

Hi @Dima_Romanchuk,

I am not sure you can easily do that. You inspect how the pc.Keyboard class works here, and maybe you can manually fire a custom event:

You can even lookup more generic JavaScript solutions by googling something like this javascript trigger keypress. There are several articles coming up on that.

You can also rework your code and handle it your self, so your logic checks a more generic property instead of accessing directly the keyboard.wasPressed() method. This way you can set the property in more than one ways:

  • as a response to keyboard.wasPressed
  • as a response to a custom event you fire e.g. this.app.fire('keyboard:pressed:d')

Hope that helps.