jeudi 26 novembre 2015

Javascript clicking a button removes key listener?

I am currently using an EventListener on 'keydown' to move objects about on the screen. My problem is that I have buttons on the page at the same time. I have found that after clicking buttons, keys won't trigger an event again until I click in a blank area of the screen.

My problem is basically that I need to click on the screen before keys will trigger events. I was wondering if there is a way to automatically give the EventListener focus (if that makes sense) so that I can switch between button input and key input smoothly without having to click anywhere on the screen again after every button click?

I'm looking for a similar fix in the way that text boxes can 'request focus' on a webpage so that you can type automatically without having to click in the text box.




Aucun commentaire:

Enregistrer un commentaire