I'm breaking my head to create a function that returns the code of the key pressed. I found this:
function inicializa(){
document.addEventListener('keydown', pegaTecla);
}
function pegaTecla(){
var tecla = event.keyCode;
alert(tecla);
}
But with this function I only get the key code to appear via alert
and if I try return
on the pegaTecla()
function it does not return and it is not called every time I press any key.
How do I do when I press a key to return the key to me later?
Here is the code in its entirety . And here the end result .
It works by displaying the key code every time I press a key.