At first, there was no response when the mouse clicked into canvas and then operated with the keyboard

When I first entered the game, the keyboard keys did not respond. I need to move the cursor out of the canvas, click (red arrow), and then click back into the canvas (green arrow). The keyboard keys can be triggered.
At first, when the mouse clicks into the canvas and then operates with the keyboard, there is no response. You need to click elsewhere and then click back into the canvas to trigger the keyboard event

There can be multiple reasons for this. Do you capture the keyboard events on the bjs rendering canvas? Can you provide a full example?

You can try this link below, but to download, please

1 Like

Ok, got the repo. I will get back to you later. I need to finish something.

OK, OK, thank you. Please reply to me when you are free. Please.

I made these changes:

  1. upgraded BabylonJS to version 5
  2. changed index.html - added the canvas directly to the html and made it to cover the whole screen
  3. removed the canvas creation from app.ts

You can download it from here:

Copy over your files. Run npm i. Enjoy!

r :vulcan_salute:


thank you very much!!
I didn’t upgrade babylongjs, I just changed the index HTML - add the canvas directly to HTML and make it cover the whole screen. Canvas starts from app The creation is deleted in TS, which solves the problem that keyboard events are not triggered at the beginning.
Can you tell me why you can create HTML directly without this problem? I wonder why.

:clap: :clap: :clap: :smiley: :smiley:

1 Like

I think the event binding occured earlier than the canvas was created dynamically or something like that. I didn’t dig deeper, you know, I’ve got a lot to do… :frowning:

You are welcome buddy!


OK, OK, thank you very much!!!