All the tips/hints/fixes/other information posted here are at your own risk. Some of the steps here could result in damage to your computer. For example, using a Windows registry editor like RegEdit could result in unintended serious changes that may be difficult or impossible to reverse. Backups are always encouraged.

19 August 2008

Some Favorite Time Savers with AutoHotkey

AutoHotkey is awesome.

NB: I use KeyTweak to remap the [Right Alt key to Right Ctrl] and [Right Ctrl to another Left Ctrl]. Although AHK can use RAlt as a command key (when written ">!"), Windows has a hard time with it.

AutoExecute Section:
#SingleInstance force
#UseHook On
SetBatchLines -1
SendMode Input
SetKeyDelay, 1, 1
Process, priority, , High
GroupAdd, AllWindows, , , , ahk_class Shell_TrayWnd

Right Alt + Right Ctrl for Back/Fwd buttons
>^LCtrl::Send {Browser_Forward}
<^RCtrl::Send {Browser_Back}
Tilde ` key to close active window
>^`::Send {asc 096} ; ` since ` is remapped to WinClose
PostMessage, 0x112, 0xF060,,, A
Sleep 50
IfWinActive, ahk_class Shell_TrayWnd
GroupActivate, AllWindows
Capslock key minimizes active window
WinMinimize, A
Sleep 50
IfWinActive, ahk_class Shell_TrayWnd
GroupActivate, AllWindows
Left Shift + Right Shift for Capslock
<+RShift:: SetStoreCapslockMode, Off Sendevent {capslock} return
Shift-Capslock toggle restore/maximize active window
WinGet MX, MinMax, A
WinRestore A
Else WinMaximize A
Ctrl-Click becomes a Middle Click for the taskbar and Firefox tab bar (recommend Taskbar Shuffle for closing windows from Taskbar with middle click)
^LButton:: ; Make ctrl-click a middle click in certain circumstances
MouseGetPos, , , , currentcontrol
If currentcontrol in ToolbarWindow324,MozillaWindowClass6
Click M
Send ^{click}

Various Clipboard extensions
>^end::Send {Shift Down}{End}{Shift Up}{Backspace} ; Delete to end of line

>^v:: ; paste without extra spaces, line breaks
gosub getplain
gosub pasteplain

+>^v:: ; additionally remove formatting
gosub getplain
clipboard := %clipboard%
gosub pasteplain
ClipSaved := ClipboardAll
StringReplace, clipboard, clipboard, `r`n, %A_Space%, All
clipboard := RegExReplace(clipboard, "` {2,}", "` ")
StringLeft, 1st, clipboard, 1
IfInString, 1st, %A_Space%
StringTrimLeft, clipboard, clipboard, 1
StringRIght, last, clipboard, 1
IfInString, last, %A_Space%
StringTrimRight, clipboard, clipboard, 1

pasteplain: ; pastes and then clears clipboard and restores clipboard from clipsaved
Send ^v
gosub restoreclip

backupclip: ; backups clipboardall to ClipSaved and then copies (follow with restoreclip)
ClipSaved := ClipboardAll ; Save the entire clipboard to a variable of your choice.
clipboard := ; empty clipboard
Send ^c
ClipWait, 2, 1
IfEqual, ErrorLevel, 0
gosub restoreclip

restoreclip: ; restores clipboard to clipsaved
Clipboard := ClipSaved ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved = ; Free the memory in case the clipboard was very large.
Edit AHK script
Reload AHK script upon save (I use HiEditor)
#IfWinActive, HiEditor - D:\Documents\AutoHotkey.ahk
Sleep 500

To prevent accidental firing using Capslock or tilde, see this solution.

1 comment: