| Comments

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!

| Comments

I recently found a good deal on a 7200 RPM 500GB latpop drive and decided to upgrade myself to that.  I’ve been operating on a 150GB drive for a long time and hadn’t been cleaning up old projects, encodings, etc. so it was running thin on space.  This was a cheap upgrade (< $90) so I opted for it.  I finally got a moment last evening to pop it in and start the fresh installs of everything.  Doing so reminded me of how long this process takes for us geeky people.  Luckily I do a backup first using my Home Server so that in the event I screw up, things are there.  Now most would say that I should just pop in the hard drive and do a restore.  I don’t do this for 2 reasons frankly.  First, I have to admit, the ‘restore’ process for me on Home Server hasn’t always been a consistent one.  Don’t be alarmed, there is no data loss, but I’ve found I had to mess with network connections, etc. blah blah…and sometimes it isn’t worth the hassle (emergencies? absolutely).  Second, and most important, I am paranoid of technical grout…or residue of install/uninstall/beta/alpha/etc versions of software.  Sometimes you just want a nice clean slate.

So after my backup I put in the new drive and booted to my network to install Windows 7 x64.  That process is the fastest of the bunch now, clocking in from start of install to workable desktop in about 30 minutes tops.  It’s the rest that I’m reminded of how long it takes.  Now I know I am not (nor likely are you) the ‘normal’ user.  Most would probably suffice with Office install after that, a few tweaks and be good.  Not me, I’m particular.  Here’s my list of what I install and some notes on them.

There are various other 3rd party components and frameworks for Visual Studio and Silverlight that I may install from time-to-time, but the above is my baseline dev machine.  For some this may be a lot, for others this may not be enough.  I don’t think I’m excessive, but somewhere in between.  Still looking (and doing) this is always daunting.

I know, I know…people will write comments below about disk imaging, Acronis, etc., etc.  I’ve tried all those methods before.  Call me paranoid, but I just like to be in control of my own stuff still.  Perhaps I’ll relinquish the control soon. 

It does feel good to have a clean machine though!


| Comments

Help me out with a bit of some research here.  In your opinion…what tools (from Microsoft) are the MINIMUM needed to get started with Silverlight?  I’m not talking about full-blown MVVM, MEF loading, Live Smooth Streaming applications…I’m talking about if you were to tell someone who has a bare hard drive and wanted to start learning Silverlight, what tools would you tell them they simply cannot do Hello World++ without?

Please respond to my survey:

[embedded survey removed please vote here: http://twtpoll.com/em387c]

Thanks!