Kyle Baley - The Coding Hillbilly

Sponsors

The Lounge

Wicked Cool Jobs

Advertisement

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:

~Ctrl::
CloseOnThird()
return

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)
      WinClose,A
}

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


Posted Thu, Sep 17 2009 5:21 PM by Kyle Baley
Filed under:

[Advertisement]

Comments

BJ Dweck wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Thu, Sep 17 2009 6:14 PM

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

David R. Longnecker wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Thu, Sep 17 2009 6:49 PM

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.

dave-ilsw wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Thu, Sep 17 2009 7:37 PM

@BJ Dweck

So use Alt instead.

Bjalf wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Fri, Sep 18 2009 3:17 AM

Good idea! Though I'd rather use the annoyingly useless "Caps Lock" key.

I'd also add

SetCapsLockState, AlwaysOff

to the script.

Cyril Bioley wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Fri, Sep 18 2009 3:24 AM

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 ;-)

Kyle Baley wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Fri, Sep 18 2009 11:56 AM

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.

Jason Meckley wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Fri, Sep 18 2009 3:24 PM

to get the script working I needed to make 1 change; negate the error level

If (!ErrorLevel and Count = 3)

Rob Henry wrote re: Using AutoHotKey to map the Ctrl key, or “How to Ctrl your closure”
on Sun, Sep 20 2009 5:00 PM

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

capslock::

send, {Escape}

return

capslock & c::

send, !{F4}

return

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us