12
I’m breaking my head to create a function that returns the code of the pressed key. I found this:
function inicializa(){
document.addEventListener('keydown', pegaTecla);
}
function pegaTecla(){
var tecla = event.keyCode;
alert(tecla);
}
But with this function I can only get key code to be displayed via alert
and if I try return
in function pegaTecla()
does not return and is not called every time q press some key.
How do I stop when I press a key the function returns me that key for later it is tested?
Here’s the code in full.
And here the final result.
It works by displaying the key code every time I press a key.
Ah, now that I saw that I needed the code (and not the letter). Anyway, here is the example :)
– Renan Gomes
and how do I execute a function so q pressed a key ? pq qro create a routine in which a key is displayed on the screen and the user has to press it. to make the function perform a comparator with difficulty so that the user presses the -key
– Leandro Macedo
@Leandromacedo added an example.
– Renan Gomes
Thank you very much I managed to do what you need :)
– Leandro Macedo