wcuter
July 11, 2019, 7:37am
1
Hi,
during porting to library 6.0 if I assign events to the keyboard, it no longer writes to the tee.
If I press OK or ESC, it does not execute the event.
My code is:
lv_obj_t * passwordtext = lv_ta_create(containerlevel, NULL);
lv_obj_t *kb = lv_kb_create(containerlevel, NULL);
lv_kb_set_ta(kb, passwordtext);
lv_obj_set_event_cb(kb, keyboard_action);
event
static void keyboard_action ( lv_obj_t * obj, lv_event_t event )
{
if ( event == LV_EVENT_APPLY )
{
code....
}
else if ( event == LV_EVENT_CANCEL )
{
code...
}
}
any suggestions?
Thanks a lot
Walter
You have to call the original event handler (lv_kb_def_event_cb
) inside your new one. It’s like OOP inheritance.
hiVGL
July 11, 2019, 10:56am
3
You can refer to this example.
lv_tutorial_objects.c
/**
Called when a button is released
@param btn pointer to the released button
@param event the triggering event
@return LV_RES_OK because the object is not deleted in this function
*/
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_RELEASED) {
/Increase the button width /
lv_coord_t width = lv_obj_get_width(btn);
lv_obj_set_width(btn, width + 20);
}
}
1 Like
@hiVGL Please read the question carefully. This has nothing to do with button event handlers.
wcuter
July 11, 2019, 11:08am
5
Hi,
tanks @embeddedt …
I thought it needed the usual event manager …
Now he writes in ta but … events don’t work…
In my code I changed only
lv_obj_set_event_cb
with
lv_kb_def_event_cb
never enters in keyboard_action function…
Any suggestions?
Thanks
Walter
@wcuter I think you misunderstood. You need to set your own custom event handler as normal, and inside that , call lv_kb_def_event_cb
(passing it the object and event).
@wcuter Just a sidenote, you can format the code blocks like this:
```c
<your code>
```
I’ve updated your first comment.
wcuter
July 11, 2019, 11:29am
9
Hi,
@embeddedt thankyou very much
@kisvegabor thanks for the information
Ciao
Walter
Im having a similar issue as you, but I still don’t understand the solution provided in this forum. Can I see how your new code looks?
Can you show a small ex of what you mean? I still don’t understand your solution to this problem.
lv_obj_t *kb = lv_kb_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(kb, keyboard_ev_handler);
static void keyboard_ev_handler(lv_obj_t * obj, lv_event_t event)
{
if ( event == LV_EVENT_APPLY )
{
/* custom logic */
}
/* default behavior */
lv_kb_def_event_cb(obj, event);
}