Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Single-line comments begin with a semicolon.
- ; Every AHK script will execute from the beginning until it sees the word Return.
- ; This is called the auto-execute portion of the script.
- #SingleInstance Force ; This line disallows two or more copies of the script.
- Tries = 12 ; The = operator is used to assign values to variables.
- Repeats := 10 ; := is used for assigning expressions, which are more flexible. Get used to using it
- f := Tries + Repeats ; This is an expression, so := is necessary.
- Repeats += f ; += is shorthand for "x = x + value"
- MsgBox %Repeats% ; This will display the value of Repeats in a Message Box.
- ; Because MsgBox does not use an expression format, variables must be enclosed in percent signs.
- ; You can force such commands to accept an expression using "% " (percent an a space):
- MsgBox % (f << 16) ** Repeats ; don't worry about what these operators do yet
- ; We've had enough fun, so we're going to end the auto-exception
- Return ; Return stops the execution of the script.
- ; If this script didn't have hotkeys or hotscripts, it would die unless it found the line #Persistent
- ; in the auto-execute portion of the script
- Tries -= Repeats ; This line never executes because it is after the Return
- ; Like +=, you can use -= as shorthand for "x = x - value".
- /*
- This is a multi-line comment.
- This script maps . to Alt+Plus.
- */
- !+:: ; Hotkey format is (command)::
- Send . ; This emulates a period keystroke. I recommend SendInput . though for speed.
- /*
- THIS IS A BAD CHOICE OF KEY COMBO TO USE!
- I wrote this script on a netbook, and you CANNOT hit the + key without also holding down Shift. Therefore,
- !+ is effectively !+= (do not confuse the + in the second example, it represents the Shift modifier).
- I would HIGHLY consider you choose another key combo to fix your broken period key.
- */
- ; Note that you can also define custom key combos which do not use the typical Ctrl/Shift/Alt/Win
- ; modifiers using the & key, limited to two keystrokes. Do not confuse with Boolean AND!
- g & q::
- SendInput .
- ; This makes the G + Q keycombo send a . keystroke. Obviously not a great idea in practice.
- ; A better idea might be this custom key combo:
- AppsKey + /::
- SendPlay . ; SendPlay is like Send, but uses games
- ; This takes the infrequently-used but usually accessible AppsKey and uses a key close to the . key to
- ; to
- ; One last goodie: loops and variables. This maps the key combo % + ] to send multiple periods.
- % & ]::
- Loop, %Repeats% {
- ; Loops must be enclosed in {braces}. They are compatible with the One True Brace format,
- ; which places the starting brace on the same line as the Loop command and the closing
- ; brace on its own line.
- Send .
- }
- ; Can you guess how many times the loop will execute?
Advertisement
Add Comment
Please, Sign In to add comment