Not able to listen to keyboard keys at start of game

HI,

I am using this code to listen to keyboard on my main.js
onLoad: function () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
},

onKeyDown: function (event) {
console.log(event);
},

Until I click in my canvas from mouse this listener doesnot listen to keyboard events.

I guess others javascript listener are disable by cocos by default. I tried using them to simulate a click or to change focous but they didnot worked.

I have the same problem in Cocos Creator 1st basic game. They suggest to click on the canvas while running it.Even after I do that, it does not work for me. Have no clue how to fix that. Iā€™m using Windows 10.
thank you

You got to listen at your current scene. Not at main.js.

And for web, the current tab must be active (may need a tap on the page as well) in order to capture keystoke or play sound. Thats for security.

1 Like