How to create a swipe left/right event

Important: posts that do not use this template will be ignored or closed.


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

VS simulator

What do you want to achieve?

create a swipe left/right event

What have you tried so far?

I tried to make the Swipe Right Event with event LV_EVENT_PRESSED and LV_EVENT_RELEASED, however only one event can be get in the event callback, so the swipe right event only can be detected at the second swiping.

Code to reproduce

void SwipeRightEventCb(lv_obj_t* obj, lv_event_t* event)
lv_indev_get_point(lv_indev_get_act(), &pointAct);
if (event == LV_EVENT_PRESSED) {
start_x = pointAct.x;
start_y = pointAct.y;
} else if (event == LV_EVENT_RELEASED) {
end_x = pointAct.x;
end_y = pointAct.y;

    lv_coord_t diffX = end_x - start_x;
    lv_coord_t diffY = end_y - start_y;

    if (diffX > abs(diffY) && diffX > 10) {
        printf(" swipe right\n ");


Screenshot and/or video

Could I get some help or suggestion, Thank you.


You can use gestures like this:

void scr_event_cb(lv_obj_t * obj, lv_event_t e)
    if(e == LV_EVENT_GESTURE) {
        lv_gesture_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        printf("Dir: %d\n", dir);


lv_obj_set_event_cb(lv_scr_act(), scr_event_cb);

Note that

  1. gestures are propagated to the screen because gesture_parent is enabled by default (lv_obj_set_gesture_parent())
  2. gestures won’t be sent if the object is dragged
1 Like

when using gestures how to avoid press other obj? I am using V8 version

If the gesture starts on an object with LV_OBJ_FLAG_PRESS_LOCK it will be clicked when the gesture is finished. However, this flag can be disabled to click the objects only if the release has happened exactly on the object.

You can enable LV_OBJ_FLAG_CLICKABLE and LV_OBJ_FLAG_PRESS_LOCK on the background objects (e.g. containers). This way if the gesture was started on a background object it will be kept pressed and the buttons touched meanwhile wont’t be pressed.

Can I use gestures on objects instead of LV_ scr_ act()?

Yes, just disable the LV_OBJ_FLAG_GESTURE_BUBBLE flag on a widget to make it NOT pass the gesture to its parent.