score:0

Accepted answer

can you not hardcode it onto your div element?
use this question as reference if you can.

if you can't harcode it maybe try this:

    document.queryselector('#yourdiv').addeventlistener('keydown', function (event) {
      console.log(event.key) //change this to whatever you want it to do
    })

then in your html give your div a tabindex="0" property.

the tabindex property:

tabindex="0" allows a non-form/link/object element to be placed in the default navigation order, allowing any element to be focusable and trigger interaction.

more info here


Related Query

More Query from same tag