What keycodes are available for JavaScript? If they're not the same for all browsers, please list the keycodes for each browser.
This question is related to
javascript
keycode
This app is just awesome. It is essentially a virtual keyboard that immediately shows you the keycode pressed on a standard US keyboard.
keyCodes are different from the ASCII values. For a complete keyCode reference, see http://unixpapa.com/js/key.html
For example, Numpad numbers have keyCodes 96 - 105, which corresponds to the beginning of lowercase alphabet in ASCII. This could lead to problems in validating numeric input.
One possible answer will be given when you run this snippet.
document.write('<table>')_x000D_
for (var i = 0; i < 250; i++) {_x000D_
document.write('<tr><td>' + i + '</td><td>' + String.fromCharCode(i) + '</td></tr>')_x000D_
}_x000D_
document.write('</table>')
_x000D_
td {_x000D_
border: solid 1px;_x000D_
padding: 1px 12px;_x000D_
text-align: right;_x000D_
}_x000D_
table {_x000D_
border-collapse: collapse;_x000D_
}_x000D_
* {_x000D_
font-family: monospace;_x000D_
font-size: 1.1em;_x000D_
}
_x000D_
Here are some useful links:
The 2nd column is the keyCode and the html column shows how it will displayed. You can test it here.
I needed something like this for a game's control configuration UI, so I compiled a list for the standard US keyboard layout keycodes and mapped them to their respective key names.
Here's a fiddle that contains a map for code -> name and visi versa: http://jsfiddle.net/vWx8V/
If you want to support other key layouts you'll need to modify these maps to accommodate for them separately.
That is unless you were looking for a list of keycode values that included the control characters and other special values that are not (or are rarely) possible to input using a keyboard and may be outside of the scope of the keydown
/keypress
/keyup
events of Javascript. Many of them are control characters or special characters like null
(\0
) and you most likely won't need them.
Notice that the number of keys on a full keyboard is less than many of the keycode values.
Here is a complete list--I believe: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
Source: Stackoverflow.com