How to setup this simple script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lemondrop
Posts: 1
Joined: 16 Jul 2017, 22:09

How to setup this simple script?

16 Jul 2017, 22:16

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
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to setup this simple script?

17 Jul 2017, 00:40

I'm new to coding and I'm not sure how it should look.
Let's guess quite similar to these (already answered) requests?!
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
User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: How to setup this simple script?

17 Jul 2017, 12:08

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Lamron750 and 373 guests