I need to make it so that every time a certain image appears on my screen a mouse will automatically click at specific coordinates (the same coordinates every time). I know I'm going to need > ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile and > Click X, Y
I'd like to be able to start the continuous loop by pressing r and end it by pressing t.
What I'm wondering is how I could put this into a loop to run continuously? I'm new to coding and I'm not sure how it should look. If someone could help me that would be super
How to setup this simple script?
Re: How to setup this simple script?
Let's guess quite similar to these (already answered) requests?!I'm new to coding and I'm not sure how it should look.
https://autohotkey.com/boards/viewtopic.php?t=4544
What I'm wondering is how I could put this into a loop to run continuously?
Code: Select all
Loop {
ToolTip "I'm wondering is how I could put this into a loop to run continuously?"
Sleep, 300
ToolTip
}
Code: Select all
r::MsgBox % "Start"
t::ExitApp
Re: How to setup this simple script?
In case you still needed help here is a working script with comments you may find helpful
Code: Select all
x1 := 0 ;rectangle to search for image, this will seach 0,0 to screenwidth,screenheight (entire screen)
y1 := 0
x2 := A_ScreenWidth
y2 := A_ScreenHeight
clickX := 500 ;coordinates to click when image is found
clickY := 500 ;because of coordmode below, it will be 500,500 relative to screen
coordmode,pixel,screen ;sets pixel and mouse coords to be relative to screen and not the active window
coordmode,mouse,screen ;delete these 2 lines if you want coordinates to be relative to window, also update x1,y1 etc.
r:: ;hotkey to start loop
toggle := true
while (toggle) { ;while toggle == true/1
ImageSearch, foundX, foundY, %x1%, %y1%, %x2%, %y2%, *15 imageFile.png ;*15 means there can be 15 shades variation difference
if (errorlevel == 0) { ;0 = image found, 1 = not found, 2 = could not perform search
click,%clickX%,%clickY%
sleep 1000 ;sleep 1 second, not needed
;break ;uncomment this if you want to stop the loop if found
}
sleep 100
}
return
*t::
toggle := false ;setting toggle to false will break the while loop
return
f8::exitapp ;when dealing with loops and automated clicks, it's best to have a hotkey to exitapp
f9::reload ;reload is useful when you are making changes to your script
Some of my AHK programs: 3D Voxel Game - Platformer Game
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
GitHub projects : Image/Pixel scanning class - Direct2D overlay class
Who is online
Users browsing this forum: Google [Bot], Lamron750 and 373 guests