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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:33:22  来源:igfitidea点击:

ascii codes for windows keyboard keys and the codes for function keys(F1 - F12) and other keys like shift,capslock,backspace,ctrl etc

windowskeyboardasciihex

提问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 键盘:

enter image description here

在此处输入图片说明

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 keyCodevalues (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

看看这个,它还包括十六进制代码

ASCII Tables with Hex

带有十六进制的 ASCII 表

回答by EvgeniySharapov

What you are looking for is called Scancodehereand here. On linux there's a command showkeythat can print a SCAN code of they pressed key. On Windows, though, you may need to write a program.

您正在寻找的称为 Scancode herehere。在 linux 上有一个命令showkey可以打印他们按下的键的扫描代码。但是,在 Windows 上,您可能需要编写程序。