dimanche 21 juillet 2019

Alternative to keydown event.keys condition

Obviously the code below is not ideal since one of the blocks is not even being used. However, it is difficult to imagine an inverse condition. Is there a better alternative?

if (Number(e.key)
|| e.key === '0'
|| e.key === '.'
|| e.key === 'Backspace'
|| e.key === 'ArrowLeft'
|| e.key === 'ArrowRight'
|| (e.getModifierState('Control') && 'a')
|| (e.getModifierState('Control') && 'c')
|| (e.getModifierState('Control') && 'v')){
} else {
  return false
}

Aucun commentaire:

Enregistrer un commentaire