Checking if a certain key is down within an UEFI app

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
uefiguy
Posts: 4
Joined: Mon Dec 27, 2021 1:33 pm
Libera.chat IRC: uefiguy

Checking if a certain key is down within an UEFI app

Post by uefiguy »

Hello, so I'm reading the UEFI specification (https://uefi.org/sites/default/files/re ... _03_18.pdf) and within the UEFI there are those two protocols `EFI_SIMPLE_TEXT_INPUT_PROTOCOL` and `EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL` that allow you to read keyboard input within the UEFI.
You use either `EFI_BOOT_SERVICES.WaitForEvent` (blocking) or `EFI_BOOT_SERVICES.CheckEvent` (non-blocking) to check for input and then you use `EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke` or `EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.ReadKeyStrokeEx` to read input if there is any in the buffer.

As far as I understand it, `ReadKeyStrokeEx` and `ReadKeyStroke` behave the same with the exception that the former simply provides more information. Is that correct?

Well my problem is that I want to check whether a certain key is currently held down so that I can handle multiple keypresses at the same time.

I want to create a simple UEFI app game where the player can move in all 8 directions and I want to move diagonally to the top right if e.g. up arrow and right arrow are pressed at the same time.
Is there any way I can achieve that? Otherwise the player would have to spam up arrow, right arrow, up arrow, right arrow etc. to do that.

I also noticed there is this protocol called `EFI_SERIAL_IO_PROTOCOL`. Does this have any relevance here? Can it help me in some way? I'm not entirely sure what it allows me to do.
I appreciate any advice on how to do this.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Checking if a certain key is down within an UEFI app

Post by Octocontrabass »

uefiguy wrote:As far as I understand it, `ReadKeyStrokeEx` and `ReadKeyStroke` behave the same with the exception that the former simply provides more information. Is that correct?
Yes.
uefiguy wrote:I want to create a simple UEFI app game where the player can move in all 8 directions and I want to move diagonally to the top right if e.g. up arrow and right arrow are pressed at the same time.
Is there any way I can achieve that?
No. Held key reporting is limited to the modifiers listed under the description of ReadKeyStrokeEx().
uefiguy wrote:I also noticed there is this protocol called `EFI_SERIAL_IO_PROTOCOL`. Does this have any relevance here? Can it help me in some way? I'm not entirely sure what it allows me to do.
It allows you to send and receive data over a serial port. It might be helpful for debugging or remote control via serial terminal. It's irrelevant unless you're using a serial terminal instead of a keyboard.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Checking if a certain key is down within an UEFI app

Post by Ethin »

Even though it doesn't really matter, I'll say it anyway: UEFI isn't designed for you to be able to play games, browse the web etc. Its not a general-purpose OS or anything like that, so a lot of functionality you'd expect or think to be there based on how the protocols are described probably isn't. (E.g.: EDK II doesn't implement isochronous USB transfers for example, even though the function in the protocol exists.) If there's anything I've learned when working with UEFI, its the following two golden rules:
  1. Not all the protocols in the specification are implemented in any implementation, reference or not.
  2. Not all of the functions, structures, etc. for any given protocol are implemented in any implementation of the specification, reference or not.
Usually, you have to find out the second point the hard way -- by digging through the code or contacting the developers.
uefiguy
Posts: 4
Joined: Mon Dec 27, 2021 1:33 pm
Libera.chat IRC: uefiguy

Re: Checking if a certain key is down within an UEFI app

Post by uefiguy »

Thank you for the answers.
Post Reply