pointer.c 993 B

123456789101112131415161718192021222324252627282930313233
  1. #include <uefi.h>
  2. /**
  3. * Get mouse pointer's coordinates
  4. */
  5. int main(int argc, char **argv)
  6. {
  7. (void)argc;
  8. (void)argv;
  9. efi_status_t status;
  10. efi_guid_t ptrGuid = EFI_SIMPLE_POINTER_PROTOCOL_GUID;
  11. efi_simple_pointer_protocol_t *ptr = NULL;
  12. efi_simple_pointer_state_t state = {0};
  13. int x = 0, y = 0;
  14. status = BS->LocateProtocol(&ptrGuid, NULL, (void**)&ptr);
  15. if(!EFI_ERROR(status) && ptr) {
  16. /* if we got the interface, loop until a key pressed */
  17. printf("move mouse around, press any key to exit\n");
  18. while(!getchar_ifany()) {
  19. ptr->GetState(ptr, &state);
  20. x += state.RelativeMovementX;
  21. y += state.RelativeMovementY;
  22. printf("\rx %4d y %4d btns %d %d", x, y, state.LeftButton, state.RightButton);
  23. /* let the CPU rest a bit */
  24. usleep(100);
  25. }
  26. printf("\n");
  27. } else
  28. fprintf(stderr, "unable to get simple pointer protocol\n");
  29. return 0;
  30. }