I was bored recently and got annoyed when making a new script (Chronicler xp macro, when I work out a last few bugs I'll post it), and made a bunch of helper functions to reduce all the annoying typing, the au3 file to include is attached to this post.
Inclusion can be done by simply copying its contents to the top of your current script, or save this as, for example, functions.au3 in the same directory and using
Code: Register to unlock hidden link
#include "functions.au3"
In the top of your script.
Now, you may ask, what does this do?
It automatically sets the end key to terminate the running script.
And it adds a bunch of functions, which I will describe here, in this pattern
returnValue FunctionName ( argumentType $argumentName, argumentType $argumentName2 [, argumentType $optionalArgument=defaultValue ] )
Void as returnValue means that there is none.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void notify ( string $description )
This function is a shorthand alias for
Code: Register to unlock hidden link
ToolTip($description,10,10,"",0,1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
array getPos ( string $description, int $heyKey )
This function gets the position of the location of the cursor when hexKey is pressed, and returns the array for extraction of X/Y coordinates or passing them along to the
Click function.
Description is used with
notify for telling the user on what to do.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
array getLeftClick ( string $description )
array getRightClick ( string $description )
array getShiftPress ( string $description )
Helper functions for getPos, should be self explanatory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void click ( array $xyArray [, int $clicks=1 ] [, string $button="left" ] [, int $pause = 300 ] )
This function clicks an area of the screen with the coordinates stored in $xyArray in pattern:
$xyArray[0] = $xCoord
$xyArray[1] = $yCoord
Designed to be used with the getPos function. $pause parameter is the sleep done after the click.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mixed getInput ( string $title, string $description, string $regexpTest [, int $exitOnCancel=1 ] [, string $default='' ] [, int $width='' ] [, int $height='' ] )
This function gives an input prompt with title
$title and text
$description.
$regexpTest is a regular expression to match the input against to see if it is valid. If you don't know regular expressions, I suggest to ignore this function. They're somewhat of a headache to learn. If you do know them, this function should not be explained further.
Examples:
Example 1: Ask the user for a location on the screen, wait 5 seconds and then double click it.
Code: Register to unlock hidden link
$loc = getLeftClick("What location should I double click in 5 seconds? Please leftclick that location once.")
sleep(5000)
click($loc, 2)
notify("Clicked said location twice. Ending script in 5 seconds.")
sleep(5000)
notify("")
Example 2: Ask the user for a number. If user presses cancel the script will stop.
Code: Register to unlock hidden link
$number = getInput("Choose a number", "Please enter a number", "^[0-9]*$")
msgbox(0, "Chosen number", "You chose " & $number)
Footnotes
If you have suggestions/requests for functions please post them and I will consider including them in future versions. Besides that: Any input is very welcome.