上下左右的ascii值是多少?

发布于 2024-09-02 00:10:52 字数 33 浏览 6 评论 0原文

箭头键的 ASCII 值是多少? (上/下/左/右)

What are the ASCII values of the arrow keys? (up/down/left/right)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

稳稳的幸福 2024-09-09 00:10:52

简而言之:

向左箭头:37
向上箭头:38
向右箭头:39
向下箭头:40

In short:

left arrow: 37
up arrow: 38
right arrow: 39
down arrow: 40

伴我老 2024-09-09 00:10:52

这些键没有真正的 ascii 代码,因此您需要检查这些键的扫描代码,根据 helppc 的信息。代码听起来为“ascii”的原因是因为按键代码是由旧 BIOS 中断 0x16 和键盘中断 0x9 处理的。

                 Normal Mode            Num lock on
                 Make    Break        Make          Break
Down arrow       E0 50   E0 D0     E0 2A E0 50   E0 D0 E0 AA
Left arrow       E0 4B   E0 CB     E0 2A E0 4B   E0 CB E0 AA
Right arrow      E0 4D   E0 CD     E0 2A E0 4D   E0 CD E0 AA
Up arrow         E0 48   E0 C8     E0 2A E0 48   E0 C8 E0 AA

因此,通过查看 E0 后面的 Make 关键代码,例如分别为 0x50、0x4B、0x4D、0x48,这就是因查看关键代码并将它们视为“ascii”而产生混淆的地方......答案是不要随着平台的不同,操作系统的不同,在Windows下会有与这些按键对应的虚拟按键代码,不一定与BIOS代码相同,VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT..这可以在 C++ 的头文件 windows.h 中找到,我记得在 SDK 的包含文件夹中。

不要依赖于具有与此处显示的相同“相同 ascii”代码的按键代码,因为操作系统将按照操作系统认为合适的任何方式重新编程整个 BIOS 代码,这自然是预期的,因为 BIOS 代码是 16 位,并且操作系统(现在是32位保护模式),当然BIOS中的那些代码将不再有效。

因此,原始键盘中断 0x9 和 BIOS 中断 0x16 会在 BIOS 加载后从内存中擦除,并且当保护模式操作系统开始加载时,它将覆盖该内存区域并用自己的 32 位保护模式处理程序替换它来处理用那些键盘扫描码。

这是旧时代 DOS 编程的代码示例,使用 Borland C v3:

#include <bios.h>
int getKey(void){
    int key, lo, hi;
    key = bioskey(0);
    lo = key & 0x00FF;
    hi = (key & 0xFF00) >> 8;
    return (lo == 0) ? hi + 256 : lo;
}

这个例程实际上返回了向上、向下的代码,分别是 328 和 336,(实际上我没有向左和向右的代码,这是在我的旧烹饪书中!)实际的扫描代码可以在 lo 变量中找到。除 AZ、0-9 之外的键通过 bioskey 例程扫描代码为 0...添加 256 的原因是,因为变量 lo 的代码为0 和 hi 变量将具有扫描代码并在其上添加 256,以免与“ascii”代码混淆......

There is no real ascii codes for these keys as such, you will need to check out the scan codes for these keys, known as Make and Break key codes as per helppc's information. The reason the codes sounds 'ascii' is because the key codes are handled by the old BIOS interrupt 0x16 and keyboard interrupt 0x9.

                 Normal Mode            Num lock on
                 Make    Break        Make          Break
Down arrow       E0 50   E0 D0     E0 2A E0 50   E0 D0 E0 AA
Left arrow       E0 4B   E0 CB     E0 2A E0 4B   E0 CB E0 AA
Right arrow      E0 4D   E0 CD     E0 2A E0 4D   E0 CD E0 AA
Up arrow         E0 48   E0 C8     E0 2A E0 48   E0 C8 E0 AA

Hence by looking at the codes following E0 for the Make key code, such as 0x50, 0x4B, 0x4D, 0x48 respectively, that is where the confusion arise from looking at key-codes and treating them as 'ascii'... the answer is don't as the platform varies, the OS varies, under Windows it would have virtual key code corresponding to those keys, not necessarily the same as the BIOS codes, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT.. this will be found in your C++'s header file windows.h, as I recall in the SDK's include folder.

Do not rely on the key-codes to have the same 'identical ascii' codes shown here as the Operating system will reprogram the entire BIOS code in whatever the OS sees fit, naturally that would be expected because since the BIOS code is 16bit, and the OS (nowadays are 32bit protected mode), of course those codes from the BIOS will no longer be valid.

Hence the original keyboard interrupt 0x9 and BIOS interrupt 0x16 would be wiped from the memory after the BIOS loads it and when the protected mode OS starts loading, it would overwrite that area of memory and replace it with their own 32 bit protected mode handlers to deal with those keyboard scan codes.

Here is a code sample from the old days of DOS programming, using Borland C v3:

#include <bios.h>
int getKey(void){
    int key, lo, hi;
    key = bioskey(0);
    lo = key & 0x00FF;
    hi = (key & 0xFF00) >> 8;
    return (lo == 0) ? hi + 256 : lo;
}

This routine actually, returned the codes for up, down is 328 and 336 respectively, (I do not have the code for left and right actually, this is in my old cook book!) The actual scancode is found in the lo variable. Keys other than the A-Z,0-9, had a scan code of 0 via the bioskey routine.... the reason 256 is added, because variable lo has code of 0 and the hi variable would have the scan code and adds 256 on to it in order not to confuse with the 'ascii' codes...

假装爱人 2024-09-09 00:10:52

实际上,这个问题的答案取决于您使用的操作系统和编程语言。本身没有“ASCII 代码”。操作系统检测到您按下箭头键并触发程序可以捕获的事件。例如,在现代 Windows 计算机上,您将收到 WM_KEYUP 或 WM_KEYDOWN 事件。它通常传递一个 16 位值来确定按下了哪个键。

Really the answer to this question depends on what operating system and programming language you are using. There is no "ASCII code" per se. The operating system detects you hit an arrow key and triggers an event that programs can capture. For example, on modern Windows machines, you would get a WM_KEYUP or WM_KEYDOWN event. It passes a 16-bit value usually to determine which key was pushed.

清风疏影 2024-09-09 00:10:52

向上键的 ascii 值

  1. - 224
    72
  2. 向下键 - 224
    80

  3. 左键 - 224
    75

  4. 右键 - 224
    77

其中每个都有两个整数值作为 ascii 值,因为它们是特殊键,而不是 $ 的代码,后者只是 36。这些 2 字节特殊键通常将第一个数字设置为 224 或 0。这可以在 Windows 中使用 F# 或删除键可以找到。

编辑:这实际上可能是 unicode 回顾,但它们确实有效。

The ascii values of the:

  1. Up key - 224
    72

  2. Down key - 224
    80

  3. Left key - 224
    75

  4. Right key - 224
    77

Each of these has two integer values for ascii value, because they are special keys, as opposed to the code for $, which is simply 36. These 2 byte special keys usually have the first digit as either 224, or 0. this can be found with the F# in windows, or the delete key.

EDIT : This may actually be unicode looking back, but they do work.

从此见与不见 2024-09-09 00:10:52

如果您使用 OpenGL 进行编程,请使用 GLUT。以下页面应该有所帮助: http://www.lighthouse3d.com/opengl/ glut/index.php?5

GLUT_KEY_LEFT   Left function key
GLUT_KEY_RIGHT  Right function key
GLUT_KEY_UP     Up function key
GLUT_KEY_DOWN   Down function key
void processSpecialKeys(int key, int x, int y) {

    switch(key) {
        case GLUT_KEY_F1 : 
                red = 1.0; 
                green = 0.0; 
                blue = 0.0; break;
        case GLUT_KEY_F2 : 
                red = 0.0; 
                green = 1.0; 
                blue = 0.0; break;
        case GLUT_KEY_F3 : 
                red = 0.0; 
                green = 0.0; 
                blue = 1.0; break;
    }
}

If you're programming in OpenGL, use GLUT. The following page should help: http://www.lighthouse3d.com/opengl/glut/index.php?5

GLUT_KEY_LEFT   Left function key
GLUT_KEY_RIGHT  Right function key
GLUT_KEY_UP     Up function key
GLUT_KEY_DOWN   Down function key
void processSpecialKeys(int key, int x, int y) {

    switch(key) {
        case GLUT_KEY_F1 : 
                red = 1.0; 
                green = 0.0; 
                blue = 0.0; break;
        case GLUT_KEY_F2 : 
                red = 0.0; 
                green = 1.0; 
                blue = 0.0; break;
        case GLUT_KEY_F3 : 
                red = 0.0; 
                green = 0.0; 
                blue = 1.0; break;
    }
}
薔薇婲 2024-09-09 00:10:52

您可以通过编译并运行这个小 C++ 程序来检查它。

#include <iostream>
#include <conio.h>
#include <cstdlib>

int show;
int main()
{    
while(true)
    {
    int show = getch();
    std::cout << show;
    }
getch(); // Just to keep the console open after program execution  
}

You can check it by compiling,and running this small C++ program.

#include <iostream>
#include <conio.h>
#include <cstdlib>

int show;
int main()
{    
while(true)
    {
    int show = getch();
    std::cout << show;
    }
getch(); // Just to keep the console open after program execution  
}
情何以堪。 2024-09-09 00:10:52

如果您正在使用终端,就像我在搜索中找到它时一样,那么您会发现箭头键发送相应的光标移动转义序列。
所以在这种背景下,
UP = ^[[A
向下 = ^[[B
右 = ^[[C
左 = ^[[D
其中 ^[ 是表示转义的符号,但您将使用转义的 ASCII 值(即 27)以及括号和字母。
就我而言,使用串行连接来传达这些方向,对于向上箭头,我发送了 ^[, [, A 的字节序列 27,91,65

If you're working with terminals, as I was when I found this in a search, then you'll find that the arrow keys send the corresponding cursor movement escape sequences.
So in this context,
UP = ^[[A
DOWN = ^[[B
RIGHT = ^[[C
LEFT = ^[[D
with ^[ being the symbol meaning escape, but you'll use the ASCII value for escape which is 27, as well as for the bracket and letter.
In my case, using a serial connection to communicate these directions, for Up arrow, I sent the byte sequence 27,91,65 for ^[, [, A

你在我安 2024-09-09 00:10:52

您可以利用特殊功能来激活导航以实现编程目的。下面是它的示例代码。

void Specialkey(int key, int x, int y)
{
    switch(key)
    {
    case GLUT_KEY_UP: 
        /*Do whatever you want*/        
        break;  
    case GLUT_KEY_DOWN: 
        /*Do whatever you want*/
        break;
    case GLUT_KEY_LEFT:
        /*Do whatever you want*/
        break;
    case GLUT_KEY_RIGHT:
        /*Do whatever you want*/
        break;
    }

    glutPostRedisplay();
}

将其添加到您的主函数中

glutSpecialFunc(Specialkey);

希望这能解决问题!

You can utilize the special function for activating the navigation for your programming purpose. Below is the sample code for it.

void Specialkey(int key, int x, int y)
{
    switch(key)
    {
    case GLUT_KEY_UP: 
        /*Do whatever you want*/        
        break;  
    case GLUT_KEY_DOWN: 
        /*Do whatever you want*/
        break;
    case GLUT_KEY_LEFT:
        /*Do whatever you want*/
        break;
    case GLUT_KEY_RIGHT:
        /*Do whatever you want*/
        break;
    }

    glutPostRedisplay();
}

Add this to your main function

glutSpecialFunc(Specialkey);

Hope this will to solve the problem!

早乙女 2024-09-09 00:10:52

箭头字符的 Ascii 代码如下:
↑ 24
↓ 25
→ 26
← 27

The Ascii codes for arrow characters are the following:
↑ 24
↓ 25
→ 26
← 27

二手情话 2024-09-09 00:10:52

我被这个问题困住了,无法找到一个好的解决方案,所以决定对我拥有的 Mingw 编译器进行一些修改。我在 头文件中使用了 C++ 和 getch() 函数,并按箭头键查找分配给这些键的值。事实证明,它们分别为上、右、下、左键分配了 22472、22477、22480、22475 值。但是等等,它并不像你期望的那样工作。你必须放弃 224 部分,只写最后两位数字,软件才能识别正确的密钥;正如你所猜测的,72、77、80 和 75 都被其他角色占据了,但这对我有用,我希望它也对你有用。如果您想自己运行 C++ 代码并找出这些值,请运行此代码并按 Enter 键退出循环:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int x;
    while(1){
        x=(int)getch();
        if(x==13){
            break;
        }
        else
            cout<<endl<<endl<<x;
    }
    return getch();
}

I got stuck with this question and was not able to find a good solution, so decided to have some tinkering with the Mingw compiler I have. I used C++ and getch() function in <conio.h> header file and pressed the arrow keys to find what value was assigned to these keys. As it turns out, they are assigned values as 22472, 22477, 22480, 22475 for up, right, down and left keys respectively. But wait, it does not work as you would expect. You have to ditch the 224 part and write only the last two digits for the software to recognize the correct key; and as you guessed, 72, 77, 80 and 75 are all preoccupied by other characters, but this works for me and I hope it works for you as well. If you want to run the C++ code for yourself and find out the values for yourself, run this code and press enter to get out of the loop:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int x;
    while(1){
        x=(int)getch();
        if(x==13){
            break;
        }
        else
            cout<<endl<<endl<<x;
    }
    return getch();
}
七婞 2024-09-09 00:10:52

如果您是出于 JavaScript 的目的来了解按下了哪个键。

然后有一个JavaScript名称keydown的AddEventListener方法。

这给了我们按下的键,但是您可以对通过 keydown 或 onkeydown 获得的按下的键执行某些方法,两者完全相同。

按下按键的方法有:-

.code :- 返回一个关于按下哪个键的字符串,如 ArrowUp、ArrowDown、KeyW、Keyr 等
.keyCode :- 此方法已过时,但您仍然可以使用它。这将返回一个整数,例如小 a ---> 65 , 大写 A :- 65 主要是 ASCII 码,表示不区分大小写
向左箭头:- 37,向上箭头:- 38,向右箭头:- 39 向下箭头:- 40

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body>
    <h1 id="show">Press Any Button</h1>

  // JavaScript Code Starting From here See Magic By Pressing Any Buttton
  <script>
    document.addEventListener('keydown', (key)=> {
         let keycode = key.keyCode;
         document.getElementById('show').innerText = keycode;

    /*
    let keyString = key.code;
    switch(keyString){
        case "ArrowLeft":
            console.log("Left Key is Pressed");
            break;
        case "ArrowUp":
            console.log("Up Key is Pressed");
            break;
        case "ArrowRight":
            console.log("Right Key is Pressed");
            break;
        case "ArrowDown":
            console.log("Down Key is Pressed");
            break;
        default:
            console.log("Any Other Key is Pressed");
            break;
    }
    */
});
</script>

</body>
</html>

If you Come for JavaScript Purpose to get to Know which Key is Pressed.

Then there is a method of AddEventListener of JavaScript name keydown.

which give us that key which is pressed but there are certain method that you can perform on that pressed key that you get by keydown or onkeydown quite same both of them.

The Methods of pressed Key are :-

.code :- This Return a String About Which key is Pressed Like ArrowUp, ArrowDown, KeyW, Keyr and Like that
.keyCode :- This Method is Depereciated but still you can use it. This return an integer like for small a ---> 65 , Capital A :- 65 mainly ASCII code means case Insensitive
ArrowLeft :- 37, ArrowUp :- 38, ArrowRight :- 39 and ArrowDown :- 40

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body>
    <h1 id="show">Press Any Button</h1>

  // JavaScript Code Starting From here See Magic By Pressing Any Buttton
  <script>
    document.addEventListener('keydown', (key)=> {
         let keycode = key.keyCode;
         document.getElementById('show').innerText = keycode;

    /*
    let keyString = key.code;
    switch(keyString){
        case "ArrowLeft":
            console.log("Left Key is Pressed");
            break;
        case "ArrowUp":
            console.log("Up Key is Pressed");
            break;
        case "ArrowRight":
            console.log("Right Key is Pressed");
            break;
        case "ArrowDown":
            console.log("Down Key is Pressed");
            break;
        default:
            console.log("Any Other Key is Pressed");
            break;
    }
    */
});
</script>

</body>
</html>

柳絮泡泡 2024-09-09 00:10:52

无法解决所有操作系统/情况,但对于 Mac 上的 AppleScript,如下所示:

左:28

右:29

上:30

下:31

    tell application "System Events" to keystroke (ASCII character 31) --down arrow

Can't address every operating system/situation, but for AppleScript on a Mac, it is as follows:

LEFT: 28

RIGHT: 29

UP: 30

DOWN: 31

    tell application "System Events" to keystroke (ASCII character 31) --down arrow
戏剧牡丹亭 2024-09-09 00:10:52

嘎啊!访问 asciitable.com。箭头键相当于 HJKL 键的控制功能。即,在 vi 中创建一个大文本块。请注意,您可以使用 HJKL 键在该文本中移动。箭头键为 ^H、^J、^K、^L。

在 asciitable.com 上,在第三列中找到“K”。现在,查看第一列中的同一行以查找匹配的控制代码(在本例中为“VT”)。

Gaa! Go to asciitable.com. The arrow keys are the control equivalent of the HJKL keys. I.e., in vi create a big block of text. Note you can move around in that text using the HJKL keys. The arrow keys are going to be ^H, ^J, ^K, ^L.

At asciitable.com find, "K" in the third column. Now, look at the same row in the first column to find the matching control-code ("VT" in this case).

爱殇璃 2024-09-09 00:10:52

这就是我得到的:

左 - 19
向上 - 5
右 - 4
向下 -

Visual Fox Pro 中的 24 个作品

this is what i get:

Left - 19
Up - 5
Right - 4
Down - 24

Works in Visual Fox Pro

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文