software solutions / project leadership / agile coaching and training

What’s in my AutoHotKey file

Posted on September 7, 2010

I was asked awhile back to blog about what is in my AutoHotKey script file. If you don’t know what AutoHotKey is, it allows you to remap keys on your keyboard or create macros that are associated with keystrokes or key combinations. So here’s what I got.

#SingleInstance

#SingleInstance says that if I load up my AutoHotKey script and there is already one loaded, then just use the new one without prompting. If you make changes to your script file, you can double click the file to reload it. This way you won’t get annoying prompts when you do so. This has to be the first line in your AHK file if you use it.

SetKeyDelay, -1

By default, AHK puts a slight delay between each keystroke in a macro. I have no idea why you would normally want this, so the above line removes that delay and it will execute the keystrokes as fast as possible.

CapsLock::
Send {End}
return

Remaps Caps Lock to End. The Caps Lock key is in such a prime location in the home row, and you don’t usually need to use it. So I remap it to End, which I use a lot when I want to go to the end of a line of code. This way, I don’t have to take my hands off the home row and stab at the End key (and often miss). This was my first AutoHotKey shortcut and it still my favorite.

+Capslock::Capslock

Shift-Caps Lock will now toggle Caps Lock. Because sometimes you actually do need Caps Lock.

#j::run explorer c:proj

Windows+J opens the folder where I keep all of my code. The “run” keyword allows you execute whatever you want.

!^Up::
Send {Up}{Up}{Up}{Up}{Up}
return

!^Down::
Send {Down}{Down}{Down}{Down}{Down}
return

!^Left::
Send {Left}{Left}{Left}{Left}{Left}
return

!^Right::
Send {Right}{Right}{Right}{Right}{Right}
return

When I hit Ctrl-Alt-arrow key, it will go 5 characters/lines in that direction. This really helps you move around faster in a code file. Ctrl-left arrow or Ctrl-right arrow will go to the beginning/end of the current word, which is nice, but sometimes you want to go to a spot in the middle of a long word, so the Ctrl-arrow doesn’t really help. This is another favorite of mine.

:*:ssf]::
SendEvent select * from `
return

When I type “ssf]”, it will change it to “select * from “. The tick at the end of the second line tells AHK that the space at the end of the line is important and should be included.

:*:ietable]::
SendEvent if exists (select 1 from sysobjects where name = 'TableName' and xtype = 'U'){Enter} drop table [dbo].[TableName]{Enter}{Backspace}go
return

:*:ieview]::
SendEvent if exists (select 1 from sysobjects where name = 'ViewName' and xtype = 'V'){Enter} drop view [dbo].[ViewName]{Enter}{Backspace}go
return

:*:ietrigger]::
SendEvent if exists (select 1 from sysobjects where name = 'TriggerName' and xtype = 'TR'){Enter} drop trigger dbo.TriggerName{Enter}{Backspace}go
return

:*:ieproc]::
SendEvent if exists (select 1 from sysobjects where name = 'ProcName' and xtype = 'P'){Enter} drop procedure [dbo].[ProcName]{Enter}{Backspace}go
return

:*:newproc]::
SendEvent if exists (select 1 from sysobjects where name = 'ProcName' and xtype = 'P'){Enter} drop procedure [dbo].[ProcName]{Enter}{Backspace}go{Enter}{Enter}create procedure dbo.ProcName{Enter}({Enter}{Enter}){Enter}as{Enter}begin{Enter}{Enter}end{Enter}go{Enter}{Enter}grant execute on dbo.ProcName to EdwardsSteelUser{Enter}go
return

Prints out the following code when I enter “ietable]”:

if exists (select 1 from sysobjects where name = ‘TableName’ and xtype = ‘U’)
drop table [dbo].[TableName]
go

I put this at the top of the file every time I create a new database table. Also included are similar macros for views, triggers, functions, and stored procedures.

:*:se]::
SendEvent ShouldEqual(
return

When I write tests, I’m often writing things like “employee.Name.ShouldEqual(“Jon”);”. When I’m typing this stuff, I can just type “se]” and get “ShouldEqual(“. Sure, Intellisense could do it for me, but AHK is a lot faster than waiting for Intellisense to figure out what I’m doing.

:*:c:|::
SendEvent c:
return

Because I often screw up when typing “c:” and type “c:|” instead. You can do similar things for common misspellings that you often find yourself typing.

I have some other project-specific macros in my AHK file too. If you find yourself typing the same class name, database table name, or anything else over and over, create a macro for it. It’s a small thing but it will help you go a lot faster.

I wanted a way to add stuff to my file quickly because I knew that I would be more likely to do it if it were easier. This led to the AutoHotKeyShortcutAppender, which is a small console app that takes in two arguments: the key combination for a macro and the output. Now I can hit Windows-Q to bring up SlickRun and type “asc scn] SomeClassName” and instantly it adds the macro to the end of my AHK file and reloads it. (If you use the code, you have to edit the app.config file and set the path to your AHK file.)

Have any other AHK favorites? Please post a comment and let me know!

7 Comments »

  1. Aside from some similar to yours, 2 of my favorites are toggling AlwaysOnTop, and Win+LEFT and Win+RIGHT to move my window left or right one monitor.

    #t::
    WinSet, AlwaysOnTop, Toggle,A
    return

    I use this constantly. I like to pin a notepad or browser while I have a maximized IDE behind it, or pin a command line while I’m doing some IronRuby scripting, or a number of other things.

    #left::
    WinGet, mm, MinMax, A
    WinRestore, A
    WinGetPos, X, Y,,,A
    WinMove, A,, X-A_ScreenWidth, Y
    if(mm = 1){
    WinMaximize, A
    }
    return

    #right::
    WinGet, mm, MinMax, A
    WinRestore, A
    WinGetPos, X, Y,,,A
    WinMove, A,, X+A_ScreenWidth, Y
    if(mm = 1){
    WinMaximize, A
    }
    return

    It will restore a window if maximized, then re-maximize it on the other monitor after you move it.

    Andy Vulhop — September 7, 2010 @ 11:34 am

  2. Oh, and since my current client pushes all internet traffic through a proxy:

    ::igem install::igem install –http-proxy http://client-specific-proxy.com

    It’s nice so that I don’t have to remember the proxy every time.

    Andy Vulhop — September 7, 2010 @ 11:36 am

  3. Thanks for the tips
    I like the first 2 – single instance and set key delay
    I have a quite extensive list of sutocorrections and key remaps but I hadnt seen those too before
    Cheers
    MATT
    PS – found you post via Twitter retweet by AHK bot

    Noblejoker — September 7, 2010 @ 11:40 pm

  4. Oooo Nice Article. It’s not often you see AHK getting some credit, and god knows it deserves it.

    Lemme throw you a few things, For starters, fundamentals

    ^!+#1:: Run C:\Program Files (x86)\AutoHotkey\AutoHotkey.chm
    return
    ^!+#2::
    Reload ; Assign a hotkey to terminate this script.
    return
    ^!+#3::
    Run d:\my dropbox\
    return
    ^!+#4::
    Edit
    return
    ^!+#5::
    Keyhistory
    return
    #w::
    Run C:\Windows\SysWOW64\cmd.exe

    This way, if I want to quickly edit the AHK file I have current in the works. Since I generally reach for AHK before I go for any other programming language. It is sort of essential to quick operation.

    Another personal favorite of mine is the doubleclick, it adds an entirely new way of accessing things. For example, hitting escape twice shuts down a program, or double-clicking the Forward button on the mouse closes tabs.

    ; Double Click Escape Close Application
    ~Escape::
    if (A_PriorHotkey “~Escape” or A_TimeSincePriorHotkey > 300)
    {
    ; Too much time between presses, so this isn’t a double-press.
    KeyWait, Escape

    return
    }
    Send !{F4}
    Sleep 1000
    return

    Lastly, I also occationally use AHK for rapid data aggrigation, especially when I do not want to put in the effort to write things out by hand. I write XML files using the clipboard for example.

    #s::
    WinGetActiveTitle, Title
    clipboard =
    SendInput ^c
    clipwait 1
    If Errorlevel = 0
    {
    StringReplace, clipboard, clipboard, `r`n, , All
    MsgBox Done!
    FileAppend,
    (
    %Title%

    ), D:\options.xml

    }
    return

    Anyway, thanks for the share. I enjoyed reading it. Hopefully some of this stuff may assist you as well. Cheers.

    Mr.Devlar — September 8, 2010 @ 12:18 am

  5. Other tips:

    Instead of “Send {Up}{Up}{Up}{Up}{Up}” you can write “Send {Up 5}.

    Also I saw you are using a lot of shortcuts like !^Up, !^Down …. It can be useful to use an Enterpad with AutoHotkey if you have too many shortcuts to remember: http://www.cedeq.com/enterpad-p120/autohotkey-english.html

    Sonia

    Sonia Lamarre — October 14, 2010 @ 12:06 pm

  6. Might I suggest using:

    #^+r::
    Reload
    Sleep 1000
    MsgBox 4, , Script reloaded unsuccessful, open it for editing?
    IfMsgBox Yes, Edit
    return

    rather than Single Instance? This lets you reload your saved AHK script rather than having to double click it again to reload it. :)

    Jane Gray — November 16, 2011 @ 11:02 am

  7. [...] posted a few years back about some of the macros that I have in my AutoHotKey file. Since then I’ve added some new [...]

    More AutoHotKey goodness (database edition) « Jon Kruger's Blog — February 28, 2013 @ 9:13 am

Leave a comment





SERVICES
SOFTWARE SOLUTIONS
I have over 10 years of software development experience on several different platforms (mostly Ruby and .NET). I recognize that software is expensive, so I'm always trying to find ways to speed up the software development process, but at the same time remembering that high quality is essential to building software that stands the test of time.
PROJECT LEADERSHIP
I have experience leading and architecting large Agile software projects and coordinating all aspects of a project's lifecycle. Whether you're looking for technical expertise or someone to lead all aspects of an Agile project, I have proven experience from multiple projects in different environments that can help make your project a success.
AGILE COACHING
I believe that Agile processes and tools should be applied with common sense. I've spent the last 6 years working on Agile projects as a consultant in many different environments, both in leadership roles and as a practitioner doing the work. I can help you find out how Agile can work best in your organization, not just apply a prescriptive process.
TEST DRIVEN DEVELOPMENT TRAINING
TDD Boot Camp is a hands-on, three day, comprehensive training course that will teach you all of the skills, tools, frameworks that you will need to use test-driven development to develop real world .NET applications. If you're not looking for something that intensive, check out the the half-day version.
Have any questions? Contact me for more information.
PRESENTATIONS
The Business of You: 10 Steps For Running Your Career Like a Business
From CONDG 2012, Stir Trek 2014
From Stir Trek 2013, DogFoodCon 2013
From Stir Trek 2012, QA or the Highway 2014
(presented with Brandon Childers, Chris Hoover, Laurel Odronic, and Lan Bloch from IGS Energy) from Path to Agility 2012
(presented with Paul Bahler and Kevin Chivington from IGS Energy)
From CodeMash 2011
An idea of how to make JavaScript testable, presented at Stir Trek 2011. The world of JavaScript frameworks has changed greatly since then, but I still agree with the concepts.
A description of how test-driven development works along with some hands-on examples.
From CodeMash 2010
From CodeMash 2010