/* Event notification function for SIMPLE_TEXT_IN.WaitForKey event Signal the event if there is key available */
VOID EFIAPI KeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
/* Event notification function for SIMPLE_TEXT_IN.WaitForKey event Signal the event if there is key available */
VOID EFIAPI KeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
{
  EFI_TPL                  OldTpl;
  KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn;
  EFI_KEY_DATA             KeyData;
  ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *)Context;
  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
  KeyboardTimerHandler (NULL, ConsoleIn);
  if (!ConsoleIn->KeyboardErr) {
    while (!IsEfikeyBufEmpty (&ConsoleIn->EfiKeyQueue)) {
      CopyMem (
        &KeyData,
        &(ConsoleIn->EfiKeyQueue.Buffer[ConsoleIn->EfiKeyQueue.Head]),
        sizeof (EFI_KEY_DATA)
        );
      if ((KeyData.Key.ScanCode == SCAN_NULL) && (KeyData.Key.UnicodeChar == CHAR_NULL)) {
        PopEfikeyBufHead (&ConsoleIn->EfiKeyQueue, &KeyData);
        continue;
      }
      gBS->SignalEvent (Event);
      break;
    }
  }
  gBS->RestoreTPL (OldTpl);
}