How to know key values in Javascript?

3

I'm developing a basic game in Javascript , and the player has some actions, I've already implemented ActionListener , but I'm having difficulty finding key values to use in ActionListener . I was picking up the values of each key by trial and error, but it is very laborious, is it possible to know the value of all keys more easily? If possible, how?

    
asked by anonymous 22.02.2017 / 12:33

2 answers

7

You can do the following with pure javascript:

document.addEventListener("keydown", function(event)
{   console.log(event);
    document.body.innerHTML = "\n<b>keyCode:</b> " + event.keyCode;
});

See working, example .

Font

    
22.02.2017 / 13:03
-1

There is an excellent jquery plugin for this: link

    
22.02.2017 / 12:49