feat(evdev): pass raw keycodes to user through event (#9771)

This commit is contained in:
Florian
2026-06-10 07:35:13 +02:00
committed by GitHub
parent e976ccee17
commit 6fa9acedef
3 changed files with 59 additions and 1 deletions
+19
View File
@@ -93,6 +93,25 @@ void key_event_cb(lv_event_t *e)
lv_indev_add_event_cb(keyboard, key_event_cb, LV_EVENT_KEY, NULL);
```
LVGL automatically converts direction keys to `LV_KEY_XXX`. For other keys
you can get their value by querying <ApiLink name="lv_evdev_get_raw_key" /> in a <ApiLink name="LV_EVENT_KEY" /> handler.
```c
void key_event_cb(lv_event_t *e)
{
if(lv_evdev_is_raw_key(e))
{
LV_LOG_USER("%d", lv_evdev_get_raw_key(e));
}
}
...
lv_obj_add_event_cb(lv_screen_active(), key_event_cb, LV_EVENT_KEY, NULL);
```
## Key Remapping
Some applications require assigning physical buttons to multiple key events depending
+15
View File
@@ -91,6 +91,21 @@ void lv_evdev_set_swap_axes(lv_indev_t * indev, bool swap_axes);
*/
void lv_evdev_set_calibration(lv_indev_t * indev, int min_x, int min_y, int max_x, int max_y);
/**
* Returns the status indicating whether an LV_KEY could not be processed.
* @param e pointer to an event
* @return true if it is a raw key
* @return false if it is not a raw key
*/
bool lv_evdev_is_raw_key(lv_event_t * e);
/**
* Returns the raw keycode if LV_KEY could not be processed
* @param e pointer to an event
* @return uint16_t raw keycode
*/
uint16_t lv_evdev_get_raw_key(lv_event_t * e);
/**
* Remove evdev input device.
* @param indev evdev input device to close and free
+25 -1
View File
@@ -112,7 +112,7 @@ static int _evdev_process_key(uint16_t code)
case KEY_END:
return LV_KEY_END;
default:
return 0;
return code + 0xFFFF;
}
}
@@ -660,6 +660,30 @@ void lv_evdev_set_calibration(lv_indev_t * indev, int min_x, int min_y, int max_
dsc->max_y = max_y;
}
bool lv_evdev_is_raw_key(lv_event_t * e)
{
LV_CHECK_ARG(e != NULL, return false);
uint32_t key = lv_event_get_key(e);
return (key > 0xFFFF);
}
uint16_t lv_evdev_get_raw_key(lv_event_t * e)
{
LV_CHECK_ARG(e != NULL, return 0);
uint32_t key = lv_event_get_key(e);
if(key > 0xFFFF) {
return (uint16_t)(key - 0xFFFF);
}
else {
LV_LOG_WARN("key is an LV_KEY");
}
return 0;
}
void lv_evdev_delete(lv_indev_t * indev)
{
lv_indev_delete(indev);