Difference between revisions of "AutoHotkey"
Jump to navigation
Jump to search
Line 77: | Line 77: | ||
{ | { | ||
SayThePhrase(names%a_index%, yearses%a_index%) | SayThePhrase(names%a_index%, yearses%a_index%) | ||
+ | } | ||
+ | Return | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Packing the names and years together (using splits and sub-splits): | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | SayThePhrase(someName, years) | ||
+ | { | ||
+ | WinActivate, Notepad | ||
+ | Send, %someName% is a model citizen with %years% years of experience.{Enter} | ||
+ | } | ||
+ | |||
+ | F3:: | ||
+ | statListList := "Larry,9;Moe,12;Curly,4" | ||
+ | StringSplit, statList, statListList, `; | ||
+ | Loop, %statList0% | ||
+ | { | ||
+ | StringSplit, stat, statList%a_index%, `, | ||
+ | SayThePhrase(stat1, stat2) | ||
} | } | ||
Return | Return |
Revision as of 07:33, 20 June 2014
Fill in the blank
Say I've made a macro that should have some sent keys set by a variable, perhaps in a loop. An example:
F3::
WinActivate, Notepad
Send, SOMENAME is a model citizen with NUMBER years of experience.{Enter}
Return
Simple example of using variables:
F3::
WinActivate, Notepad
someName = Larry
years = 9
Send, %someName% is a model citizen with %years% years of experience.{Enter}
Return
Factored out into a function (note that the name must now have quotes):
SayThePhrase(someName, years)
{
WinActivate, Notepad
Send, %someName% is a model citizen with %years% years of experience.{Enter}
}
F3::
SayThePhrase("Larry", 9)
Return
Looping without the function:
F3::
nameList = Larry,Moe,Curly
yearsList = 9,12,4
StringSplit, names, nameList, `,
StringSplit, yearses, yearsList, `,
; A note on "arrays": AHK does not have a built-in array type; arrays are
; simulated by concatenating a base variable name with an index. As implemented
; by StringSplit, the array is 1-based and the array length is stored at the
; zero index. In this example, names0 would be set to 3 and names1, names2, and
; names3 would be set to each successive name.
Loop, %names0%
{
; a_index is the loop counter.
someName := names%a_index%
years := yearses%a_index%
WinActivate, Notepad
Send, %someName% is a model citizen with %years% years of experience.{Enter}
}
Return
Looping with the function:
SayThePhrase(someName, years)
{
WinActivate, Notepad
Send, %someName% is a model citizen with %years% years of experience.{Enter}
}
F3::
nameList = Larry,Moe,Curly
yearsList = 9,12,4
StringSplit, names, nameList, `,
StringSplit, yearses, yearsList, `,
Loop, %names0%
{
SayThePhrase(names%a_index%, yearses%a_index%)
}
Return
Packing the names and years together (using splits and sub-splits):
SayThePhrase(someName, years)
{
WinActivate, Notepad
Send, %someName% is a model citizen with %years% years of experience.{Enter}
}
F3::
statListList := "Larry,9;Moe,12;Curly,4"
StringSplit, statList, statListList, `;
Loop, %statList0%
{
StringSplit, stat, statList%a_index%, `,
SayThePhrase(stat1, stat2)
}
Return
See also
- Official website
- Pulover's Macro Creator, a recorder that exports to .ahk