Exemple #1
0
EFI_STATUS
UnregisterHotkeyNotify (
  IN HOTKEY                             *Hotkey
  )
{
  EFI_STATUS                            Status;
  UINTN                                 Index;
  UINTN                                 KeyIndex;
  EFI_HANDLE                            *Handles;
  UINTN                                 HandleCount;
  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TxtInEx;
  VOID                                  *NotifyHandle;

  gBS->LocateHandleBuffer (
          ByProtocol,
          &gEfiSimpleTextInputExProtocolGuid,
          NULL,
          &HandleCount,
          &Handles
          );
  for (Index = 0; Index < HandleCount; Index++) {
    Status = gBS->HandleProtocol (Handles[Index], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
    ASSERT_EFI_ERROR (Status);
    for (KeyIndex = 0; KeyIndex < Hotkey->CodeCount; KeyIndex++) {
      Status = TxtInEx->RegisterKeyNotify (
                          TxtInEx,
                          &Hotkey->KeyData[KeyIndex],
                          HotkeyCallback,
                          &NotifyHandle
                          );
      if (!EFI_ERROR (Status)) {
        Status = TxtInEx->UnregisterKeyNotify (TxtInEx, NotifyHandle);
        DEBUG ((EFI_D_INFO, "[Bds]UnregisterKeyNotify: %04x/%04x %r\n", Hotkey->KeyData[KeyIndex].Key.ScanCode, Hotkey->KeyData[KeyIndex].Key.UnicodeChar, Status));
      }
    }
  }

  return EFI_SUCCESS;
}
	EFI_STATUS 
testHotKey()
{
	EFI_STATUS  Status;
	EFI_KEY_DATA hotkey={0};
	EFI_KEY_DATA key = {0};
	EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL* InputEx = NULL;
	Status = gBS->LocateProtocol(
			&gEfiSimpleTextInputExProtocolGuid,
			NULL,
			(VOID**)&InputEx
			);
	Print(L"%r\n", Status);
	hotkey.Key.ScanCode = 0;
	hotkey.Key.UnicodeChar = 'c';
	hotkey.KeyState.KeyShiftState = EFI_LEFT_CONTROL_PRESSED | EFI_SHIFT_STATE_VALID;
	hotkey.KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;


	Status = InputEx->RegisterKeyNotify(InputEx,
			&hotkey,
			myNotify,
                        (VOID**)&notifyHandle);
	Print(L"%r\n", Status);
	while( key.Key.UnicodeChar != 'q')
	{
		UINTN Index;
		gBS->WaitForEvent(1, &(InputEx->WaitForKeyEx),  &Index);
	        Status = InputEx->ReadKeyStrokeEx(InputEx,
				&key);
		Print(L"(Scan %x Unicode%x)%x %x %r\n", key.Key.ScanCode, key.Key.UnicodeChar, key.KeyState.KeyShiftState, key.KeyState.KeyToggleState, Status);
		if(key.Key.UnicodeChar == 'q')
			break;
	}
	Status = InputEx->UnregisterKeyNotify(InputEx, notifyHandle);
	return Status;

}