Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”

Quick productivity blorg today. Because if hillbillies are known for anything, it’s their efficacy. And their ability to use words they don’t quite know the meaning of but can fake in context. (I’m referring, of course, to “efficacy”. I know full well what a “blorg” is so I don’t need you telling me in the comments.)

Alt-F4 is not the most natural keystroke on the Kinesis keyboard. Or even on a regular keyboard. Yet I use it pretty often. Especially recently while testing out Lucene on my document repository. Word and PDF docs abound very quickly while I’m opening them and verifying results. So I was looking for a faster way of closing them quickly.

My chosen method: Press Ctrl three times in rapid succession to close the active window.

The implementation: AutoHotKey. Here is the script that does it:


CloseOnThird() {

   Static Count
   key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^( UP)]")
   If ( A_ThisHotKey = A_PriorHotKey and A_TimeSincePriorHotkey < 400 )
        Count += Count < 3 ? 1 : 0
   Else Count = 1
   KeyWait %key%, DT0.4
   If (ErrorLevel and Count = 3)

The end result: at the end of a strenuous day, I can mash the Ctrl key over and over again until the computer shuts down. Tres satisfying.

Kyle the Ctrl’d

This entry was posted in Utilities. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Rob Henry

    You can keep capslock mapped to escape, and then map capslock and other keys to other functions. This leaves you with a massive number of possibilities. Here’s an example of mapping capslock & c to close:

    SetCapsLockState, AlwaysOff

    send, {Escape}

    capslock & c::
    send, !{F4}

  • Jason Meckley

    to get the script working I needed to make 1 change; negate the error level
    If (!ErrorLevel and Count = 3)

  • Kyle Baley

    Bjalf: I’ve mapped CapsLock to Esc (though I think I use SharpKeys to do that). Reasons: a) as you point out, the key is nigh useless, and b) I use Esc often enough that having it close by is useful.

    I’ve also mapped F1 to Esc because I’m tired of hitting it by mistake and waiting for some help file to pop up.

  • Cyril Bioley

    I personally prefer to bind WinKey + Q to close and WinKey + W to minimize. More natural to me.

    Yeah I know, I’m not the first to come with these specific bindings 😉

  • Bjalf

    Good idea! Though I’d rather use the annoyingly useless “Caps Lock” key.

    I’d also add
    SetCapsLockState, AlwaysOff
    to the script.

  • dave-ilsw

    @BJ Dweck

    So use Alt instead.

  • David R. Longnecker

    Haha, awesome. Definitely adding this to the list. Even on a standard (natural) keyboard, there are quite a few odd-to-reach combos with the F-keys. Now time to sit and ponder the other odd ones I hit throughout the day.

  • BJ Dweck

    Cool tip, but i have the Google Desktop search box popping up after the 2nd Ctrl… so it doesn’t work for me… oh well