diff --git a/docs/src/details/main-modules/indev/keypad.rst b/docs/src/details/main-modules/indev/keypad.rst index 05f6da9ebc..0153b27045 100644 --- a/docs/src/details/main-modules/indev/keypad.rst +++ b/docs/src/details/main-modules/indev/keypad.rst @@ -88,7 +88,31 @@ The most important special keys in your :cpp:func:`read_cb` function are: You should translate some of the read keys to these special keys to support navigation in a group and interact with selected widgets. -Key remapping + +Key Events +********** + +If needed you can easily catch the keys sent by an input device by subscribing to +an indev event like this: + + +.. code-block:: c + + void key_event_cb(lv_event_t *e) + { + lv_indev_t * indev = (lv_indev_t *)lv_event_get_target(e); /*Same as lv_indev_active()*/ + if(lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) { + LV_LOG_USER("%c", (char) lv_indev_get_key(indev)); + } + } + + ... + + lv_indev_add_event_cb(keyboard, key_event_cb, LV_EVENT_KEY, NULL); + + + +Key Remapping ************* Some applications require assigning physical buttons to multiple key events depending diff --git a/src/indev/lv_indev.c b/src/indev/lv_indev.c index 436d1cf89a..f427064f17 100644 --- a/src/indev/lv_indev.c +++ b/src/indev/lv_indev.c @@ -782,6 +782,8 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) uint32_t prev_key = i->keypad.last_key; i->keypad.last_key = data->key; + lv_indev_send_event(indev_act, LV_EVENT_KEY, NULL); + lv_group_t * g = i->group; if(g == NULL) return; @@ -885,6 +887,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) /*Release happened*/ else if(is_enabled && data->state == LV_INDEV_STATE_RELEASED && prev_state == LV_INDEV_STATE_PRESSED) { LV_LOG_INFO("%" LV_PRIu32 " key is released", data->key); + /*The user might clear the key when it was released. Always release the pressed key*/ data->key = prev_key; if(data->key == LV_KEY_ENTER) { @@ -1859,7 +1862,8 @@ static lv_result_t send_event(lv_event_code_t code, void * param) code == LV_EVENT_RELEASED || code == LV_EVENT_LONG_PRESSED || code == LV_EVENT_LONG_PRESSED_REPEAT || - code == LV_EVENT_ROTARY) { + code == LV_EVENT_ROTARY || + code == LV_EVENT_KEY) { lv_indev_send_event(indev, code, indev_obj_act); if(indev_reset_check(indev)) return LV_RESULT_INVALID;