Black and White Rainbow Published on September 29, 2008
by Black and White Rainbow

Black and White Rainbow's blog

Browse posts
Programming languages. Second part.
Posted on December 7, 2008
Programming languages. First part.
Posted on November 24, 2008
Comment ne pas devenir pauvre.
Posted on October 29, 2008
Les côtes bretonnes et les nombres complexes.
Posted on October 18, 2008
AutoHotKey for coders.
Mi-math, mi-info...
Posted on September 27, 2008
Instant noodles tweaks ou comment préparer une soupe instantanée...
Posted on September 20, 2008
Get a smarter browser.
Posted on September 17, 2008
Séries
Posted on September 12, 2008

More information

This post is public
Attribution + non Commercial + no Derivs
  1. Read 214 times

AutoHotKey for coders.

Monday September 29, 2008 at 05:59PM

Thanks to Lifehacker.com website, I recently discovered AutoHotKey, a keyboard and mouse macro creator. It allows, by running small scripts, to automate some tasks, to create or change your keyboard shortcuts and more.

First thing first : HOWTO use AutoHotKey ?

Download it from the official web site ; install it ; create a new text file ; rename it with a ".ahk" extension. There, you have your first AutoHotKey script... Yes it's empty, but it's a script ! Continue the reading for a code example (or scroll down and stop wasting time correcting poor English and typos).

So far I use AHK (that's both AutoHotKey acronym and scripts extensions) for two purposes. The first thing I've done after downloading and installing was to change my CAPSLOCK behavior. Honestly, does anyone use it ? And if I really had to enter a long CAPITALIZED text I would use notepad++ command ! The previously mentioned useless key is now a shortcut launcher : CAPSLOCK+a launches Firefox ; CAPSLOCK+z launches Firefox (with special arguments) ; CAPSLOCK+e launches the explorer and so on. The script is still evolving and I'm not used to it yet, but I've never hit the CAPSLOCK button like I did last week.

The second script I've written was to simplify coding in my favorite language : OCAML (I'll will create Java, Python and C versions latter... maybe). But how could it be helping a coder ? An simple example is when you want to insert comments in your program you have to enter the starting sequence "(*" ("/*" in C and Java) type your human destined text and enter the closing sequence "*)" ("*/" in C and Java). With the ocaml.ahk script you can just hit the CAPSLOCK+c combination to have a full "(**)" as if you've typed it and guess what. Your caret is right in the middle, where you can right your comments. An other example is function declaration, CAPSLOCK+; create the function declaration frame and position your caret at the function name place.

Here's my script but beware, it's intended to be used for AZERTY (frenchy) keyboards with OCAML language. Well, to be honest ot's intended to show that AHK is cool, it's not a definitive version and will get more and more usefull.

; this is a script intended to empower productivity when coding in OCAML language

SetCapsLockState AlwaysOff
CapsLock & c::Send, (**){LEFT}{LEFT} ;create commentary field
CapsLock & 3::Send, ""{LEFT} ;create a pair of quote (or string field)
CapsLock & 4::Send, {{}{}}{LEFT} ;create {}
CapsLock & 5::Send, (){LEFT} ;create ()
CapsLock & 6::Send, {CTRLDOWN}{ALTDOWN}(){CTRLUP}{ALTUP}{LEFT} ;create []
;CapsLock & {LEFT}:: ;will jump to the previous (,[ or {
;CapsLock & {RIGHT}:: ;will jump to the next ), ] or }
CapsLock & i::Send, let{SPACE}{SPACE}={ENTER}{TAB}{ENTER}{BACKSPACE}in{UP}{UP}{END}{LEFT}{LEFT}
CapsLock & .::Send, let{SPACE}{SPACE}={ENTER}{TAB}{ENTER}{BACKSPACE}`;`;{LEFT}{LEFT}{LEFT}{LEFT}{LEFT}{LEFT}{LEFT}
CapsLock & ENTER::Send, {ENTER}{TAB}

I think the Scheme (or every LISP based language) version would be even more power-full. It would, when well used, avoid parenthesis problems. In Java it'll simplify all the "public synchronized void whatever () {}" boring thing...

Updates will be posted as comments.

Add your comment

Reply to this comment

Edit your comment

Please sign in to post a comment Sign in now?


rss Latest comments – Subscribe to the feed of comments related to this post.

 

Català | Čeština nové | 中文 | Deutsch | English | Español | Esperanto | Ελληνικά | Français | Galego | Italiano | Nederlands | Português | More...