One of Autohotkeys most basic uses is text replacement or manipulation. Here is one I use daily to insert date/comment in my code:
:*:;cmt:: FormatTime, TimeString, ShortDate SendInput, %TimeString% - Jim Priest - priestj@niehs.nih.gov return
So now when I’m in my text editor I simply type ;cmt and it inserts the date time and my information:
10:27 AM Tuesday, August 18, 2009 – Jim Priest – priest@myworkdomain.com
This uses some simple date formatting options and then does a SendInput to print out the output.
Now you may be asking why not use an CFEclipe/CFBuilder snippet? Well, a lot of times I’m editing files outside of Eclipse. Maybe in Notepad, or an email, or on our company wiki. Autohotkey shortcuts work everywhere!
Here’s another usage example. I’m on the CFEclipse mailing list and often answer bug questions with a standard response. I got tired of typing that over and over so I created a shortcut:
:*:;bug::
SendInput, Can you provide us with more detail on your setup?{Enter}
SendInput, {Enter}
SendInput, http://trac.cfeclipse.org/cfeclipse/wiki/ReportingBugs{Enter}
SendInput, ------------{Enter}
SendInput, When submitting a bug or if you email the mailing list with an issue, please provide as much information as possible:{Enter}
SendInput, {Enter}
SendInput, * Eclipse version: Help > About Eclipse SDK{Enter}
SendInput, * CFEclipse version: Help > About Eclipse SDK > Plug-in Details{Enter}
SendInput, * Java version: From a command line type "java -version"{Enter}
SendInput, * OS - Windows? OSX? Linux?{Enter}
SendInput, * Error log information {Enter}
SendInput, ------------{Enter}
return
This example is very similar to the comment shortcut above. We simply use SendInput to dump some text out. Note the use of {Enter} to force line breaks. So now if I’m on Gmail or Google Groups I can simply type ;bug and this will get dumped in eliminating a lot of typing and also reducing the chance I might forget something.
Can you provide us with more detail on your setup?
http://trac.cfeclipse.org/cfeclipse/wiki/ReportingBugs
————
When submitting a bug or if you email the mailing list with an issue, please provide as much information as possible:* Eclipse version: Help > About Eclipse SDK
* CFEclipse version: Help > About Eclipse SDK > Plug-in Details
* Java version: From a command line type “java -version”
* OS – Windows? OSX? Linux?
* Error log information
————
My final example will demonstrate how to prompt for user input.
:*:;cfif::
Send, {Enter}{Enter}{Enter}{Enter}
Send {UP 3}
Send {LEFT 2}
SetKeyDelay, 20 ;in millisceonds
InputBox, attName, Attribute Prompt, Attribute Name..., , 300, 150
If ErrorLevel = 1 ; They clicked cancel
return
InputBox, attValue, Attribute Prompt, Attribute Value..., , 300, 150
If ErrorLevel = 1 ; They clicked cancel
return
Sleep, 100
SendRaw, %attName% = %attValue%
returnc
In this example first we type out our standard cfif/cfelse blog (using ;cfif as the shortcut) with the Send command, then we use some built in Autohotkey commands UP and LEFT to navigate back to where we want our cursor. We then open an input box and ask the user to enter the variable and value. Since our cursor is already in the correct place (right after the first cfif) we simple send the information captured back to the screen and we end up with:
Hopefully these basic examples will get your wheels turning. Tomorrow we’ll explore using Autohotkey and the clipboard together.
Thanks for the posts about AutoHotKey. I have one question and I can’t find any documentation – in your examples from Day 2 you define your hotkey in the format :*::: rather than just ::. Does that just allow you to type a sequence as opposed to a key combination?
Checkout the Options section of the Hotstings page (http://www.autohotkey.com/docs/Hotstrings.htm). On it it mentions the ‘*’ means ‘An ending character (e.g. space, period, or enter) is not required to trigger the hotstring’.
Thanks!