The LV_EVENT_KEY is sent continuously after I press a key

Environment: LVGL8 with the windows simulator.

I want to create a event call back on a object so that a animation can be started when I press a key. So I added a event call back like this:

lv_obj_add_event_cb(scr, keyPadCallBack, LV_EVENT_KEY, NULL);

void keyPadCallBack(lv_event_t* e) {
uint32_t key = lv_event_get_key(e);
if (key == LV_KEY_UP) {
if (currentIndex > 0) {
currentIndex–;
}
}
else if (key == LV_KEY_DOWN) {
if (currentIndex < 9) {
currentIndex++;
}
}
}

The call back function is successfully called when I press a key, but after that the program keeps call the call back function even if I didn’t press any key.

Environment: LVGL8.3 with the windows simulator.

I want to catch the ESC key to terminate the simulator application.

I even cannot get the callback called. With LV_EVENT_ALL the callback works, but with LV_EVENT_KEY the callback cannot trigger.

lv_obj_t* screen_active = lv_scr_act();
lv_obj_add_event_cb(screen_active, my_event_key_cb, LV_EVENT_ALL, NULL);

Please could anyone guide me how to get simulator trigger an ESC keypress in the main window.

I now can successfully get the key by changing the current screen into the inner object in my case is the TabView1. The following code displays the key and quit the app when key = ESC. No continuously occurs, the callback triggered only once.

static void my_event_key_cb(lv_event_t* event)
{

lv_indev_t* i = lv_indev_get_act();

uint32_t key = 0;
if (i) key = lv_indev_get_key(i);

std::cout << "key: " << key << std::endl;

if (key == 27) lv_win32_quit_signal = true;

}

lv_obj_add_event_cb(ui_TabView1, my_event_key_cb, LV_EVENT_KEY, NULL);