CODE2

2016年11月11日 星期五

【UEFI】EFI_SIMPLE_TEXT_INPUT_PROTOCOL

EFI_SIMPLE_TEXT_INPUT_PROTOCOL

當我們需要輸入任何字元時,我們必須使用此protocol

範例如下:


#include <efi.h>
#include <efilib.h>

EFI_STATUS
ConsoleInput(
    IN EFI_HANDLE           ImageHandle,
    IN EFI_SYSTEM_TABLE     *SystemTable
    )
{
EFI_INPUT_KEY Key;
int count=0;
UINTN EventIndex,K;
CHAR16 *InputNumber={0};
InitializeLib (ImageHandle, SystemTable);
Print(L"\n Enter the number:\n");

do{
    count++;
    BS->WaitForEvent (1 , &ST-> ConIn-> WaitForKey, &EventIndex);
ST->ConIn->ReadKeyStroke(ST -> ConIn, &Key);
InputNumber[count]=Key.UnicodeChar;
Print(L"%c",Key.UnicodeChar);

}
while(InputNumber[count]!= '\r');
InputNumber[count]= '\0';
K=Atoi(InputNumber);
Print(L"\nNumber=%d \n",K);

return EFI_SUCCESS;
}


如此一來在shell底下執行則可由鍵盤輸入數字並顯示在螢幕上!

沒有留言:

張貼留言