Windows 键盘键的 ascii 代码和功能键(F1 - F12)和其他键(如 shift、capslock、backspace、ctrl 等)的代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10832522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ascii codes for windows keyboard keys and the codes for function keys(F1 - F12) and other keys like shift,capslock,backspace,ctrl etc
提问by saplingPro
To write a keyboard related application I wanted the list of the ASCII codes of the keys that I have on my keyboard.
为了编写与键盘相关的应用程序,我需要键盘上按键的 ASCII 代码列表。
It is a windows keyboard :
这是一个 Windows 键盘:
From where can I get the codes ? It will be great if I get the codes in hexadecimal notation.
我可以从哪里获得代码?如果我得到十六进制表示法的代码,那就太好了。
回答by vertexion
This maybe too late,but I have a solution.You may get all the keyCode
values (Even for Function keys) by running (injecting) following JavaScript code into your browser's console.simply paste the following code and press enter.Then click anywhere in the page to remove the cursor from the console.
这可能为时已晚,但我有一个解决方案。您可以keyCode
通过将以下 JavaScript 代码运行(注入)到浏览器的控制台中来获取所有值(即使是功能键)。只需粘贴以下代码并按 Enter。然后单击页面以从控制台中删除光标。
Then press any key for which you want a keyCode in Hex
然后按您想要十六进制 keyCode 的任意键
Here is the code :
这是代码:
document.addEventListener("keydown", function (e) {
code = (e.keyCode);
console.log("In decimal "+e.keyCode);
var hex = code.toString(16);
console.log("In hex "+hex);
}, false);
回答by Federico Giust
There is no ascii code for the Function (F1-F12), Control, Windows or Alt keys.
Function (F1-F12)、Control、Windows 或 Alt 键没有 ASCII 代码。
If what you need is ASCII for the characters that is already defined in most languages.
如果您需要的是大多数语言中已经定义的字符的 ASCII。
Have a look at this, it also includes the hexadecimal codes
看看这个,它还包括十六进制代码