I wanted to ask if anyone knows how I could get the keyboard to disappear and have the user leave focus from the text area after pressing the return/enter key on the keyboard.
Do you mean on the keyboard widget or the keyboard of your PC?
If you are talking about LVGL keyboard, then you can consider using the āFOCUSEDā event of the keyboardās textarea.
- If the textarea is focused, add the āfocusedā event to unhide the keyboard
- If you press enter of the keyboard, the textarea will become āunfocusedā, then you can add a event to hide the keyboard.
I am referring to the keyboard widget. I can understand how to achieve my intended functionality by working with the āFOCUSEDā event, but when I press enter on the keyboard, it just creates a new line rather than defocusing from the text area. If I set the text area to āOne line modeā then pressing enter does not do anything.
The keyboard widget. If I can get the keyboard to defocus after pressing enter, I think I can easily achieve my desired outcome, but I am currently struggling to get that to work.
You should press the āCHECKā symbol (ā) of the keyboard to finish input which will also ādefocusā the text input widget.
Pressing that key also does nothing.
Are you sure?
To hide the keyboard when pressing its Enter key, you can add a VALUE_CHANGE
event to the keyboard, and use a āCall functionā action. In that custom function you can do something like:
lv_obj_t * kb = lv_event_get_target(e);
uint32_t btn_id = lv_keyboard_get_selected_btn(kb);
const char * txt = lv_keyboard_get_btn_text(kb, btn_id);
if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) {
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
Thanks for this. Iāve just realised the elegance of this method (I didnāt know about lv_event_get_target). It means itāll work for any keyboard against which is is called. Thanks!