How to achieve mouse input dev?


In my project, I want to achieve the function which is when mouse pressing or long-pressed, the trerminal can print the position of current mouse.

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


What LVGL version are you using?


What do you want to achieve?

In the demo function “lv_port_indev_init();”, I want to know how to fill the mouse_read, mouse_get_xy and mouse_pressed three function

What have you tried so far?

search on internet

Code to reproduce

void input_mouse(void)
    //lv_group_t* group1 = lv_group_create();
    /*Initialize your mouse if you have*/

    /*Register a mouse input device*/
    lv_indev_drv_init(&indev_drv); //初始化结构体
    indev_drv.type = LV_INDEV_TYPE_POINTER;//输入设备类型,当前为鼠标
    indev_drv.read_cb = mouse_read;//回调函数,用于定期(几乎实时)获取输入设备的数据
    indev_mouse = lv_indev_drv_register(&indev_drv);//注册输入设备
    //lv_indev_set_group(indev_mouse, group1);

    /*Set cursor. For simplicity set a HOME symbol now.*/
    lv_obj_t* mouse_cursor = lv_img_create(lv_scr_act()); //创建光标对象  
    lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME); //设置光标图像的来源
    lv_indev_set_cursor(indev_mouse, mouse_cursor);//链接显示驱动


static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
    /*Get the current x and y coordinates*/
    mouse_get_xy(&data->point.x, &data->point.y);
    LV_LOG_ERROR("x = %d , y=%d\n", data->point.x, data->point.y);

    /*Get whether the mouse button is pressed or released*/
    if(mouse_is_pressed()) {
        data->state = LV_INDEV_STATE_PR; 
    else {
        data->state = LV_INDEV_STATE_REL;

static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
    /*Your code comes here*/
    //(*x) = indev_mouse->proc.types.pointer.act_point.x;
    //(*y) = indev_mouse->proc.types.pointer.act_point.y;

    (*x) = 0;
    (*y) = 0;
    //LV_LOG_ERROR("The mouse is now at x:%d y%d \n", *x, *y);

static bool mouse_is_pressed(void)
    /*Your code comes here*/
   //if (indev_mouse->proc.state == LV_INDEV_STATE_PRESSED)
   //    return 1;
    return false;

Screenshot and/or video

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

I think, the indev_mouse->proc.types.pointer.act_point.x; should have value if my code run well, but it is zero.

Also, lv_indev_drv_register
→ lv_indev_read_timer_cb → indev_pointer_proc → indev_proc_press , when I open the printf, the terminal could print the pos of mouse while I pressing the mouse on screen. I want to know is there any relationship between indev_proc_press and mouse_read?