ControlClick & ImageSearch coordinates offset. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Mr Mojo
Posts: 12
Joined: 06 Jul 2017, 14:12

ControlClick & ImageSearch coordinates offset.

Post by Mr Mojo » 24 May 2023, 19:46

Is there anyway of using a negative offset when it comes to ControlClick coordinates, without declaring variables first?

Code: Select all

loop
{
imagesearch, x, y, 0, 0, A_Screenwidth, A_Screenheight, *50 c:\temp\test.bmp
if errorlevel = 0
break
}
ControlClick, x%x-351% y%y+27%,,, right, 1, pos NA,,
goto, end
Thanks in advance to a great community!
- Mr Mojo :D


[Mod action: Moved topic to v1 section. The main section is for v2.]

[Mod edit: Changed code box from .txt type to .ahk type.]

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: ControlClick & ImageSearch coordinates offset.  Topic is solved

Post by boiler » 24 May 2023, 19:54

Use % followed by a space to force an expression for a parameter that is otherwise expected to use command syntax:

Code: Select all

ControlClick, % "x" (x-351) " y" (y+27),,, right, 1, pos NA

User avatar
Mr Mojo
Posts: 12
Joined: 06 Jul 2017, 14:12

Re: ControlClick & ImageSearch coordinates offset.

Post by Mr Mojo » 25 May 2023, 11:12

Thanks Boiler, all I needed was just one answer from a knowledgeable person.

Thanks again, problem solved!

-Mr Mojo :bravo:

User avatar
Mr Mojo
Posts: 12
Joined: 06 Jul 2017, 14:12

Re: ControlClick & ImageSearch coordinates offset.

Post by Mr Mojo » 01 Jun 2023, 19:23

Hey Boiler!

Perhaps my reply was a bit too fast, see below for my complete script. The aim is to look for image Test.bmp, which is the "I'm Feeling Lucky" button on the Goolgle homepage, if found, show ToolTip acknowledging it was found, and then , using your provided answer, ControlClick in the center, in relation to the X & Y of the image found. Hélas, it does not work. Attached is a link to the Google homepage.
https://www.google.com/

Code: Select all

#WinActivateForce
SetTitleMatchMode 2
setcontroldelay, -1

gosub, progman
gosub, mousecenter
sleep, 1500

ifwinexist, Mozilla Firefox
winactivate, Mozilla Firefox
winwaitactive, Mozilla Firefox
sleep, 1000

loop, 5
{
ImageSearch, X, Y, 0, 0, A_screenwidth, A_Screenheight, *15 c:\temp\test.bmp
if errorlevel = 0
goto, found
}

	found:
ToolTip, Image Found :), A_Screenwidth/2, A_Screenheight*0.25
sleep, 3000
tooltip
sleep, 1500
controlclick, % "x" (x+67) "y" (y+15),,, left, 1, NA Pos,,
goto, end

; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	progman:
loop
{
winminimizeall
WinActivate, ahk_class Progman
controlfocus,, ahk_class Progman
ifwinactive, ahk_class Progman
break
else continue
}
return

	mousecenter:
mousemove, A_screenwidth/2, A_Screenheight*0.35
return

esc::goto, end
Pause::Pause

	end:
mousemove, A_Screenwidth/2, A_Screenheight/2
gui, destroy
loop, 5
{
Progress, b fm12 zh0 w100 zy0 ZX0 wm1000 cwff0000,, EXITING SCRIPT!,, arial black
sleep, 125
progress, off
sleep, 125
}
exitapp
Maybe something wrong with the syntax, not sure. Hopefully you can provided some help, and as always, it will be greatly appreciated.

Regards

Mr Mojo


[Mod edit: Changed code box from .txt type to .ahk type.]

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: ControlClick & ImageSearch coordinates offset.

Post by boiler » 01 Jun 2023, 20:15

Please make your code boxes of .ahk type, not .txt type. The code box button that produces just “code” tags will use the default .ahk type, or you can choose it from the dropdown.

Mr Mojo wrote: using your provided answer, ControlClick in the center, in relation to the X & Y of the image found. Hélas, it does not work.
No, you didn’t use my answer. For some reason, you removed the space before the y, so that results in (for example) x100y200 instead of x100 y200.

User avatar
Mr Mojo
Posts: 12
Joined: 06 Jul 2017, 14:12

Re: ControlClick & ImageSearch coordinates offset.

Post by Mr Mojo » 01 Jun 2023, 22:11

Boiler,
My bad for doubting you, I initially thought that the space between the quotation marks and the Y was a typo on your part. Turns out it was a wrong assumption on my part, and just plain noob ignorance. I tested it and it works like a charm.

Thanks for your patience and the rapidity in responding, I shall not assume anymore.

Thanks again! :beard:

Regards

- Mr. Mojo

Post Reply

Return to “Ask for Help (v1)”