My Technical Notes

Wednesday, 22 March 2017

Using DebugView for Debugging AutoHotkey Scripts

DebugView is an application made by SysInternals that can be used to view debug messages produced by applications.

To create a debug message using AutoHotkey, use the `OutputDebug` command:


OutputDebug, Hello World

Because many other applications also produce debug messages, you want to be able to show only those messages produced by your AutoHotkey script. For this, you can wrap the above command in a function that prepends `[AHK] ` to messages to make them searchable:


DebugMsg(Msg) {
    OutputDebug, [AHK] %Msg%
}

This function is called by passing in a string argument, as below demonstrates. The result is that `[AHK] Hello World` will appear in DebugView's message list.


DebugMsg("Hello World")

Configuring DebugView

Filter to only include [AHK] messages

To configure DebugView to only show messages from AutoHotkey, first show the "DebugView Filter" dialog, by either doing `Ctrl-L` or Edit → Filter/Highlight. In this dialog, in the `Include` field, add `[AHK]*` and press OK. This will not filter existing messages in the list, only new ones.

Highlighting messages by color
To highlight messages containing some text by color, first select a Filter from the list, and then in the colored textbox below it, enter some text to highlight:

Strangely enough, in contrast to the filtering behavior only affecting newly captured messages, the highlighting affects existing messages too.

Other...

If DebugView is not capturing messages (with filter set as `*`), then you may have to run it as administrator.

No comments: