How do I get widget button value pressed seen by my Arduino code?

I am running the lv_ex_btnmatrix_1 example with Arduino.(compiled with the Arduino IDE)

The example creates a keypad. When a button is pressed the button value (txt) is printed.
How do I get the value of the button (in txt) accessible in my code?

I assume that I could copy txt to a global variable, but I always get an error.

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

What LVGL version are you using? 7

What do you want to achieve? Make the value of txt available to my code in the loop().

What have you tried so far?

keyValue = txt;

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

static void event_handler(lv_obj_t * obj, lv_event_t event)
    if(event == LV_EVENT_VALUE_CHANGED) {
        const char * txt = lv_btnmatrix_get_active_btn_text(obj);

        printf("%s was pressed\n", txt);

static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
                                  "6", "7", "8", "9", "0", "\n",
                                  "Action1", "Action2", ""};

void lv_ex_btnmatrix_1(void)
    lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL);
    lv_btnmatrix_set_map(btnm1, btnm_map);
    lv_btnmatrix_set_btn_width(btnm1, 10, 2);        /*Make "Action1" twice as wide as "Action2"*/
    lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
    lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECK_STATE);
    lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_event_cb(btnm1, event_handler);


Screenshot and/or video

If possible, add screenshots and/or videos about the current state.