#include <Library/DebugLib.h>
#include <Protocol/UsbIo.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Protocol/SimplePointer.h>
#include <Protocol/DevicePath.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <string.h>
//#include <IndustryStandard/Usb.h>
//#include <Library/UefiUsbLib.h>
//#include <stdio.h>
//#include <stdlib.h>
extern EFI_BOOT_SERVICES *gBS;
#define NUM0 0x30
#define NUM1 0x31
#define NUM2 0x32
#define NUM3 0x33
#define NUM4 0x34
#define NUM5 0x35
#define NUM6 0x36
#define NUM7 0x37
#define NUM8 0x38
#define NUM9 0x39
typedef enum _KeyCode
{
KC_NUM0 = 0x00,
KC_NUM1 = 0x01,
KC_NUM2 = 0x02,
KC_NUM3 = 0x03,
KC_NUM4 = 0x04,
KC_NUM5 = 0x05,
KC_NUM6 = 0x06,
KC_NUM7 = 0x07,
KC_NUM8 = 0x08,
KC_NUM9 = 0x09,
KC_UNKNOW = 0xA0
} KeyCode;
KeyCode HIDkeyboard_getCode()
{
KeyCode code;
EFI_STATUS Status;
EFI_EVENT myEvent[2];
UINTN index = 0;
Status = gBS->CreateEvent(
EVT_TIMER,
TPL_CALLBACK,
(EFI_EVENT_NOTIFY)NULL,
(VOID*)NULL,
&myEvent[0]
);
Status = gBS->SetTimer(
myEvent[0],
TimerRelative,
10*1000*1000
);
myEvent[1] = gST->ConIn->WaitForKey;
Status = gBS->WaitForEvent(2, myEvent, &index);
Status = gBS->SetTimer(myEvent[0],TimerCancel,10*1000*1000);
if(index == 0)
{
code = KC_UNKNOW;
}
else if(index == 1)
{
EFI_INPUT_KEY Key;
Status = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
if (EFI_ERROR(Status))
{
Print(L"key board is not support\n");
return -1;
}
INTN currentKey = Key.UnicodeChar;
switch (currentKey)
{
case NUM0:
code = KC_NUM0;
break;
case NUM1:
code = KC_NUM1;
break;
case NUM2:
code = KC_NUM2;
break;
case NUM3:
code = KC_NUM3;
break;
case NUM4:
code = KC_NUM4;
break;
case NUM5:
code = KC_NUM5;
break;
case NUM6:
code = KC_NUM6;
break;
case NUM7:
code = KC_NUM7;
break;
case NUM8:
code = KC_NUM8;
break;
case NUM9:
code = KC_NUM9;
break;
default:
code = KC_UNKNOW;
break;
}
}
Status = gBS->SetTimer(
myEvent[0],
TimerRelative,
10*1000*1000
);
return code;
}
INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
{
while(1)
{
KeyCode code = HIDkeyboard_getCode();
}
return EFI_SUCCESS;
}
07-29
09-08
1743