Hide keyboard on pressing "enter"

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);
1 Like