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

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

问题描述

方向键的 ASCII 值是多少?(上/下/左/右)

解决方案

这些键本身并没有真正的 ascii 码,您需要检查这些键的扫描码,称为 Make and Break 键码根据 helppc 的信息.代码听起来像ascii"的原因是因为键代码是由旧的 BIOS 中断 0x16 和键盘中断 0x9 处理的.

<前>普通模式数字锁定断断续续断断续续向下箭头 E0 50 E0 D0 E0 2A E0 50 E0 D0 E0 AA左箭头 E0 4B E0 CB E0 2A E0 4B E0 CB E0 AA右箭头 E0 4D E0 CD E0 2A E0 4D E0 CD E0 AA向上箭头 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 的包含文件夹中.

不要依赖键码来获得此处显示的相同相同的 ascii"代码,因为操作系统会以操作系统认为合适的方式重新编程整个 BIOS 代码,这自然是意料之中的,因为 BIOS 代码是16 位和操作系统(现在是 32 位保护模式),当然 BIOS 中的那些代码将不再有效.

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

这里是过去使用 Borland C v3 编写的 DOS 编程代码示例:

#include int getKey(void){int 键,你好,你好;键 = bioskey(0);lo = 键 &0x00FF;hi = (key & 0xFF00) >>8;返回 (lo == 0) ?嗨 + 256 : 哦;}

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

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

解决方案

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

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

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