drivers/input: partial fix of indistinguishable ASCII and special keycodes
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions

As analyzed, the NuttX initial keyboard API design uses event
type KBD_SPECPRESS/KBD_SPECREL to deliver special keys
and KBD_PRESS/KBD_RELEASE to deliver ASCII codes.

But it seems that this design choice has not been followed
in virtio-input, goldfish_events and sim_keyboard designs
and result is that external keyboard special keys events
are mapped to KEYCODE_xxx values which start from 0 and
overlaps with ASCII keys.

The issue is tracked under #19527 number.

This set of changes correct events reporting for mentioned
keyboards to report right event type for special keys.

The solution is only partial at this phase.

Virtual and more complex keyboards usually deliver
key pressures as scancodes (key position on keyboard)
and mapping to ASCII for keys which corresponds to letter
and other similar keys lacks mapping of national alphabets,
second row symbols and switch to capital letter according
to modifiers.

Signed-off-by: Pavel Pisa <pisa@fel.cvut.cz>
This commit is contained in:
Pavel Pisa 2026-07-29 14:29:29 +02:00 committed by Alan C. Assis
parent 5c9c236954
commit ab4890df16
8 changed files with 328 additions and 102 deletions

View file

@ -204,7 +204,7 @@ static uint32_t translate_x11_key(uint32_t code)
return KEYCODE_F24;
default:
return code;
return KEYCODE_NORMAL;
}
}
@ -246,10 +246,16 @@ int sim_kbd_initialize(void)
void sim_kbdevent(uint32_t key, bool is_press)
{
uint32_t trans_key;
bool is_special;
struct sim_dev_s *priv = (struct sim_dev_s *) &g_simkeyboard;
uint32_t types[2] =
static const uint32_t types[2][2] =
{
KEYBOARD_RELEASE, KEYBOARD_PRESS
{
KEYBOARD_RELEASE, KEYBOARD_PRESS
},
{
KBD_SPECREL, KBD_SPECPRESS
}
};
if (priv->eventloop == 0)
@ -258,9 +264,11 @@ void sim_kbdevent(uint32_t key, bool is_press)
}
trans_key = translate_x11_key(key);
is_special = trans_key != KEYCODE_NORMAL;
trans_key = is_special ? trans_key : key;
iinfo("key=%04x\n", key);
/* Report data changes */
keyboard_event(&priv->lower, trans_key, types[is_press]);
keyboard_event(&priv->lower, trans_key, types[is_special][is_press]);
}