Handling Key Inputs Web

web key input listener

for use in a loop

const KEYS = {} const keyUpdate = e => { KEYS[e.code] = e.type === `keydown` e.preventDefault() } addEventListener(`keydown`, keyUpdate) addEventListener(`keyup`, keyUpdate)

you may use it as if( KEYS.ArrowUp )

single use

addEventListener(`keyup`, function(e){ if(e.code === 'KeyM') { // stuff e.preventDefault() } }

Reference

No known

History Jun 23, 2018