Disabling indev/group when switching to another screen

Description

I have two screens. Each screen has one button. I have event on LV_EVENT_SCREEN_LOADED and LV_EVENT_SCREEN_UNLOADED (for screen), and the LV_EVENT_LONG_PRESSED event (for the button). If the key is pressed (and held), the event Screen1_btn_event is called. By moving to another Screen2, the LV_EVENT_SCREEN_LOADED event is called (Screen2_Loaded_Evnt), and then the event LV_EVENT_SCREEN_UNLOADED event is called (Screen1_Unloaded_Evnt). When the key is released after loading Screen2, Btn2_Event is called immediately. Btn2_Event event function loads Screen1.

What needs to be done to prevent the described situation from happening? It is necessary to release the button after reading the new screen, and then press it if we want to create an event for Btn1. Three external hardware keys are used, as an encoder

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

ESP32-C3, ESP-IDF v5.0

What LVGL version are you using?

v8.3.9

Simpliest way, I think, is use _CLICKED (not _PRESSED) events to switch between screens. This will require to release button to made transition to another screen

If a button is pressed on one screen and released on another screen, it is the “clicked” event that occurs on the focused object on the other screen

_CLCKED event called when object was pressed then released, see docs. So if you switch screen in this case the key already will be released, and user should be press key again to generate new event.

When moving to another Screen2, the user holds the button, and releases it after Screen2 is loaded.
Then the “CLICKED” event occurs. Regardless of the fact that the “press” of the key occurred on Screen1 and the release occurred on Screen2, the event occurred

What’s stopping you from switching screens when the user releases the key?

On screen1 i have a button, which is invisible, and it needs to receive an event from all three buttons (hardware button: ENTER, PREV and NEXT). Otherwise, the event can only be received if the ENTER button is used. In this way, I create “shortcuts” to some important submenus.
When switching to another screen, I call the function lv_indev_wait_release(lv_indev_get_act()); (I call her in the event: LV_EVENT_SCREEN_LOADED). lv_indev_get_act() sometimes returns NULL, that’s why the button/screen behaves like this.
I don’t know where the problem is