1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00

lv_indev_get_key fixes

This commit is contained in:
Gabor Kiss-Vamosi 2019-03-17 07:59:38 +01:00
parent 80738425f6
commit efd647f853
3 changed files with 14 additions and 4 deletions

View File

@ -198,7 +198,7 @@ void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point)
}
/**
* Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD)
* Get the last pressed key of an input device (for LV_INDEV_TYPE_KEYPAD)
* @param indev pointer to an input device
* @return the last pressed key (0 on error)
*/
@ -386,6 +386,13 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
lv_obj_t * focused = lv_group_get_focused(g);
if(focused == NULL) return;
/*Save the last key to compare it with the current latter on RELEASE*/
uint32_t prev_key = i->proc.types.keypad.last_key;
/* Save the last key.
* It must be done here else `lv_indev_get_key` will return the last key in events and signals*/
i->proc.types.keypad.last_key = data->key;
/*Key press happened*/
if(data->state == LV_INDEV_STATE_PR &&
i->proc.types.keypad.last_state == LV_INDEV_STATE_REL)
@ -468,7 +475,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
else if(data->state == LV_INDEV_STATE_REL && i->proc.types.keypad.last_state == LV_INDEV_STATE_PR)
{
/*The user might clear the key when it was released. Always release the pressed key*/
data->key = i->proc.types.keypad.last_key;
data->key = prev_key;
if(data->key == LV_GROUP_KEY_ENTER) {
focused->signal_cb(focused, LV_SIGNAL_RELEASED, NULL);
@ -489,7 +496,6 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
}
i->proc.types.keypad.last_state = data->state;
i->proc.types.keypad.last_key = data->key;
#else
(void)data; /*Unused*/
(void)i; /*Unused*/

View File

@ -106,7 +106,7 @@ void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback);
void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point);
/**
* Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD)
* Get the last pressed key of an input device (for LV_INDEV_TYPE_KEYPAD)
* @param indev pointer to an input device
* @return the last pressed key (0 on error)
*/

View File

@ -116,6 +116,10 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
data->point.x = indev->proc.types.pointer.act_point.x;
data->point.y = indev->proc.types.pointer.act_point.y;
}
/*Similarly set at least the last key in case of the the user doesn't set it on release*/
else if(indev->driver.type == LV_INDEV_TYPE_KEYPAD) {
data->key = indev->proc.types.keypad.last_key;
}
if(indev->driver.read_cb) {
LV_LOG_TRACE("idnev read started");