Selecting Buttons From Code

i had the misfortune of adding functionalities to a big project.
i need to simulate clicking on a button from code but apparently there is no api for that unless i use internal lvgl things. can anyone tell me how to achieve this?

How does your application reacts to buttons clicks?

it seems the original dev only used buttons for navigable and highlight-able aspect of buttons. he added callbacks to them. now enter(return) key works fine for selecting them and one of the keys in hardware had been defined as return. now i want to also have a dynamic button that can work as a select button. i managed to get the btn object but still cant simulate clicking on it. only way i found is that every time i set a callback i should also add pointer to callback function into user data. it doesn’t feel right though.

It depends on what kind of input device you want to use. Let’s be clear what we’re talking about - physical buttons or button widget. If you mean widget - so it’s not possible to add calback to it, you can add callback to event. And when you manipulate with widgets some events may occur that may cause the corresponding callback to be called. So if you need to simulate click on widget from application just use lv_obj_send_event() for widget you need.

1 Like