Some keys do not work in the keyup event in javascript

0

I am learning to develop games in javascript, and the truth is that when handling keyboard events I am having problems.

this is my code

const onKeyDown = (e) => {
  let key = e.keyCode? e.keyCode : e.witch
  if ( board.keyCode[key] ) { //
    binaryKey = board.keyCode[key] | binaryKey
  }
}

const onKeyUp = (e) => {
  let key = e.keyCode? e.keyCode : e.witch
  if ( binaryKey & board.keyCode[key] ) {
    binaryKey -= board.keyCode[key]
  }
}

const start = () => {
  keyElement.innerHTML = binaryKey
  window.addEventListener('keydown', onKeyDown)
  window.addEventListener('keyup', onKeyUp)
  requestAnimationFrame( main )
}

start()

then, according to the debugger, all the keys go through the keydown, particularly I am using the arrow keys.

It turns out that the keyup does not execute when the arrows are released ... in fact, I press keys like Q, W, E, R and if it works, but I also press keys like A and S and it does not work ...

Interestingly, I press 2 keys at once (example date above and arrow down) and I do keyup and one of the 2 keys is executed, although if I press them individually they do not work ...

Has it happened to you? or do you have at least some suggestions?

    
asked by Franklin'j Gil'z 12.08.2018 в 06:44
source

1 answer

0

Solved my problem. I was using window instead of document

    
answered by 24.08.2018 / 22:40
source