Android device with hardware keyboard: bind to key press


#1

I have Android device with hardware keyboard. I want to bind some actions of my page to some hardware keys. How can I do it?

I have tried

document.onkeyup = (k)=>{
  console.log(`MainPage: ${k.keyCode}`);
};

but one catches all events on all pages.

Thanks in advance!