Variables for commands

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
loggerhead
Posts: 9
Joined: 09 May 2016, 19:39

Variables for commands

12 Jul 2016, 23:56

I'm curious if somebody could help me define some variables in my script. I want to define a variable at the beginning that will be called through various hotkey commands. The reason is that I am doing a lot of mouseclick commands, and they will be used on different computers with different screen resolutions and I want to have just a quick location to change all the x,y coordinates.

For instance:

:*:test1::
Mouseclick, left, 100, 200 ; variable 1
Mouseclick, left, 300, 400 ; variable 2
Send, test1
return

:*:test2::
Mouseclick, left, 100, 200 ; variable 1
Mouseclick, left, 500, 600 ; variable 3
Send, test2
return

:*:test3::
Mouseclick, left, 300, 400 ; variable 2
Mouseclick, left, 500, 600 ; variable 3
Send, test3
return


I would want it look like:
:*:test1::
Mouseclick, left, variable 1
Mouseclick, left, variable 2
Send, Test 1
return
:*:test2::
Mouseclick, left, variable 1
Mouseclick, left, variable 3
Send, test 2
return
:*:test3::
Mouseclick, left, variable 2
Mouseclick, left, variable 3
send, test 3
return

Thanks!
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Variables for commands

13 Jul 2016, 00:04

each individual parameter needs to be its own variable, so you will end up with 6 variables, not 3

so for example:

Code: Select all

x1 := 100
y1 := 200
Mouseclick, left, %x1%, %y1%
see here, read this page:
https://autohotkey.com/docs/Variables.htm

take a try doing the rest yourself, and post your code that you come up with

loggerhead
Posts: 9
Joined: 09 May 2016, 19:39

Re: Variables for commands

15 Jul 2016, 08:46

Having issues.

;;Click Ad Hoc
adhoc_x = 1120
adhoc_y = 94



:*:---::
MouseClick, left, adhoc_x , adhoc_y
Sleep, 1500
MouseClick, left, 86, 83
Sleep, 300
MouseCLick, left, 319, 240
MouseClick, left, 1038, 601
Return
loggerhead
Posts: 9
Joined: 09 May 2016, 19:39

Re: Variables for commands

15 Jul 2016, 11:50

OK, so the issue is that the variable is not contained within the autokey command. For instance, this works fine:

:*:---::
adhoc_x = 1120
adhoc_y = 94
MouseClick, left, adhoc_x , adhoc_y
Return

The whole point, however, is to define variables for a list of autokeys. I'm going to have about 10 different keystroke combos that will utilize the adhoc_x and adhoc_y coordinates, and I want to be able to change them in one location, as opposed to updating every autokey.

For instance, this is how I want it to look:

;Define Variables:
adhoc_x = 1120
adhoc_y = 94

:*:---::
MouseClick, left, adhoc_x , adhoc_y
Return

:*:+++::
MouseClick, left, adhoc_x , adhoc_y
Return
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Variables for commands

15 Jul 2016, 12:23

Define the variables at the very top of your script. More info at Auto-Execute Section.
loggerhead
Posts: 9
Joined: 09 May 2016, 19:39

Re: Variables for commands

15 Jul 2016, 13:52

So, what this means is if I have a script that has multiple hotkeys, the variable has to be defined for each hotkey?

:*:---::
adhoc_x = 1120
adhoc_y = 94
MouseClick, left, adhoc_x , adhoc_y
Return

:*:+++::
adhoc_x = 1120
adhoc_y = 94
MouseClick, left, adhoc_x , adhoc_y
Return

I have over 200 hotkeys defined inside one script and I would like to define about 40 variables for locations on my screen (I'm working in citrix), so obviously I don't want to have to add the variable to each hotkey. I am going to be placing this script on 10 different computers with different monitor resolutions, so I have to change the x,y coordinates for each and every hotkey, which is overwhelming. If I could just change the 40 variables, then that is easy.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Variables for commands

15 Jul 2016, 13:58

loggerhead wrote:So, what this means is if I have a script that has multiple hotkeys, the variable has to be defined for each hotkey?
No. Define the variables once. At the top of the script.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Variables for commands

15 Jul 2016, 21:00

post your full script because you're probably defining the variables in the wrong place

or read and reread and fully understand the link provided

loggerhead
Posts: 9
Joined: 09 May 2016, 19:39

Re: Variables for commands

15 Jul 2016, 22:56

I got it working, thanks. I was placing my variables in the wrong spot. I appreciate the help, greatly appreciated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, mmflume, OrangeCat, roysubs, scriptor2016, ShatterCoder and 99 guests