Difference between revisions of "AutoHotkey"
Jump to navigation
Jump to search
(Created page with " == See also == * [http://www.autohotkey.com/ Official website]") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | == Something's horribly amiss! STOP! == | ||
+ | |||
+ | Put this in your script to make it cut out early when you press F8: | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | F8::ExitApp | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Note that this will make the instance of AHK exit, so your script won't run again until you reopen it. | ||
+ | |||
+ | This is an alternative that I'm using on a remote server; it reloads but pauses as it waits (and stays paused if the reload fails). The pause is more or less immediate since the reload is asynchronous. | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | ; This hotkey pauses and reloads the script. If the reload failed, at least the | ||
+ | ; script is paused. This is my panic button. | ||
+ | F8:: | ||
+ | Reload | ||
+ | ; Reload continues running after this pause. When it finishes loading, the | ||
+ | ; script is started anew, unpaused. | ||
+ | Pause | ||
+ | Return | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == 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: | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | F3:: | ||
+ | WinActivate, Notepad | ||
+ | Send, SOMENAME is a model citizen with NUMBER years of experience.{Enter} | ||
+ | Return | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Simple example of using variables: | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | F3:: | ||
+ | WinActivate, Notepad | ||
+ | someName = Larry | ||
+ | years = 9 | ||
+ | Send, %someName% is a model citizen with %years% years of experience.{Enter} | ||
+ | Return | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Factored out into a function (note that the name must now have quotes): | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | SayThePhrase(someName, years) | ||
+ | { | ||
+ | WinActivate, Notepad | ||
+ | Send, %someName% is a model citizen with %years% years of experience.{Enter} | ||
+ | } | ||
+ | |||
+ | F3:: | ||
+ | SayThePhrase("Larry", 9) | ||
+ | Return | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Looping without the function: | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | 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 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Looping with the function: | ||
+ | |||
+ | <syntaxhighlight lang=autohotkey> | ||
+ | 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 | ||
+ | </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 | ||
+ | </syntaxhighlight> | ||
== See also == | == See also == | ||
* [http://www.autohotkey.com/ Official website] | * [http://www.autohotkey.com/ Official website] | ||
+ | * [http://www.macrocreator.com/ Pulover's Macro Creator], a recorder that exports to .ahk |
Latest revision as of 13:12, 20 June 2014
Something's horribly amiss! STOP!
Put this in your script to make it cut out early when you press F8:
F8::ExitApp
Note that this will make the instance of AHK exit, so your script won't run again until you reopen it.
This is an alternative that I'm using on a remote server; it reloads but pauses as it waits (and stays paused if the reload fails). The pause is more or less immediate since the reload is asynchronous.
; This hotkey pauses and reloads the script. If the reload failed, at least the
; script is paused. This is my panic button.
F8::
Reload
; Reload continues running after this pause. When it finishes loading, the
; script is started anew, unpaused.
Pause
Return
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