Odd camera movement issue with fullscreen Electron app

I have an Electron app that launches with a BabylonJS scene in fullscreen mode. Once it has launched, I can mouse look in any direction using the UniversalCamera. However, I can not move forward, backward, or sideways using keyboard movement unless I first click a mouse key. After that, I can keyboard move as expected. I would like to be able to use keyboard movement without having to first click a mouse button. Unfortunately, I can not find how to do this in the documentation.

I think you need to give focus to the canvas, something like canvas.focus().

Thanks, that helped point me in the right direction. I had actually tried doing canvas.focus() last week. However, it did not work. After you mentioned canvas.focus() I tried testing that again to see if I actually had focus, which I did not. I researched it a little and found out that I need to place “tabindex=0” into the canvas tag HTML element in order for calling .focus() to work, because apparently canvas elements can not be focused by default. For anyone else using React, just add tabIndex={0} into your canvas tag in your jsx, then calling canvas.focus() will work as intended.

1 Like