Mouse movment - how to ? - Error: Can't open display: (null)

Hi,
wanna move the mouse 2px left, 2px right
in a loop.

here a example I found and modiy but got error: Error: Can't open display: (null)



use mouse_rs::{types::keys::Keys, Mouse};

fn main() {
    loop  {
        move_and_press();        
    }
}


fn move_and_press() {
    let mouse = Mouse::new();
    mouse.move_to(500, 500).expect("Unable to move mouse");
    mouse.move_to(-500, -500).expect("Unable to move mouse");


}

What did I wrong ?

If you are running it on Linux, mouse-rs uses libxdo passing NULL to xdo_new(), which has this in its documentation:

xdotool/xdo.h at 33092d8a74d60c9ad3ab39c4f05b90e047ea51d8 ยท jordansissel/xdotool

If null, uses the environment variable DISPLAY just like XOpenDisplay(NULL).

Have you set the DISPLAY environment variable?

export DISPLAY=':0'

yes the display var is set...

I played a bit.... with this CODE it work... for me so far

use std::thread::sleep;

use mouse_rs::{types::keys::Keys, Mouse};
use std::{time};
fn main() {
    


    loop  {
            sleep(time::Duration::from_millis(60000));
            move_and_press();        
    }
}


fn move_and_press() {
    let mouse = Mouse::new();
    mouse.press(&Keys::MIDDLE).expect("Unable to press button");
    mouse.release(&Keys::MIDDLE).expect("Unable to release button");

}