Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move mouse with javascript

I am trying to do simple mouse move with javascript but I am unable to do it and dont know what is wrong.

function doMove(){
    let element = document.getElementById('root');

    let eventMouseDown = new MouseEvent("mousedown", {
        clientX: window.innerWidth/2,
        clientY: window.innerHeight/2
    });
    let eventMouseMove = new MouseEvent("mousemove", {
        clientX: (window.innerWidth/2)+50,
        clientY: window.innerHeight/2
    });
    let eventMouseUp = new MouseEvent("mouseup", {
        clientX: (window.innerWidth/2)+50,
        clientY: window.innerHeight/2
    });

    element.dispatchEvent(eventMouseDown);
    element.dispatchEvent(eventMouseMove);
    element.dispatchEvent(eventMouseUp);
}

First I put mouse down then move and then realease which should simulate me moving with mouse on map for example. How can I make it work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t move mouse using JavaScript in the website. Imagine that you are opening a website and it takes control over your mouse.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading