等待按键GNU EFI

时间:2019-09-20 17:57:58

标签: uefi 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;
}

2 个答案:

答案 0 :(得分:1)

您可以从the EDK2 implementation of UEFI Shell中获得一些想法。

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

另请参阅UEFI specification v2.8中的 12.3简单文本输入协议部分。

答案 1 :(得分:0)

efi_main(...){...} 的顶部,您应该添加 EFI_INPUT_KEY密钥;

efi_main 之后,

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

添加 UINTN KeyEvent = 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;