How to see which key was pressed with LV_EVENT_KEY event


I can’t figure out how to actually retrieve which key was pressed in an event callback.

Specifically, I’m using a roller callback, and I get the events like LV_EVENT_KEY and LV_EVENT_PRESSED.

However, the callback signature of the even callback system has no means of passing in the actual event data. How do I retrieve that?

I see in lv_event_send_func that the input device’s callback gets the data at indev_act->driver.feedback_cb, but I don’t quite see the use of that – isn’t it the indev that sent the key in the first place?

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


What LVGL version are you using?

github master branch cac6f92964f3cdb960612b21a7e7996af2a9e8ee

What do you want to achieve?

Get the key value so that I can pop out of a menu when a particular key is pressed.

What have you tried so far?

looked through the code and I can’t find how I’m supposed to retrieve the actual key pressed value.

Ah, I think I found the solution. Dig deeper into the forums… Looks like lv_event_get_data() gets the event data as a void pointer.

1 Like

I updated the docs to described this:

Hi ccrome,

Could you just tell me how to write a call back function to retrieve the LV_KEY. I am facing the difficulty to retrieve the keys. Below is my code for your reference

void event_handler(lv_obj_t * obj, lv_event_t event)    {
if(event == LV_EVENT_KEY){
	uint32_t * key = lv_event_get_data();

	if (* key == LV_KEY_HOME)
		*key = 0;

lv_obj_set_event_cb(list_btn, event_handler);

Your code seems correct. Is LV_EVENT_KEY triggered? If so what is the value of *key.