等待按键 GNU EFI



如何在 GNU EFI 中等待密钥?
我打算它等待单个密钥,然后继续执行。
我的代码:

#include <efi.h>
#include <efilib.h>
#include <stdlib.h>
EFI_STATUS efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
EFI_STATUS Status;
ST = SystemTable;
Status = uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
if (EFI_ERROR(Status)){
...
return Status;
}
...
Status = ST->ConIn->Reset(ST->ConIn,1!=1);
if (EFI_ERROR(Status)){
...
return Status;
}
// wait for key here
return EFI_SUCCESS;
}

你可以从 UEFI Shell 的 EDK2 实现中获得一些想法。

基本原则是您需要设置一个等待按键的事件。

另请参阅 UEFI 规范 v2.8 中的第 12.3 节简单文本输入协议

顶部在 efi_main(...( 之外{...}您应该添加EFI_INPUT_KEY密钥;

efi_main之后

#if defined(_GNU_EFI)
InitializeLib(ImageHandle, SystemTable);  
#endif

添加UINTN 键事件 = 0;

或者无论你的方式是什么...

<小时 />
Print(L"PRESS ANY KEY OR PLEASE PRESS ESC TO EXIT.%Nn");
uefi_call_wrapper(SystemTable->ConOut->OutputString, 1, SystemTable->ConOut, L"START KEY READn"); // YES WE COULD DO SIMPLY Print(...);
SystemTable->ConIn->Reset(SystemTable->ConIn, FALSE);
//NOW WE SHOULD READ SOME KEYS
//YOU CAN ADD ANY OTHER OPTION HERE, WHEN CAPSLOCK ON THAT WILL PRINT FIRST CHAR CAPITALIZED BUT NOT REST OF CHARACTERS SINCE WE RESET...
//IF YOU WANT MORE KEYS SIMPLY IN VISUAL STUDIO TYPE SCAN_ AND YOU WILL SEE OTHER KEYS
/*...OTHER...*/
while ((UINTN)Key.ScanCode != SCAN_ESC)
{
SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &KeyEvent);
SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key);
SystemTable->ConIn->Reset(SystemTable->ConIn, FALSE);
Print(L"%c", Key.UnicodeChar);
}
/*...OTHER...*/
SystemTable->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
return EFI_SUCCESS;

相关内容

  • 没有找到相关文章

最新更新