LVGL With external keypad

what values did you get with lv_indev_get_key()?

The key I get is correct, that is the key I have supposed to get, then I remove 160 from it to get ascii code.

@kisvegabor
I think I have found something strange.
If I add to textarea that is not focused or selected in this case, It is ok, but if I want to add to the selected textarea, it doesnt happen. Had I made a mistake or is it something with textarea library? This is happening with keypad. (Not the keyboard widget)

Do you see the results of the printf-s in the event?

@kisvegabor Here is the code I have used to find the addresses.

static void ta_key_event(lv_event_t * e)
{
	lv_obj_t * ta = lv_event_get_target(e);
	uint8_t key = lv_indev_get_key(lv_indev_get_act()) - 160;
	if (key>='0' && key<='9')
		lv_textarea_add_char(ta, key);
	printf("\nget address:0x%x\n",ta);
	printf("ta1 address:0x%x\n",window_Login.textareaPassword);
	printf("ta2 address:0x%x\n",window_Login.textareaNewPassword);
	printf("ta3 address:0x%x\n",window_Login.textareaOldPassword);
}

and here is the resault

get address:0x2001014c
ta1 address:0x2001014c
ta2 address:0x200162f0
ta3 address:0x20016500

get address:0x200162f0
ta1 address:0x2001014c
ta2 address:0x200162f0
ta3 address:0x20016500

get address:0x20016500
ta1 address:0x2001014c
ta2 address:0x200162f0
ta3 address:0x20016500

It seems you get the Text areas correctly. So the only issue can be that the character is not added for some reason. What if you change this

	if (key>='0' && key<='9')
		lv_textarea_add_char(ta, key);

to

	//lv_textarea_set_cursor_pos(ta, 0); //try this too
	lv_textarea_add_char(ta, 'A');

Dear @kisvegabor
I have changed my code with your suggestion to

	uint8_t pos = lv_textarea_get_cursor_pos(ta)-1;
	lv_textarea_set_cursor_pos(ta, pos);

	if ((key >= '0') & (key <= '9'))
		lv_textarea_add_char(ta, key);

Now it does work, formerly I have used the LVGL keyboard with touch screen and there was no problem, but what is the problem with external keypad? Had I made a mistake in driving keypad or is it something with LVGL that should be changed?

Finally are these 2 lines solved the issue?

	uint8_t pos = lv_textarea_get_cursor_pos(ta)-1;
	lv_textarea_set_cursor_pos(ta, pos);

If so I don’t know why. The textarea examples in the docs are working with keyboard too, and they are really working :slight_smile:

@kisvegabor these two lines solved my problem, but I wondered why there were needed, had I made mistake in the way of sending key messages to lvgl or is it something that should be redesigned in lvgl? The matter is the problem is not with keyboard.
The problem is wigh keypad!

I have no idea unfortunately. I could tell more only by looking into the exact code and execution with a debugger :frowning:

Let’s the cursor setting workaround for now.