What are the JavaScript KeyCodes? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-26 06:58:48

问题


What keycodes are available for JavaScript? If they\'re not the same for all browsers, please list the keycodes for each browser.


回答1:


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.




回答2:


Followed @pimvdb's advice, and created my own:

http://daniel-hug.github.io/characters/

Be patient, as it takes a few seconds to generate an element for each of the 65536 characters that have a JavaScript keycode.




回答3:


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.




回答4:


http://keycodes.atjayjo.com/

This app is just awesome. It is essentially a virtual keyboard that immediately shows you the keycode pressed on a standard US keyboard.




回答5:


Here is a complete list--I believe: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes




回答6:


Here are some useful links:

  • http://www.toolcase.org/charset.php?charset=UTF-8&min=0&per=512&search=

The 2nd column is the keyCode and the html column shows how it will displayed. You can test it here.

  • http://en.wikipedia.org/wiki/UTF-8



回答7:


One possible answer will be given when you run this snippet.

document.write('<table>')
for (var i = 0; i < 250; i++) {
  document.write('<tr><td>' + i + '</td><td>' + String.fromCharCode(i) + '</td></tr>')
}
document.write('</table>')
td {
  border: solid 1px;
  padding: 1px 12px;
  text-align: right;
}
table {
  border-collapse: collapse;
}
* {
  font-family: monospace;
  font-size: 1.1em;
}


来源:https://stackoverflow.com/questions/5603195/what-are-the-javascript-keycodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!