我试图使用 EDK2 制作一个简单的应用程序来读取用户输入并将其打印出来,但它不起作用。
这是我的来源:
#include "UserInput.h"
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) {
EFI_STATUS Status;
EFI_INPUT_KEY Key;
Print(L"Enter something: ");
Status = SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key);
if (EFI_ERROR(Status)) {
Print(L"Failed to read user input\n");
return Status;
}
Print(L"\nUser input: %c\n", Key.UnicodeChar);
return EFI_SUCCESS;
}
结果是“无法读取用户输入”
如果您想等待用户输入,您有两个选择:
轮询直到用户按下某个键:
EFI_状态 读取用户输入轮询( 输出 CHAR16* 统一码) { EFI_STATUS 状态; EFI_INPUT_KEY 键;
if (Unicode == NULL) {
return EFI_INVALID_PARAMETER;
}
do {
Status = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
if (EFI_ERROR(Status)) {
if (Status != EFI_NOT_READY) {
return Status;
}
// wait, check for timeout, ...
}
} while (EFI_ERROR(Status));
*Unicode = Key.UnicodeChar;
return Status;
}
使用WaitForKey事件:
EFI_状态 读取用户输入等待( 输出 CHAR16* 统一码) { EFI_STATUS 状态; EFI_INPUT_KEY 密钥; UINTN指数;
if (Unicode == NULL) {
return EFI_INVALID_PARAMETER;
}
// Combine this with a timer event if you don't want to wait forever
Status = gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &Index);
if (EFI_ERROR(Status)) {
return Status;
}
Status = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
if (EFI_ERROR(Status)) {
return Status;
}
*Unicode = Key.UnicodeChar;
return Status;
}