Control GUI by mecahnical buttons or PC keyboard in simulator

Description

I have an application with a LCD without touch panel. So I need to control the GUI by mechanical buttons.

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

STM32F429/Custom Board/GCC

What do you want to achieve?

How do I generate Key-Events from mechanical buttons and how can I generate such events in the simulator from PC keyboard to switch between screens for example?

What have you tried so far?

I just startet with LVGL and played around with some examples. I also searched the forum but I could not figure out how to do it.

Kind Regards
Jens

Hi,

There are 2 options:

  • Use the buttons to imitate presses on screens. Eg. you have UI buttons on the display on fixed positions and you want to press those buttons with an external button. In this case take a look at this
  • Use buttons to focus between elements (like with Tab on PC). In case chack this and this.

Thank you very much for your reply.

I read the links provided by you but its still not quite qlear to me. But I found your example “Screen transitions and display background

static lv_indev_t * kb_indev;

lv_indev_drv_t kb_drv;
lv_indev_drv_init(&kb_drv);
kb_drv.type = LV_INDEV_TYPE_KEYPAD;
kb_drv.read_cb = keyboard_read;
kb_indev = lv_indev_drv_register(&kb_drv);


lv_obj_t* screen1 = lv_scr_act();
lv_obj_t* btn = lv_btn_create(screen1, NULL);
lv_obj_t* label = lv_label_create(btn, NULL);
lv_label_set_text(label, "Screen 1");
lv_obj_set_style_local_bg_color(screen1, LV_OBJ_PART_MAIN, 0, LV_COLOR_YELLOW);

lv_obj_t* screen2 = lv_obj_create(NULL, NULL);
btn = lv_btn_create(screen2, NULL);
label = lv_label_create(btn, NULL);
lv_label_set_text(label, "Screen 2");
lv_obj_set_style_local_bg_color(screen2, LV_OBJ_PART_MAIN, 0, LV_COLOR_GREEN);


// Create a group and associate it with kb_indev
lv_group_t * g = lv_group_create();
lv_indev_set_group(kb_indev, g)

// Now add Objects to the group which should be able to receive the Keyboard Input
lv_group_add_obj(g, Myobj);	

How do I create a custom Object which is capable to receive and react to the Keyboard Inputs to switch between the screens like this:

if( '1' == Key ) {

	lv_scr_load(screen1);

} else if ( '2' == Key ) {

	lv_scr_load(screen2);
}

Kind regards
Jens

I think registering an event handler on the object and checking for LV_EVENT_KEY should work (although I don’t personally use keypad-based input).