Description
when i create a list,i want to control the list by keypad.but when i press key_1,i can’t get real key from event_handler()
The code block(s) should be formatted like:
static bool keypad_callback(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
uint last_key = 0;
/*Get whether the a key is pressed and save the pressed key*/
uint act_key = keypad_get_key();
/*Get the current x and y coordinates*/
mouse_get_xy(&data->point.x, &data->point.y);
if(act_key != KEY_NONE)
{
data->state = LV_INDEV_STATE_PR;
data->key=act_key;
/*Translate the keys to LVGL control characters according to your key definitions*/
switch(act_key)
{
case KEY_DOWN:
act_key = LV_KEY_DOWN;
break;
case KEY_UP:
act_key = LV_KEY_UP;
break;
case KEY_CANCEL:
act_key = LV_KEY_END;
break;
case KEY_CONFIRM:
act_key = LV_KEY_ENTER;
break;
case KEY_DELETE:
act_key = LV_KEY_DEL;
break;
case KEY_POWER:
act_key = LV_KEY_HOME;
break;
default:
break;
}
last_key = act_key;
}
else
{
data->state = LV_INDEV_STATE_REL;
}
data->key = last_key;
//TRACE(DBG_TRACE_LVL,"%s,act_key=%d\r\n",__FUNCTION__,data->key);
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
static void list_event_cb(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_CLICKED)
{
TRACE(DBG_TRACE_LVL,"clicked\r\n");
}
else if(e==LV_EVENT_KEY)
{
TRACE(DBG_TRACE_LVL,"key=%d\r\n",keypad_get_key());
}
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.