Lv_keyboard doesn't work

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

I run lv_keyboard but when I click the keyboard it doesn’t print anything on the textarea . Can anyone tell me why???

What MCU/Processor/Board and compiler are you using?

LVGL simulator (Visual Studio)

What LVGL version are you using?

7.9.1

What do you want to achieve?

Print a character when I click the keyboard.

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

#include "../../../lv_examples.h"
#include <stdio.h>

#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name;

static void kb_create(void);
static void ta_event_cb(lv_obj_t* ta, lv_event_t event);
static void signal_speed_create(void);
static const char* btn_map[] = { "Back", "Home", "Menu","" };
static lv_obj_t* kb;
static lv_obj_t* ta;

void lv_test_btnmatrix()
{
    lv_obj_t* btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
    lv_btnmatrix_set_map(btnm1, btn_map);

    lv_obj_align(btnm1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);

    lv_obj_t* signal = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(signal, LV_SYMBOL_WIFI);
    lv_obj_align(signal, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);

    lv_obj_t* battery = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(battery, LV_SYMBOL_BATTERY_FULL);
    lv_obj_align(battery, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);

    lv_obj_t* clock = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(clock, "17:00");
    lv_obj_align(clock, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

    lv_obj_t* ID = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(ID, "101");
    lv_obj_align(ID, battery, LV_ALIGN_IN_TOP_RIGHT, 0, 20);

    signal_speed_create();

}

static void kb_create(void)
{
    /*Create the custom map for the keyboard*/
    static const char* kb_map[] = {
        "1", "2", "3",LV_SYMBOL_BACKSPACE,"\n",
        "4", "5", "6",LV_SYMBOL_CLOSE,"\n",
        "7", "8", "9"," ","\n",
        "0", LV_SYMBOL_LEFT, LV_SYMBOL_RIGHT," ",""
    };

    static const lv_btnmatrix_ctrl_t kb_ctrl[] = {
        LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT,
        LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT,
        LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_HIDDEN,
        LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_HIDDEN
    };

    /* Create a keyboard*/
    kb = lv_keyboard_create(lv_scr_act(), NULL);
    lv_obj_set_size(kb, LV_HOR_RES/2, LV_VER_RES / 3);
    lv_obj_align(kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
    lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUM);
    lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_NUM, kb_map);
    lv_keyboard_set_ctrl_map(kb, LV_KEYBOARD_MODE_NUM, kb_ctrl);
    lv_keyboard_set_textarea(kb, ta);
}

static void ta_event_cb(lv_obj_t* ta, lv_event_t event)
{
    if (event == LV_EVENT_CLICKED) {
        kb_create();
    }
}

static void signal_speed_create(void)
{
    /*Create the text area*/
    lv_obj_t* ta = lv_textarea_create(lv_scr_act(), NULL);
    lv_obj_set_event_cb(ta, ta_event_cb);
    lv_textarea_set_accepted_chars(ta, "0123456789");
    lv_textarea_set_one_line(ta, true);
    lv_textarea_set_text(ta, "");
    lv_obj_align(ta, NULL, LV_ALIGN_CENTER, 0, 0);
}

Thanks,
Best regards,

You’re redeclaring ta inside signal_speed_create so the global is never initialized. I suggest enabling shadowing warnings if your compiler has them.

omg sr for my late reply. Tks did it. Because I copy the code from another code so I forget this thing. Tks a lot.
Best regards,