How to avoid EVENT_CLICK when changing screens

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

STM32F7xx

What LVGL version are you using?

7.1

What do you want to achieve?

I have a screen with a button that has to be hold in order to go to another screen. When I process the hold event, I create the new screen, but the new screen has a button in the same position as the previous button, and then a CLICK event is called in the new button because the touch has not been released yet.

Is there any way to avoid this? In this page there has not been any new pressings, so the CLICK should not be called. Any way to avoid this?

Alex

You can try setting LV_PROTECT_PRESS_LOST on the button.

Hi,

thanks for the tip. I have tested it, but does not fix my problem. After the PRESS time, the button executes the code, creates the new screen, and the button of the new screen is pressed.

If I change the PROTECT_PRESS_LOST, it changes the way the button behaves (still is pressed when you move the finger), so the protection is enabled, but does not fix my problem. I suspect that this problem will happen every time I hold and change the screen.

In my opinion, a new created screen should check if the touch is pressed when is created, and in this case should not listen to touch pressings until the touch is released, but I think this is difficult to change right now.

Alex

This happens to me also, for example, if I open a mesage box when pressing a button. I have a button in the middle of the screen, yhat has bo be hold to activate a function. When I hold it, I create a msgbox with a “OK” button to inform of the change, but as soon as the msgbox is created, the OK button is pressed, because the user still has the finger on the screen. In my opinion, the object should check if it is pressed on creation, and wait until depressed to accept touch events…

Alex

In this case you need to call lv_indev_wait_release(NULL) when creating the new objects.

1 Like

That works! That is what I was searching for. Thank you.

I’ve had to change the NULL for a pointer to the touch device, but then it works.

The only little thing that happens is that if I press a button, and then I create the msgBox (with the lv_indev_wait_release), when I release the touch the button pressed at the beginning does not return to normal state. Even after deleting the msgBox (by timeout), the button remains pressed. It changes to correct state after pressing the screen again. It’s not a big deal, but I don’t know if this is how it should work.

Thanks for the help

Alex

I’m not sure, but perhaps it’s because of my suggestion to enable LV_PROTECT_PRESS_LOST. It may not be necessary with @kisvegabor’s fix.

I’m not sure, but perhaps it’s because of my suggestion to enable LV_PROTECT_PRESS_LOST . It may not be necessary with @kisvegabor’s fix.

No, it’s not the case. This setting is not activated (I tested but I saw it did not do what I wanted).

Thank you

Alex

Oh, true. In some cases NULL means “apply to all indev” but here the indev needs to be set explicitly.