左上右下的ascii值是多少? [英] What are the ascii values of up down left right?

查看:131
本文介绍了左上右下的ascii值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

这些键没有真正的ascii码,因此您需要检出这些键的扫描码,称为Make and Break键码,具体方法如下:根据 helppc 的信息.该代码听起来像"ascii"的原因是因为密钥代码是由旧的BIOS中断0x16和键盘中断0x9处理的.

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

因此,通过查看Make键代码的E0之后的代码,例如分别为0x50、0x4B,0x4D,0x48,这就是由于查看键代码并将其视为"ascii"而引起的困惑.答案是不要,因为平台有所不同,操作系统也有所不同,在Windows下,它将具有与这些密钥相对应的虚拟密钥代码,不一定与BIOS代码VK_UP,VK_DOWN,VK_LEFT相同, VK_RIGHT ..可以在您的C ++头文件windows.h中找到,正如我在SDK的include文件夹中回忆的那样.

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.

不要依赖键码来显示相同​​的"ascii"码,因为操作系统会以OS认为合适的方式对整个BIOS代码进行重新编程,这自然是可以预料的,因为16位和操作系统(当今是32位保护模式),当然,BIOS中的这些代码将不再有效.

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.

因此,在BIOS加载后,原始键盘中断0x9和BIOS中断0x16将从内存中清除,并且当受保护模式OS开始加载时,它将覆盖该内存区域,并将其替换为自己的32位保护模式处理程序来处理这些键盘扫描代码.

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.

以下是使用Borland C v3进行DOS编程时的代码示例:

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;
}

实际上,此例程返回的代码分别为up和down,分别为328和336(我实际上没有左右代码,这在我的旧书中!)实际的扫描代码位于lo变量.通过bioskey例程,除AZ,0-9以外的其他键的扫描代码为0 ....添加256的原因,因为变量lo的代码为0,而hi变量的代码为0.扫描代码并在上面添加256,以免与"ascii"代码混淆...

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...

这篇关于左上右下的ascii值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆