C语言 无法捕获0x 01 - 0x 1F中的所有值

h22fl7wq  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(107)

我正在编写一个受DOS启发的Windows操作系统。我已经下载了捕获键部分,如您所见:

#include "uefi/uefi.h"

int main(int argc, char **argv) {
    efi_input_key_t ch; // define ch as an efi input key
    char command[1024] = ""; // define the command variable as a buffer stored in memory with a size of 1024 bytes
    int len = 0; // define the length of the command

    while (1) {
        ST->BootServices->WaitForEvent(1, &(ST->ConIn->WaitForKey), NULL); // wait for key so keys arent printed forever
        ST->ConIn->ReadKeyStroke(ST->ConIn, &ch); // define ch as pressed key

        if (ch.ScanCode == 0x01) {
            // Check for Escape key and break the loop
            break;
        }

        printf("%c", ch.UnicodeChar); // print the character

        if (len < (sizeof(command) - 1)) {
            command[len] = ch.UnicodeChar; // add the character to the back
            command[len + 1] = '\0';  // Null-terminate the string
            len++;
        }
    }

    return 0; // after pressing ESC, exit the program and go to the UEFI shell
}

字符串
当我按ESC键时,它将先前键入的字符复制到当前光标位置,当我将其设置为ENTER而不是ESC键时,按ENTER键时,它将光标移动到开头。如何修复此问题?

wmvff8tz

wmvff8tz1#

您使用了错误的扫描码,ESC扫描码为0x17。

ukxgm1gy

ukxgm1gy2#

我发现了ENTER和ESC。ESC扫描码是0x17,ENTER像普通字符一样有0x0的扫描码,但你可以检查0xd的UnicodeChar值。

相关问题