1

This is what I have so far:

for(var i;i< 99999;i++){
  if(mouse.x == element.x,mouse.y == element.y){
    element.click
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
ORION TYO
  • 11
  • 5
  • 1
    Does this answer your question? [How to simulate a click by using x,y coordinates in JavaScript?](https://stackoverflow.com/questions/3277369/how-to-simulate-a-click-by-using-x-y-coordinates-in-javascript) – Emmanuel Dec 19 '21 at 23:42
  • 3
    Please add an explanation as of what you are trying to do here. – connexo Dec 19 '21 at 23:42
  • @connexo I assume simulate click at mouse position – Emmanuel Dec 19 '21 at 23:44
  • yes simulate click at mouse position – ORION TYO Dec 19 '21 at 23:51
  • but you can loop to make an auto clicker – ORION TYO Dec 19 '21 at 23:52
  • Why would you do that? What's your larger purpose here? If you want to take some action when the mouse hovers over a control, you can use `mouseover` for that (as @Bulog shows), but just forcing the mouse to click arbitrarily is a terrible user experience. – Tim Roberts Dec 19 '21 at 23:53
  • If you're running Javascript, then this is a web page you control. In that case, you don't have to "simulate" actions at all. You can call whatever functions you want to call. – Tim Roberts Dec 19 '21 at 23:55
  • yes @Emmanuel it dose – ORION TYO Dec 19 '21 at 23:56

2 Answers2

1

use window.mouseover to listen the mouse event

var item;
window.addEventListener("mouseover", function( event ) {
  // the mouseover target
  item = event.target;
}, false);

// now you can use the item
Bulog
  • 79
  • 2
0
window.addEventListener("click", spawn);

function spawn(e){
  console.log(e.clientX);
  console.log(e.clientY);
}

click anywhere in the window...

Ghoyos
  • 604
  • 2
  • 7
  • 18