OvmfPkg/VirtioInputDxe: do not set ScanCode together with UnicodeChar

EFI_INPUT_KEY's ->ScanCode and ->UnicodeChar are mutually exclusive.
The value space of ->ScanCode only includes representations of keys that
are not representable in Unicode (F1-F10, Esc, arrows etc.) and vice
versa. Furthermore, the integer representations of those fields overlap.
As such, writing ->UnicodeChar values into ->ScanCode is invalid and
produces bogus EFI_INPUT_KEYs that would compare inequal to any
well-formed values that might be passed into e.g. RegisterKeyNotifyEx.

Do not set ->ScanCode when a Unicode value is produced for a printable
character.

Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Tested-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
This commit is contained in:
Ivan Shapovalov 2026-07-28 11:03:24 +03:00
parent e9ca367750
commit cd7c5fe467

View file

@ -167,10 +167,8 @@ VirtioKeyboardConvertKeyCode (
default:
if (Dev->KeyActive[KEY_LEFTSHIFT] || Dev->KeyActive[KEY_RIGHTSHIFT]) {
Key->ScanCode = MapShift[Code];
Key->UnicodeChar = MapShift[Code];
} else {
Key->ScanCode = Map[Code];
Key->UnicodeChar = Map[Code];
}