How to get keycode in an input event

Here is the code:

let el = document.querySelector("input[name='test']")

el.addEventListener('input', (e)=>{
 console.log(e.keyCode)
})

I’m only grabbing the actual input element. Is there a way to grab the element and the event keycode?
Here is the pen:

e.target is the element that triggered the event.

Yes, but how can I know what keys are pressed?

Hi @Chronzam, input is not an actual keyboard event so you’ll have to listen to keydown, keyup or keypress in order to get the key; also note that keyCode is deprecated, better use either key or code.

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.