我正在编写一个受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键时,它将光标移动到开头。如何修复此问题?
2条答案
按热度按时间wmvff8tz1#
您使用了错误的扫描码,ESC扫描码为0x17。
ukxgm1gy2#
我发现了ENTER和ESC。ESC扫描码是0x17,ENTER像普通字符一样有0x0的扫描码,但你可以检查0xd的UnicodeChar值。