Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Using AutoHotkey to make Demos More Awesome (and more reliable)

Pete Brown - 18 June 2012

My main machine uses what one manager used to call "the monkey keyboard". It's one of those split ergonomic jobs. So, when I go type on a laptop, especially a smaller laptop like my x220, my typing speed and accuracy aren't exactly production-quality.

In addition, fast-paced "lap around" demos often require either a bunch of pre-build projects, or a lot of code snippets. There are tons of solutions for this, but I haven't been very happy with them. Some require too much effort to move between machines (I regularly use four different machines, two of which are laptops I bring to events), and others were just cumbersome or otherwise didn't fir the way I work.

While at the Ask the Experts table at Tech Ed, Tim Heuer and John Lam were raving about this tool AutoHotKey. John Papa had mentioned it to me earlier as well, so clearly I was out of the loop on some new hotness. This free and open source tool enables you to create scripts which use the accessibility API to, in my case, load data on to the clipboard and paste it in. All you need to do is type some mnemonic and hit enter. You can see me using it here.

image

Here's a small part of the WPF demo script. My script was very simple - you can do a lot more, like only enable the operation if a certain window is focused, call functions, and more.

;*********************************************************************
; Background data updating (for live shaping)
;*********************************************************************
::x8::
clipboard =
(
public void StartUpdatingData()
{
Task.Factory.StartNew(() =>
{
while (true)
{
for (int i = 0; i < 10; i++)
{
int pos = _random.Next(0, Stocks.Count - 1);

Stocks[pos].Value += _random.Next(-200, 200) / 100.0m;

}

Debug.WriteLine("Updated Values");
Thread.Sleep(1000);
}
});
}
)
send ^v
return

;*********************************************************************
; VM Constructor stuff for live shaping
;*********************************************************************
::x9::
clipboard =
(
StocksView = new ListCollectionView(Stocks);

// sorting
SortDescription desc = new SortDescription("Value", ListSortDirection.Descending);

StocksView.SortDescriptions.Add(desc);
StocksView.LiveSortingProperties.Add("Value");
StocksView.IsLiveSorting = true;

)
send ^v
return




;*********************************************************************
; Datagrid stuff for live shaping
;*********************************************************************
::x10::
clipboard =
(
<DataGrid Grid.Column="1"
ItemsSource="{Binding StocksView}"
Margin="10">

</DataGrid>
)
send ^v
return

In the code, I then put in some comments which just said which code (x1-x10) to use. It may not be as impressive as typing all this code from scratch, but it also saved a lot of time and typos for a talk which required showing a ton of different features in a short amount of time. In fact, it shaved off 10 or so unnecessary minutes from the talk.

You can even compile the runtime and the script into an EXE, making it dead simple to share your demo script with anyone. Definitely check it out.

     
posted by Pete Brown on Monday, June 18, 2012
filed under:      

2 comments for “Using AutoHotkey to make Demos More Awesome (and more reliable)”

Comment on this Post

Remember me