Read LV_EVENT_KEY on screen with only image on it


Hello, I need to read the movement of the encoder on a screen where there are no buttons or other input ui things → only screen background img and main image

What MCU/Processor/Board and compiler are you using?

Arduino , esp32

What LVGL version are you using?


What do you want to achieve?

read the key event for further processing in the code

What have you tried so far?

I tried to connect the event to the screen or image, but the event is not called

Code to reproduce

// in ui.c file
void ui_event_Test1(lv_event_t * e)
    lv_event_code_t event_code = lv_event_get_code(e);
    if(event_code == LV_EVENT_KEY) {
lv_obj_add_event_cb(ui_Screen1, ui_event_Test1, LV_EVENT_ALL, NULL);
// in ui_event.c file
void TEST_Event2BTN(lv_event_t * e)
	// Your code here
  LV_LOG_USER("TEST Call!");


Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Encoder is an external motor encoder?
How do you read the encoder?
How should lvgl know that a motor movement has happened?
Do you want to change anything on display when motor movement occurred?

When you don’t have any button (or other control) on screen,
from where should come an event for calling the event callback?

Maybe this thread may help you: lvgl approach “event driven” instead of “polling”?

Hello, thank you for your interest

encoder → standart user interface hw encoder =)

control using the encoder works great on the screen where there are buttons, dropdown menu check boxes, keyboard … etc

I used an example → learn-lvgl

  • learn-lvgl/arduino/rotery_encoder_input - it’s for v7 but it served the purpose

on the next screen, I want to select a profile with the help of rotating the encoder… each rotation changes the main image - and I don’t know how to achieve it

I thought about putting a button behind the image that would receive those events

but I don’t know if the left , right key events are also sent to the button

I will try it today … but if you know of a better way, I’m not against a better way =)

sorry for mistakes in text english is not my native language

OK it works!

on the screen2, I created a spinbox that is hidden behind the main image, so it cannot be seen and only receives events from the encoder ->left, right, enter key

to make everything simple, immediately after loading I activate the focus on the given spinbox to avoid the need to “click” =)

  • parts of the code that do all this - maybe it will help someone else :
ui_Spinner = lv_spinbox_create(ui_Screen2);
    lv_spinbox_set_range(ui_Spinner, 0, 9);
    lv_obj_set_width(ui_Spinner, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align(ui_Spinner, LV_ALIGN_CENTER);

    lv_obj_add_event_cb(ui_Spinner, ui_event_Test, LV_EVENT_ALL, NULL);
void ui_event_Test(lv_event_t * e)
    lv_event_code_t event_code = lv_event_get_code(e);
    if(event_code == LV_EVENT_KEY) {
lv_group_set_editing(group, true);