Thursday, November 25, 2010

AutoHotkey puts the HOT in Hotkey

If you're a Windows user and you don't know about AutoHotkey, you're living a sad, sad life.

"AutoHotkey unleashes the full potential of your keyboard, joystick, and mouse. For example, in addition to the typical Control, Alt, and Shift modifiers, you can use the Windows key and the Capslock key as modifiers. In fact, you can make any key or mouse button act as a modifier."

AutoHotkey (AHK) works with scripts. The basic syntax is fairly easy to understand, however some of the more complicated stuff is, well, more complicated.

Lets look at an example of a simple but very useful AHK script; a hotkey that runs a program, eg. Calculator, when WindowsKey and C is pressed:

#c:: Run, calc

The hash (#) represents the Windows Key. The letter after that is the key to be pressed with the Windows Key. Thus '#c' means the hotkey is activated when the WindowsKey and C is pressed. Other modifiers include Shift, represented by a plus sign (+), Control by a caret (^) and Alt by an exclamation mark (!).

Then there's two colons (::) directly after defining the keys. Whatever is on the right of the colons is what is executed when the keys are pressed.

'Run' quite simply runs the command after the comma, and 'calc' is the command in Windows for opening the Calculator. You can do the same thing with 'notepad', 'cmd', 'iexplore', and loads more.

Scripts can obviously be more than one line long, for example:

#c::
Sleep 10
Run, calc
return

Does basically the same thing, except for the 'Sleep' command, which, in this case, waits ten milliseconds before running 'calc'.

The 'return' function ends the multi-line hotkey. If you didn't have this here and you define another hotkey after that one, it might think that hotkey is part of the previous one.

Besides built-in Windows programs like 'calc' and 'notepad', other programs can be 'Run'. For example, I use Notepad++ and use Windows Key and N to launch it using the following script:

#n::
Sleep 10
Run, E:\programs\npp\notepad++.exe
return

You can even 'Run' websites. For example, you could make Windows Key and F open Facebook in your default browser:

#f::
Sleep 10
Run, http://www.facebook.com
return

I have a very useful hotkey that Googles whatever I select by pressing Windows Key and G:

#g::
Send, ^c
Sleep 50
Run, http://www.google.com/search?q=%clipboard%
return

The 'Send' command here "sends" Control+C to the computer as though you pressed it on the keyboard. This copies whatever text you might have selected into the clipboard.

After sleeping for fifty milliseconds (to make sure the computer is finished copying your selection) it runs Google with the copied text as the search criteria.

''%clipboard%' puts whatever is copied into the clipboard wherever you want. You can even put it in a 'Send' command (i.e. Send, %clipboard%)

Scripts can get very complicated, for instance, this script I have which allows me to move my Windows around without dragging from the titlebar by holding down the Windows Key (like Gnome/Ubuntu):

#LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return

Don't ask me to explain this, I got it from somebody else. By the way, anything after a semi-colon (;) is a comment and is ignored by AHK.

Here are a few more that I use:

Windows Key and H toggles Show/Hide Hidden Files in Explorer:

#h::
RegRead, HiddenFiles_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
If HiddenFiles_Status = 2
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
Else
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
WinGetClass, eh_Class,A
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA")
send, {F5}
Else PostMessage, 0x111, 28931,,, A
Return

Windows Key and Right Mouse Button (Yes you can combine with mouse events!) minimizes the Window under the mouse cursor:

#RButton::
MouseGetPos, , , WinID, control
WinGetPos, WinX, WinY, WinWidth, , ahk_id %WinID%
WinMinimize, ahk_id %WinID%
return

Windows Key and Q is a lot more comfortable than Alt F4, which is a commonly used hotkey for me. This simple one-liner saves me some wrist aerobics:

#Q::WinClose,A

Check out the Tutorial on AHK scripting or the list of commands that you can use.

I hope you find these scripts useful. Also, I'd love to see what scripts you guys are using, too.

Special thanks to @EttVenter for telling me about the awesomeness of AutoHotkey, and @brskln, who's recent tweets inspired this blog post.

Saturday, November 20, 2010

Quote Collection of the Week #5

I've decided to move Quote Collection day to Saturday. It makes more sense.

"Your wife is not necessarily the enemy." - Riaan Niemand

"This hazelnut drink I ordered tastes far too much like hazelnut." - Angela Smith

"Thouest in the heavenest." - Riaan Niemand

"It'll implode with a small explosion." - Aubrey Hlongwane

"We will be having morning devisions..." - translator in Hammanskraal

"Hallelujah?" - translator in Hammanskraal

"Frontline news." - Riaan Niemand

Daniel Smith: "If my liver was a shack, you'd be home."
Joshua Ball: "You talking to the alcohol there?"

"If peanut butter had a twitter account I'd follow it." - Sean Finaughty

"I suffice." - Daniel Smith

"Don't bite me, I have rabies." - Sean Finaughty

"There are stuff that happens to people." - Riaan Niemand

"When people say you are wrongness." - Riaan Niemand

"Wow, that's a pretty churchy church." - Jean Labuschagne

"The power of the wicket is broken." - Riaan Niemand

"I knew you 'til you were born." - Piet-Hein van Eeghen

"Why do you have to sleep with someone you see all day?" - Nicholas Leask

"My whole pelvic bone shifted gears." - Nicholas Leask

"My butt cheek stretched to the biggest limit." - Nicholas Leask

"Ooh look at him, he's so flexible." - Marcel Labuschagne

"How's this... Since I've started running, I've gotten fatter!" - Aubrey Hlongwane

"Can I lick your knees while you do that?" - Nicholas Leask

"Are you finished with the exercise? Ok do it again." - Keanan (Robyn's nephew)

"That girl has got pretty lips, pity about the rest of her though." - Riaan Niemand (watching maybeline advert)

"Hey it's shin-kicking! They're kicking shins!" - Justin Strehler

"I'll kill you alive!" - Nicholas Leask

"There's not a pastor with nothing." - Nicholas Leask

"It smells like balloon in here... I HATE IT!!" - Aubrey Hlongwane

"How to tame a lion: cut off its head and stick it back on again." - Daniel Smith

"I was raised by English-speaking wolves." - Ryan Norton

"I've seen some noodles floating around the church." - Robyn Ball

"This place turns you into a monster, like survival of the fittest... hey what's this knife doing here?" - Thembani Ketse

"It's the thought that the same." - Nicholas Leask

"Children under eleven years and other unused household appliances." - Tuks FM

"Nick your hair looks so fluffy, like a manicured wookie." - Joshua Ball

"I've always been a dry guy." - Marcel Labuschagne

"I like your MirindaAAAAAAH!!!" - Jacques Schewitz

"Most light-haired-coloured people have orange beards. It makes sense." - Marcel Labuschagne

"Don't dice him, loveman!" - Melissa Donaldson

And my favourite:

"I don't like background music, I like foreground music. It's like foreplay, but ground music." - Nicholas Leask

Saturday, November 13, 2010

Quote Collection of the Week #3 and #4 Bumper Edition

Hey guys

Sorry for the delay. This should have been done yesterday... no wait it should have been done last Friday as well! Oh well, better late than never. This last week didn't "generate" any good quotes to mention, but the week before that contained a massive amount. Feel free to lol

"I needed someone to blame, and you were the ugliest person around." - Riaan Niemand

"Hey, guys! I need some juice please. I think my voice is breaking." - Marcel Labuschagne

"People surprise people." - Nicholas Leask

"I can't even function on a thinkable level." - Robyn Ball

"You said she came with a spiritual fire?" - Marcel Labuschagne

"No ways, I'm not gonna eat your frikken turds!" - Thembani Ketse

"Frikken turds sounds like multiple servings." - Aubrey Hlongwane

"It's bound by glue on a piece of 'nother paper." - Nicholas Leask (explaining how books are made)

"Are your legs very white, Marcel? Oh, they are." - David Roebuck

"Dude, have you heard how the English speak English?" - Nicholas Leask

"I've bred with moths before." - Fransie O'Brien

"So Patrick is actually a moth?" - Nicholas Leask

"I just thought of the most interesting statistic in my brain." - Kurt Schröder

"Ahw man, my brain." - Brian "Brain" Louw

"Hey, Brian Louw, when you lived in Pinetown, was your name Brian Snow?" - Nicholas Leask

"Nick is really thirsty, GIVE HIM JUICE." - Nicholas Leask (talking to himself)

"Gee vir my julle koppe wanneer julle klaar met hulle is." - Sean Finaughty

"Did you stick dead ferret hair to your chin?" - Matthew Church

"Dude, Weetbix punches your colon into submission." - Matthew Church

"Guys, it's Robyn's ball's birthday on the 11th." - Aubrey Hlongwane

"I had like a fat-ass air bubble stuck in my throat with a lot of juice behind it!" - Thembani Ketse

"Now they're going to go to people and say 'I did a plumbing course, now I'm a plumber. I can plumb.'" - Nicholas Leask

"But he got punched really hard hey, the guy concusted him." - Thembani Ketse

"Dude, did you show someone your mopani worm?" - Nicholas Leask

"The dog went to the shop... Its a superhero dog, okay." - Nicholas Leask

"Aaah! I hate frikken spiritual gifts!" - Joshua Ball

"Josh started this whole quote thing... I'm gonna punch him in the nose." - Nicholas Leask

"Obviously I only speak stupid when I'm excited... seriously." - Nicholas Leask

"Ah c'mon guys, I was just ripping your legs out." - Nicholas Leask

"Nick is so priceless." - Joshua Ball

And my favourite:

"Dude, seriously, people were getting shot through the head, and their spinal cages were getting ripped out." - Nicholas Leask

Wednesday, November 10, 2010

Some advice

There is only so much you can do, so do as much as you can.

I believe that you can’t build Rome in a day but you can do more than you think. How do you do this? I think by minimizing the time on less important things you can achieve more with the bigger picture. For example: Teenagers are playing computer games every day, as my dad would say “Wasting their lives away”. Instead of wasting your time in front of that square, they can learn to do something that would benefit their adult lives. Playing computer games is only a short lived experience of fun but cycling or fishing creates bonds between people. Virtual machines don’t create the bonds you can get in the real world. There’s more than meets the eye with life, we need to unlock opportunities that will produce wondrous memories. Memories that catch you when you are older shouldn’t make you long for the past.

However, there is a solution. Try to imagine entering a room from Exclusive Books that has no windows and no other door. You close the door, pitch black, and sit. That is like leaving your life full of new chapters but you leave your opportunities and talents behind. Now if you had stayed in that book store and created chapters of a life well spent, you wouldn’t feel that you could have done more. I believe that we are all given talents, and we should all use them to the best of our abilities. Now I will use a metaphor between the talents as the ancient currency. When you receive talents for free, buy the gift that you will use like academics. Now that you have attained this gift you should use it to the best of your ability because this will be the most powerful freebie you will ever receive.