0

如何在 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;
}
4

2 回答 2

2

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

基本原理是你需要设置一个事件等待按键。

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

于 2019-09-21T08:49:38.537 回答
0

TOP OUTSIDE OF 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.%N\n");

uefi_call_wrapper(SystemTable->ConOut->OutputString, 1, SystemTable->ConOut, L"START KEY READ\n"); // 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;
于 2020-11-26T18:00:02.340 回答