I am coding a DOS-inspired EFI operating system. I have the capture key part down, as you can see here:
#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
}
When I press ESC, it copies the previously typed character to the current cursor position, and when I set it to ENTER instead of ESC, upon pressing ENTER, it moves the cursor to the beginning. How can I fix this?
You are using the wrong scan code, the ESC scan code is 0x17.