ReadKey.py has these samples... EDKII event (EFI_EVENT), SimpleTextIn protocol and function return value.
In ReadKey.py file, it waits EfiPy.gST.ConIn[0].WaitForKey event in while loop.
EfiPy.gST.ConIn[0] protocol read user input key while event function return EFI_SUCCESS.
In output message, it output EFI_INPUT_KEY data.
source code - WaitForEvent
import EfiPy2 as EfiPy
# while (RETURN_ERROR (Status)) {
while EfiPy.RETURN_ERROR (Status):
# Status = gBS->WaitForEvent (
# 1,
# & (EFI_EVENT)(gST->ConIn[0].WaitForKey),
# & EventIndex,
# );
Status = EfiPy.gBS.WaitForEvent (
1,
EfiPy.byref(EfiPy.EFI_EVENT(EfiPy.gST.ConIn[0].WaitForKey)),
EfiPy.byref(EventIndex)
)
source code - ReadKeyStroke
# Status = gST->ConIn[0].ReadKeyStroke (
# gST.ConIn, &InputKey
# );
Status = EfiPy.gST.ConIn[0].ReadKeyStroke (
EfiPy.gST.ConIn, EfiPy.byref (InputKey)
)
EfiPy.gST.ConOut[0].OutputString (
while EfiPy.RETURN_ERROR (Status):
# Status = gBS->WaitForEvent (
# 1,
# & (EFI_EVENT)(gST->ConIn[0].WaitForKey),
# & EventIndex,
# );
Status = EfiPy.gBS.WaitForEvent (
1,
EfiPy.byref(EfiPy.EFI_EVENT(EfiPy.gST.ConIn[0].WaitForKey)),
EfiPy.byref(EventIndex)
)
source code - ReadKeyStroke
# Status = gST->ConIn[0].ReadKeyStroke (
# gST.ConIn, &InputKey
# );
Status = EfiPy.gST.ConIn[0].ReadKeyStroke (
EfiPy.gST.ConIn, EfiPy.byref (InputKey)
)
source code - EFI_INPUT_KEY
if InputKey.ScanCode != Si.SCAN_NULL:
EfiPy.gST.ConOut[0].OutputString (
EfiPy.gST.ConOut,
u"Scan code 0x%04X is input\r\n" % InputKey.ScanCode
)
else:
EfiPy.gST.ConOut[0].OutputString (
EfiPy.gST.ConOut,
u"Input key \"%c\"\r\n" % InputKey.UnicodeChar
)
screenshot
Sample code from screenshot is uploaded to Github
2024/07014 update
- In this sample code, user just adds this python statement (import EfiPy2 as EfiPy) in the file header, then all other parts needn't be modified and works well.
- One bug is found that this program may lead to exception while it received some special key. This error is skipped in commit abdf7b7
No comments:
Post a Comment