HTML5 How do I remove keyboard focus from the canvas?

Hi juj!

Your suggestion of manual fix works! However clicking back on the canvas doesn’t remove focus (the blinking cursor and the ability to keep typing in it) from the text box, so clicking anywhere other than the canvas will remove focus (and the blinking cursor and ability to type in it) from the text box. This behavior is good enough I think for now as I don’t have any game logic bound to any of the alphanumeric keys, although I’ll have to manually do the fix each time I build for HTML5.

For anyone else following this, look in the file in your HTML5 build called projectname_asm.js (not .asm.js). There’s 35 counts of preventDefault, but the first one is the one that you want. Comment out that first preventDefault code. For me it looks like this:

...

stringToUTF8(e.locale?e.locale:"",JSEvents.keyEvent+88,32);stringToUTF8(e.char?e.char:"",JSEvents.keyEvent+120,32);HEAP32[JSEvents.keyEvent+152>>2]=e.charCode;HEAP32[JSEvents.keyEvent+156>>2]=e.keyCode;HEAP32[JSEvents.keyEvent+160>>2]=e.which;var shouldCancel=Module["dynCall_iiii"](callbackfunc,eventTypeId,JSEvents.keyEvent,userData);if(shouldCancel){/*e.preventDefault()*/}});

...

Notice at the end I added the block comment /* */ around e.preventDefault(). As a heads up, while typing in a text box, all of those keypresses are still being sent to the UE4 canvas in addition to the text box.

I hope UE4 upgrades to a newer version of Emscripten soon!

As always juj, you’re an amazing wealth of knowledge and I appreciate your time explaining these things :slight_smile: