Add a variable in function parameter Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Add a variable in function parameter

01 Dec 2020, 06:33

I have a code that clicks the specified point.
Coordinates are obtained using ImageSearch but I simplified the example and set it to 100, 200.
I need to press the center of the button, that's why I add +30 and +10 to coordinates:

Code: Select all

x = 100
y = 200
x += 30
y += 10
click, %x%, %y%
Is there any way to refactor it to something like this?

Code: Select all

x = 100
y = 200
click, %x%+30, %y%+10
I also tried this way but failed:

Code: Select all

x = 100
y = 200
click, % x+30, % y+10

Code: Select all

x = 100
y = 200
click, x+30, y+10
I use function Click because only it works correctly in my case.
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Add a variable in function parameter

01 Dec 2020, 06:55

Click, %x%, %y% : Since click does not support expressions, variables should be enclosed in percent signs.
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Add a variable in function parameter

01 Dec 2020, 07:04

Yeah, that's kind of a pain, I agree. Here's another way.

Code: Select all

x := 100
y := 200
MouseMove, x + 30, y + 10
Click
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Add a variable in function parameter

01 Dec 2020, 07:13

Hallo,
or:

Code: Select all

x = 100
y = 200
MouseMove, x, y
Click, 30, 10, Relative
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Add a variable in function parameter  Topic is solved

01 Dec 2020, 07:43

Or even:

Code: Select all

x := 100
y := 200
Click, % x + 30 "," y + 10		; or: Click, % x + 30 " " y + 10
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Add a variable in function parameter

01 Dec 2020, 07:49

Fascinating! I never imagined that one. Thanks to both of you.
Haswell
Posts: 90
Joined: 21 Feb 2016, 17:11

Re: Add a variable in function parameter

01 Dec 2020, 08:15

Wow! Works like a charm!
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Add a variable in function parameter

01 Dec 2020, 10:41

gregster wrote:
01 Dec 2020, 07:43
Or even:

Code: Select all

x := 100
y := 200
Click, % x + 30 "," y + 10		; or: Click, % x + 30 " " y + 10
If you omit the parameter separating real comma, Click will most likely use one of its one-parameter modes. For me it does not just a single click:

Code: Select all

#NoEnv
CoordMode, Mouse, Screen
Return

^+y::
MouseGetPos, X, Y
Click, % x + 30 "," y + 30		; or: Click, % x + 30 " " y + 30
Return
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Add a variable in function parameter

01 Dec 2020, 10:43

How do you mean? All commas are optional with Click.
For me it does not just a single click
What does it do for you?
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Add a variable in function parameter

01 Dec 2020, 11:00

I am enthusiastic! Even this works:

Code: Select all

x := 100
y := 200
Click,% (x += 30) "," y += 10
just me
Posts: 9456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Add a variable in function parameter

01 Dec 2020, 11:31

Hmmm, I think I fell in this trap before. I overlooked
Separate each item from the next with at least one space, tab, and/or comma.
So all parameters seem to be read as one.

While testing in a Notepad window this 'Click' is selecting text here if the mouse cursor is on text. But after further testing, this seems to happen with Click, %X%, %Y% too.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Add a variable in function parameter

01 Dec 2020, 11:46

MouseClick
X, Y
The x/y coordinates to which the mouse cursor is moved prior to clicking, which can be expressions
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Add a variable in function parameter

01 Dec 2020, 11:54

Good point. I don't use that much due to
The Click command is generally more flexible and easier to use.
but of course, it could be a perfect choice here!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat, songdg and 291 guests