How can I trigger an event by pressing a hardware button (changing the screen)?


I want to change the screen by pressing a hardware button. I think I should trigger an event manually after the hardware button is pressed. please help me

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

ESP32-Arduino IDE

What LVGL version are you using?


What do you want to achieve?

I need an example for doing this

What have you tried so far?

I searched a lot in forums but couldn’t find any useful suggestions. the first solution was to make a transparent button and add an event for this button. after that change state of this button after the hardware button is pressed. I don’t know how to change the state of the transparent button.

Code to reproduce

I tried the functions below for changing the screen separately but only lv_scr_load(ui_Digital) worked. but i need fade mode for changing my screens.
tested functions:
//_ui_screen_change(ui_Digital, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0);

// button event:
void ui_event_Button13(lv_event_t * e)
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_PRESSED) {
        _ui_screen_change(ui_Digital, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0);

// define transparent button:
    ui_Button13 = lv_btn_create(ui_Clock);
    lv_obj_set_width(ui_Button13, 100);
    lv_obj_set_height(ui_Button13, 50);
    lv_obj_set_x(ui_Button13, -59);
    lv_obj_set_y(ui_Button13, -104);
    lv_obj_set_align(ui_Button13, LV_ALIGN_CENTER);
    lv_obj_add_flag(ui_Button13, LV_OBJ_FLAG_SCROLL_ON_FOCUS);     /// Flags
    lv_obj_clear_flag(ui_Button13, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
    lv_obj_set_style_opa(ui_Button13, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

//hardware button 
  if (IO27Value == LOW) {
      //_ui_screen_change(ui_Digital, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0);
      lv_event_send(ui_Button13, LV_EVENT_PRESSED, NULL);

for example

@Marian_M Thank you so much. it works!