×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

This week was TechEd North America, a conference from Microsoft for technical professionals covering the span of pretty much everything Microsoft produces to support IT professionals and software developers.  I was pleased to have been invited to speak on developing Metro style apps in XAML for .NET developers.  Like most developer presenters, I planned on showing a lot of demos, using different tools, editors, and varying code samples, URLs, etc.  When you are a presenter at a conference you usually don’t have the luxury of sitting in your office and doing things without distractions.  You want to get across your message of your presentation and also be able to have some good demonstrations articulating your points.  When you have a lot of demos, most of the time presenters will rely on some form of snippets – something for them to either type in quickly, copy/paste, or drag/drop onto editors.

I’ve used various snippet concepts over the years:

  • Using the Visual Studio Toolbox area and dragging text there (yes, did you know you can do that)
  • VS Code Snippets
  • Custom WPF “always on top” snippet utility (developed by a WPF team member when she was doing presentations)
  • Other 3rd party macro tools

But mostly I, like others, have relied on good ol’ notepad.  For each presentation I have a file and just blocks of code separated with headers denoting to me which step the snippet is for in the demonstration.  I don’t always use snippets because I do have some sense of pride in being able to demonstrate yes, I do actually know what I’m talking about and not just always copy/pasting!  However, again, for efficiency and to get many points across, it is an effective way to start from a blank slate (project) and build up how code gets structured for your particular concept.

Notepad has been great and reliable so I’ve always used it.  The other methods are more laborious to set up and sometimes error prone…aside from the fact they don’t work in all scenarios (i.e., VS code snippets don’t work in XAML…argh). 

This week while preparing in the speaker room with my colleague John Lam (who also gave a presentation on the Windows Runtime) he was using a new utility I hadn’t heard of before.  I usually get my little widgets of knowledge from Scott Hanselman’s massive list of tools.  Most I don’t use, but there are some really helpful gems in there.  So I was surprised about this new tool John was showing me I hadn’t heard of before.

YES, I realize this is probably not a new tool and this invites comments of ‘duh, this has been around forever dude’ so feel free to not post those.  It is new to me, like in that new used car kind of way.

When John was walking through his demo he was typing what seemed like random keystrokes in various places: VS, Blend, Notepad, dialogs, command prompt, web apps.  All of these were translating into blocks of text, shell commands, etc.  He lit up showing me about this new tool, AutoHotkey.

AutoHotkey is a very small tool that basically is a mini macro language.  I’m going to completely under-sell it for it’s likely true abilities, but even for the simplest use it has been a new favorite.  AutoHotkey works by listening to the accessibility features in Windows (also referred to UIA) for anything that has input focus.  Yes, that’s right, anything.  You define a ‘macro’ keyword and then what the command defines.  For me, this was just needing to be a series of copy/paste automation.  Here’s an example of one of my snippets:

   1: ; clear clipboard
   2: ^+x::
   3: clipboard = ; null
   4: return
   5:  
   6: ; Initial StackPanel stubs
   7: ::d1::
   8: clipboard = 
   9: (
  10: <StackPanel>
  11:             <TextBlock FontSize="53" x:Name="FirstName" />
  12:             <Button Content="Click Me" Click="Button_Click_1" />
  13:         </StackPanel>
  14: )
  15: send ^v
  16: return

Anything preceded with a semicolon is a comment.  The next line is the macro command it will listen for when input has focus.  In the above there are two “^+x” means CTRL+SHIFT+X.  The command is followed by two colons which is the delimiter for the command.  The simpler one for “d1” shows how you issue a copy/paste.  I tell it what I want to put on the clipboard, then say to send a CTRL+V (paste) and end the script with a ‘return’ statement.

The beauty is that there is no “app” that you have to run – your script is basically the app.  You create your script in a text file named with an .ahk extension.  When your script is complete, double-click on it and it is now listening.  You’ll get an icon in the system tray showing you that it is running and some options (i.e., you can pause it, edit, reload to tweak):

AutoHotkey example

What is cool is that if you want to see how it is working and what it is doing you can look at the “spy” feature:

AutoHotkey spy

to see how it is listening to automation events and input focus. 

The other great feature it has is that you can compile your script.  What this does is take your script (ahk file) and compiles the AutoHotkey runtime into it as well, producing an EXE.  Now you can take that EXE to any machine and double-click and boom, your snippets are available and listening.  So now I can can compile my snippets for each presentation and put them alongside my other presentation materials on my SkyDrive…keeping everything together and quickly restorable to any machine.  Awesome.

I immediately started using it and became an instant evangelist to other presenters that moment.  John Papa used it in his presentation as well and Pete Brown I think is now converted as well.  For me it worked great, no issues. 

Creating the script was a bit of trial and error because the documentation is, well, not great.  It does SO MUCH MORE than what I’m using it for which is why I felt the docs lacking for the simple cases.  The ‘return’ keyword was critical for me to get mine working without error.  When you install AutoHotkey there is also an “Extras” folder that contains plugins for various editors: VIM, Emacs, TextPad, SciTE, Notepad++ and more.  These allow you to get syntax highlighting in these editors quickly.

Thanks to John Lam for turning me on to this. UPDATE: I’m the idiot because it *is* on Scott’s list.  My search wasn’t good enough apparently :-) and maybe Scott Hanselman will consider it for his ultimate tools list this year.  What is also awesome is that there is a Chocolatey installer for it so I just added this to my personal just-repaved-my-machine-please-give-me-my-utilities package.  Be sure to check it out if you find yourself doing a lot of snippets.

Hope this helps!


This work is licensed under a Creative Commons Attribution By license.


6/13/2012 6:59 AM | # re: AutoHotkey–my new snippet tool
It's already in Scott's list and has been since 2007 :-)
Gravatar
6/13/2012 8:09 AM | # re: AutoHotkey–my new snippet tool
Well its already there in Scott Hanselman's tools list. Also check out Window Pad built entirely using AutoHotKey - very useful.
6/13/2012 8:49 AM | # re: AutoHotkey–my new snippet tool
Maybe http://www.autoitscript.com/site/autoit/ may interest you somehow.

Cheers.
Gravatar
6/20/2012 2:02 PM | # re: AutoHotkey–my new snippet tool
When I right-click on a AutoHotKey script in the system tray, I see the option "Window Spy." When I click on it, I get the "Active Window Info" window. How do I get the other window in your post that shows the steps?

Thanks.
6/21/2012 8:25 PM | # re: AutoHotkey–my new snippet tool
Yes, I'm a convert. I should have checked your blog before I wrote my own post in praise of this tool :)

Thanks for turning me on to this utility.

Pete
6/20/2013 3:53 AM | # re: AutoHotkey–my new snippet tool
Hallo!
For a series of reasons I am very interested in your snippet tool; at this stage because it uses both SqLite and AutoHotKey. I would likt to use the snippet tool in my work using a series of languages. The first pair I used were English and German. I now am using German and French and German and Spanish. All of my writing is language pairs based and I will open a series of WebSites illustrating how and why shortly.
I will get back to you with comments. Regards, Patrick Forkin.

 
Please add 5 and 3 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.