/* Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey. */
VOID EFIAPI USBKeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
/* Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey. */
VOID EFIAPI USBKeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
{
  USB_KB_DEV    *UsbKeyboardDevice;
  EFI_KEY_DATA  KeyData;
  EFI_TPL       OldTpl;
  UsbKeyboardDevice = (USB_KB_DEV *)Context;
  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
  while (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
    CopyMem (
      &KeyData,
      UsbKeyboardDevice->EfiKeyQueue.Buffer[UsbKeyboardDevice->EfiKeyQueue.Head],
      sizeof (EFI_KEY_DATA)
      );
    if ((KeyData.Key.ScanCode == SCAN_NULL) && (KeyData.Key.UnicodeChar == CHAR_NULL)) {
      Dequeue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (EFI_KEY_DATA));
      continue;
    }
    gBS->SignalEvent (Event);
    break;
  }
  gBS->RestoreTPL (OldTpl);
}