Difference between revisions of "AutoHotkey"

From HalfgeekKB
Jump to navigation Jump to search
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>
  
 
== Fill in the blank ==
 
== Fill in the blank ==

Revision as of 07:34, 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

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