1

i have a auto clicker that work with mouse position . here is the code :

var elem = document.elementFromPoint( x,y );

elem.addEventListener('click', function() {
    console.log('clicked')
}, false);

var support = true;

try {
    if (new MouseEvent('click', {bubbles: false}).bubbles !== false) {
        support = false;
    } else if (new MouseEvent('click', {bubbles: true}).bubbles !== true) {
        support = false;
    }
} catch (e) {
    support = false;
}

setInterval(function() {
    if (support) {
        var event = new MouseEvent('click');
    }else{
        var event = document.createEvent('Event');
        event.initEvent('click', true, true);
    }
    elem.dispatchEvent(event);
},1000);

and i also have code for get mouse position :

var cursorX;
var cursorY;
document.onmousemove = function(e){
    cursorX = e.pageX;
    cursorY = e.pageY;
}
setInterval("checkCursor()", 1000);
function checkCursor(){
   alert( cursorX + ","+ cursorY);
}

and my questions is : how can i put mouse position in document.elementFromPoint(x,y ) ????

i know can put my x and y but i want to x and y update when i move mouse anywhere

  • Possible duplicate of [Triggering a JavaScript click() event at specific coordinates](http://stackoverflow.com/questions/2845178/triggering-a-javascript-click-event-at-specific-coordinates) – Rayon Mar 03 '16 at 11:14
  • i know can put my x and y but i want to x and y update when i move mouse anywhere – Mehrshad Farahani Mar 03 '16 at 11:36

1 Answers1

1

Edit

You actually need to initialize elem and cursorX and cursorY first, sorry, didn't test this code.

Declare elem as a variable var elem = document.elementFromPoint( cursorX,cursorY );

And initialize cursors cursorX = 0; cursorY = 0

Then inside your mousemove function, do this

document.onmousemove = function(e) {
   cursorX = e.pageX;
   cursorY = e.pageY;
   elem = document.elementFromPoint(e.pageX, e.pageY);
}
JB06
  • 1,881
  • 14
  • 28