-6

I made a (working) auto clicker and I wanted to add a little modification to it. I want the code to grab the mouse's current position when you call the AutoClick function. Now when it calls the ClickClick function it gets the now current position of the mouse. After that, it snaps the mouse back to the original position (oX, oY) and clicks. After clicking, it jumps to the position the mouse was just at (x, y). The clicking part works, but the mouse doesn't move at all. I have no idea what to do to try to fix it.

^h::AutoClick()

^j::ExitApp

AutoClick(Interval=100){

   MouseGetPos, xpos, ypos

   oX = %xpos%
   oY = %ypos%

   static Toggler

   Toggler := !Toggler

   TPer := Toggler ? Interval : "off"

   SetTimer, ClickClick, %TPer%

   return

   ClickClick:

   BlockInput On
   MouseGetPos, x, y
   MouseMove, %oX%, %oY%, 0
   Click
   MouseMove, %x%, %y%, 0
   BlockInput Off

   return

   }
paisanco
  • 4,098
  • 6
  • 27
  • 33

1 Answers1

1

Fistly, you have some restructuring you need to take care of- Get your Timer's subroutine out of the function. It doesn't belong there; plus it won't be isolated to the function anyway because it's global.

The oX, oY variables are in fact isolated to the function and are therefore only available within that function. Unless you declare them as global.

oX:=oY:=""
^h::AutoClick()
^j::ExitApp

AutoClick(Interval=100){
    global oX, oY
    static Toggler
    MouseGetPos, xpos, ypos
    oX = %xpos%
    oY = %ypos%
    Toggler := !Toggler
    TPer := Toggler ? Interval : "off"
    SetTimer, ClickClick, %TPer%
    return
}

ClickClick:
BlockInput On
MouseGetPos, x, y
MouseMove, %oX%, %oY%, 0
Click
MouseMove, %x%, %y%, 0
BlockInput Off
return

Alternatively, you can have your function return a value (in this case mouse coords) and pass those back to your ClickClick.

fischgeek
  • 688
  • 1
  • 5
  • 18