Multi function key handle

Description

If my device is a music player, one key’s function is that click for next song and long press for volumn up. How can I handle it?

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

What LVGL version are you using?

What do you want to achieve?

What have you tried so far?

Code to reproduce

Screenshot and/or video

For different key,you can set a LV_EVENT_KEY event, then use lv_indev_get_key() to get the key.
For long press, set this event LV_EVENT_LONG_PRESSED.

If more keys pressed at same time, this flow is not good idea. I add 3 different events for key pressed/repeat/released.

How these keys are related to the UI? I mean do they press a specific button on the screen? Or working on all screens?

Maybe you should handle these key out of LVGL and if volume up is pressed change the value of a slider.

Or you can create transparent buttons on lv_layer_top() and use the LV_INDEV_TYPE_BUTTON type to make the physical buttons press the transparent buttons.

I have a combo key e.g. Up and Down. Or Long Press Right to enter menu. and click right key to turn on a Led. Key Up/Down click for next/previous song, Long for Volumn Up/Down.

In this case I’d go with LV_INDEV_TYPE_BUTTON.

I reopen this old one, but to this time dont handled good. For example i use encoder indev and need show one think on short click and other on long.
Actual indev code dont do it. Indev override LONG with toggle and dont send event…

Then i must patch lvgl code with this disabling toggle …

            if(data->key == LV_KEY_ENTER) {
                bool editable_or_scrollable = lv_obj_is_editable(indev_obj_act) ||
                                              lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_SCROLLABLE);

                /*On enter long press toggle edit mode.*/
                if(editable_or_scrollable && 0) {   //MM modified
                    /*Don't leave edit mode if there is only one object (nowhere to navigate)*/
                    if(lv_group_get_obj_count(g) > 1) {
                        LV_LOG_INFO("toggling edit mode");
                        lv_group_set_editing(g, lv_group_get_editing(g) ? false : true); /*Toggle edit mode on long press*/
                        lv_obj_clear_state(indev_obj_act, LV_STATE_PRESSED);    /*Remove the pressed state manually*/
                    }
                }
                /*If not editable then just send a long press Call the ancestor's event handler*/
                else {
                    lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED, indev_act);
                    if(indev_reset_check(&i->proc)) return;
                }

but more better will be , that i can in code change key from enter to other if required, and code handle all type press. Now too completely dont work and send only one event.

Im not expert to pull on git , but my idea is change this

bool editable_or_scrollable = lv_obj_is_editable(indev_obj_act) ||
                                              lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_SCROLLABLE);

to somethink with && , that revoke toggling…
Understand my controlled object is ARC , that must be editable for change value with encoder…