Help with using a variable in ControlClick pos

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsiqueira
Posts: 4
Joined: 15 Apr 2021, 16:05

Help with using a variable in ControlClick pos

19 Jun 2021, 10:23

Hello everyone!

I have this piece of script that words just fine, but I want change it to use variables to quick change the coordinates used in the controlclick:

Code: Select all

SetMouseDelay,-1
SetKeyDelay,-1
Setdefaultmousespeed,0

^Esc::Exitapp
Del::pause


Home::
Loop {
 Loop 50 {
     ControlClick, X1777 Y531, ahk_exe client.exe, , , , D
     ControlClick, X1815 Y804, ahk_exe client.exe, , , , U
     Sleep 400
     ControlClick, X1815 Y804, ahk_exe client.exe, , , , D
     ControlClick, X1777 Y807, ahk_exe client.exe, , , , U
     Sleep 400
 }  
 Sleep 400
 ControlClick, X1777 Y807, ahk_exe client.exe, , , , D
 ControlClick, X1813 Y739, ahk_exe client.exe, , , , U
 Sleep 400
}
I tried to use varibles but it isnt working and I cant find anything on the forum to help me out:

Code: Select all

SetMouseDelay,-1
SetKeyDelay,-1
Setdefaultmousespeed,0
^Esc::Exitapp
Del::pause

SearchSlot = X1777 Y531
ContainerSlotOne = X1777 Y807
ContainerSLotTwo = X1815 Y804
DepotSlot = X1813 Y739

Home::
Loop {
 Loop 50 {
     ControlClick % ", " . SearchSlot . ", ahk_exe client.exe, , , , D Pos"
     ControlClick % ", " . ContainerSLotTwo . ", ahk_exe client.exe, , , , U Pos"
     Sleep 400
     ControlClick % ", " . ContainerSLotTwo . ", ahk_exe client.exe, , , , D Pos"
     ControlClick % ", " . ContainerSlotOne . ", ahk_exe client.exe, , , , U Pos"
     Sleep 400
 }  
 Sleep 400
 ControlClick % ", " . ContainerSlotOne . ", ahk_exe client.exe, , , , D Pos"
 ControlClick % ", " . DepotSlot . ", ahk_exe client.exe, , , , U Pos"
 Sleep 400
}
OBS: I has to be controlclick because I need this to perform on the background, out of focus.

Thanks!
User avatar
mikeyww
Posts: 27049
Joined: 09 Sep 2014, 18:38

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 10:39

This example may help.

Code: Select all

SearchSlot = X162 Y74
ControlClick, %SearchSlot%, ahk_exe notepad.exe
Another one:

Code: Select all

ControlClick, % SearchSlot, ahk_exe notepad.exe,,,, D Pos
dsiqueira
Posts: 4
Joined: 15 Apr 2021, 16:05

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 11:30

mikeyww wrote:
19 Jun 2021, 10:39
This example may help.

Code: Select all

SearchSlot = X162 Y74
ControlClick, %SearchSlot%, ahk_exe notepad.exe
Another one:

Code: Select all

ControlClick, % SearchSlot, ahk_exe notepad.exe,,,, D Pos
Those also doesnt works :(
User avatar
mikeyww
Posts: 27049
Joined: 09 Sep 2014, 18:38

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 11:38

Test in Notepad, because it works there. You may be misunderstanding the command.
If there is a control at the specified coordinates, it will be sent the click-event at those exact coordinates. If there is no control, the target window itself will be sent the event (which might have no effect depending on the nature of the window).
Feel free to post your revised script.

You can also test the following.

Code: Select all

SearchSlot = X1777 Y531
Home::
MouseMove, 1777, 531
ControlClick, %SearchSlot%, ahk_exe client.exe,,,, D Pos
Return
If it does not work, how do you know that it did not work? You can also check KeyHistory. See doc about the NA option, which you could also try.
Sally2Q
Posts: 43
Joined: 16 Jun 2021, 10:18

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 11:50

i confirm that this works

Code: Select all

 co2= x273 y519 
 ControlClick, %co2%  ,  *Untitled - Notepad
dsiqueira
Posts: 4
Joined: 15 Apr 2021, 16:05

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 12:01

mikeyww wrote:
19 Jun 2021, 11:38
Test in Notepad, because it works there. You may be misunderstanding the command.
If there is a control at the specified coordinates, it will be sent the click-event at those exact coordinates. If there is no control, the target window itself will be sent the event (which might have no effect depending on the nature of the window).
Feel free to post your revised script.

You can also test the following.

Code: Select all

SearchSlot = X1777 Y531
Home::
MouseMove, 1777, 531
ControlClick, %SearchSlot%, ahk_exe client.exe,,,, D Pos
Return
If it does not work, how do you know that it did not work? You can also check KeyHistory. See doc about the NA option, which you could also try.
I know its not working because i've run the script and its not doing whats suppose to do, like the first script with hardcoded coordinates.
About the mousemove, I dont want to use it, because that script is suppose to run on the background, without interfering with the mouse and other applications.

The main problem for me is using the variable in the controlclick. The first script with hardcoded coordinates if fully functional, but when i try to use variables inside de controlclick, i wont work.
User avatar
boiler
Posts: 17044
Joined: 21 Dec 2014, 02:44

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 12:25

The approach shown for replacing the hard-coded values with variables is correct. If your original script worked, the only reason your version with variables wouldn’t have worked is that some error was made in implementing it. I suggest you post your entire new script using variables that is meant to be equivalent of the first script you posted.
User avatar
mikeyww
Posts: 27049
Joined: 09 Sep 2014, 18:38

Re: Help with using a variable in ControlClick pos

19 Jun 2021, 12:44

The mouse move was just a demo to show you where the coordinates are-- but I admit that these will be wrong if your target window is not active.

Although some programs might not respond to a ControlClick, since you indicated that your original script actually does work in your target program, I agree with boiler.

It also seems possible that the script is working, but you do not realize it. My question remains about how you know that the new script does not execute as programmed.

The following script will show you which lines execute. You can test it by changing the WinTitle to your target program.

Code: Select all

SearchSlot = X1777 Y531
wTitle = ahk_exe notepad.exe
Home::
If WinExist(wTitle) {
 WinActivate ; A test
 MouseMove, 1777, 531
 ControlClick, %SearchSlot%, %wTitle%,,,, D Pos
 ControlClick, %SearchSlot%, %wTitle%,,,, U Pos
 SoundBeep, 1500
} Else MsgBox, 48, Error, Window not found.`n`n%wTitle%
ListLines
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, MrDoge, Rohwedder and 330 guests