I've been looking around and it seems that String.fromCharCode()
is the method I was looking for, however, when trying to convert a keyCode using String.fromCharCode()
the results are completely off
For example:
let foo = 40;
console.log(String.fromCharCode(foo))
//Output "("
When at https://keycode.info 40
is ArrowDown
, and also is ArrowDown
when logging event.key
as such:
function logKey(event) {
console.log(event.key);
console.log("Key: " + event.keyCode)
}
document.addEventListener("keydown", logKey)
What is happening here?