Thursday, November 25, 2010
"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:
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:
You can even 'Run' websites. For example, you could make Windows Key and F open Facebook in your default browser:
I have a very useful hotkey that Googles whatever I select by pressing Windows Key and G:
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):
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.
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
SetTimer, EWD_WatchMouse, off
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%
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the 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
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:
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
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2
If (eh_Class = "#32770" OR A_OSVersion = "WIN_VISTA")
Else PostMessage, 0x111, 28931,,, A
Windows Key and Right Mouse Button (Yes you can combine with mouse events!) minimizes the Window under the mouse cursor:
MouseGetPos, , , WinID, control
WinGetPos, WinX, WinY, WinWidth, , ahk_id %WinID%
WinMinimize, ahk_id %WinID%
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:
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
Saturday, November 13, 2010
Wednesday, November 10, 2010
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.