just add a event listener
window.addEventListener(event_type, event_handler, capture)
i.e.:
window.addEventListener("keypress", myFunc, false)
and you can use
function myFunc(e) {
alert(e.keyCode)
}
solved how do I connect keyboard keys to functions In a game [closed]