Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Keycode for a: 65 or 97?

I'm working with javascript (on a macbook pro OSX 10.11.x, not sure if this matters) using Chrome browser. Im using the function:

window.onkeypress = function(e) {
    var key = e.keyCode ? e.keyCode : e.which;
    console.log("keypressed = " + key);
}

when i press 'a' key on my keyboard, it logs as 97, however this does not correspond to any other keyCode list i find on the internet, which states 'a' is 65.

This is the same for other keys as well, for example, 's' for me is 115, but everyone else states that 's' is 83.

Is there a dependency that i'm missing? If i fire an event assuming a == 95, will it work on other browsers?

Thanks.

like image 612
noobcoder Avatar asked Jul 27 '17 21:07

noobcoder


1 Answers

So I found that a capital A is indeed, 65.

A lowercase a is 97

Please see this chart:

enter image description here

Chart original location: http://www.asciitable.com/

like image 141
Derek Pollard Avatar answered Oct 01 '22 05:10

Derek Pollard