Question about input device


I would to know the logic flow that start from when I press a Button using an input device and finish when the Button on the screen is selected.

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


What do you want to achieve?

I want to use a custom input device to control my gui.

What have you tried so far?

I have tried to run the example that use the keyboard and the mouse (lv_demo_keypad_encoder). I have added my input drive to the example, but i’m not able to run all the functionalities that are in this example. In particular i have noticed that the events UP, DOWN, ENTER that I send using my input driver don’t are recognize proprerly from the rest of the example.
To run the enter button I have modified the msgbox_event_cb function as you can see in the code section. In this section I have copied my function that read the input data.
I don’t know if the use of the queue is a good idea, but i have created a task that read the input device (this is a 5 button shield that give me 5 events: UP, DOWN,LEFT,RIGHT and ENTER) and after the read, associate each of those events, with the lvgl input events, so I send to the GUI this events LV_KEY_ENTER, LV_KEY_UP e so on…
But unfortunately, seem to me that these events aren’t recognize properly.

Someone can help me to understand what are wrong in my code and how I control the objects in my GUI using an input device?

Code to reproduce

static void msgbox_event_cb(lv_obj_t * msgbox, lv_event_t e)
	//printf("msgbox_event_cb: %d\n",e);
        uint16_t b = lv_msgbox_get_active_btn(msgbox);
        if(b == 0 || b == 1) {
            lv_obj_reset_style_list(lv_layer_top(), LV_OBJ_PART_MAIN);
            lv_obj_set_click(lv_layer_top(), false);
            lv_event_send(tv, LV_EVENT_REFRESH, NULL);

static bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
    (void) indev_drv;      /*Unused*/
//    data->state = state;
//    data->key = keycode_to_ascii(last_key);
    uint32_t keyboard_event;
    if(xQueueReceive(gui_input_evt_queue, &keyboard_event, portMAX_DELAY)){
    	data->state = LV_INDEV_STATE_PR;
    	data->key = keyboard_event;
    	//printf("key board event: %d\n",keyboard_event);
    	data->state = LV_INDEV_STATE_REL;

    return false;

Screenshot and/or video

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


I assume that you have created the input device with LV_INDEV_TYPE_KEYPAD.

Generally, what you did should work, but I see these possible issues:

  1. portMAX_DELAY should 0 to return from keyboard_read is not key was pressed
  2. If keyboard_event is the pressed key. Be sure you use LV_KEY_UP/DOWN/ENTER values and not normal ASCII codes or keycodes from a keyboard.

A log from keyboard_read with state and key values would be useful to see what can be the issue.

Hi kisvegabor!
I’m sorry for the late reply, but I very busy with my work.
However now I’m able to read all keys that I need correctly.
The problem is that in my project I use a touchless input that I believe it’s different from other predefinited input device.
Now I have implemented this using keyboard input device, but there are some gesture that I have associated with dummy keys ( LV_KEY_BACKSPACE, LV_KEY_HOME etc…) and I don’t know if this is a problem.
However there is a way to associate some custom keys to my custom input device?

No problem.

You are free to define custom keys similarly to the built-in ones. E.g. #define MY_KEY_1 0x100

Hi kisvegabor,
your answer Is very usefull, many thanks!

Sorry to hijack this question, but it relates directly to my lack of basic understanding about how LVGL works.

In Lucas’ question how are:

msgbox_event_cb(lv_obj_t * msgbox, lv_event_t e)
keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)

related or connected?

In other words, how does what happens ( data->state = LV_INDEV_STATE_PR) in keyboard_read() become “e == LV_EVENT_PRESSING” in msgbox_event_cb() ?