AutoHotkey shortcuts

From Site
Jump to: navigation, search

You can read elsewhere about AutoHotkey, but here is a list of macros that I use a lot.

Note: these aren't robust in the sense of working on every possible Windows configuration. It's the nature of AutoHotkey macros that they are easy to write but work on a best-effort basis.

In Windows Explorer, press Win+N to create a new file (and be ready to type in its name):

   #n::
   Send {Space}^{Space}
   Send +{F10}{Up}{Up}{Right}+T
   Sleep, 700
   Send {Backspace}{Del}{Del}{Del}{Del}
   return

In Windows Explorer, press Win+F to create a new folder:

   #f::
   Send {Space}^{Space}
   Send +{F10}{Up}{Up}{Right}{Enter}
   return

In Windows Explorer, press Win+V to edit a file with Vim.

   #v::
   Send +{F10}V{Enter}
   return

Anywhere, type Right Alt+E to type my first name:

   >!e::
   Send Evgeni
   return

Similar shortcuts apply for surname, and full name.

Anywhere, type Right Alt+Shift+H to type in my email address:

   >!+h::
   SendRaw my_email_address@example.com
   return

Anywhere, type Right Alt+U to type in the domain name of my university:

   >^u::
   Send {.}unimelb.edu.au
   return

Anywhere, type Right Ctrl+M to type the name of the city where I live:

   >^m::
   Send Melbourne
   return

In a Google search field, type Right Ctrl+Shift+W to restrict search to Wikipedia:

   >^+w::
   Send site:wikipedia.org
   return

The following few are self-explanatory:

   >^h::
   Send http://
   return
   >^s::
   Send site:
   return


The following is very useful when you want to search with Google under a specific domain. Go to a page under that domain, then type Right Ctrl+Shift+S and it will go to the search box and type in site:the.domain.com leaving you to type in the search query. For Firefox, but also works in Chrome!

   >^+s::
   Send ^l
   Send ^c
   Sleep 200
   temp = %clipboard%
   found_pos := RegExMatch(temp, "(https?://)?([^/]+)", parmatch)
   Send ^k
   SendRaw site:%parmatch2%
   Send {Space}
   return

The following is a function that enables many of the following short-cuts for typing in special characters.

   SendViaClipboard(unicode_string) {
           temp = %clipboard%
           clipboard = %unicode_string%
           Sleep 200
           Send ^v
           Sleep 200
           clipboard = %temp%
   }

Type in an em-dash by hitting Win+-.

   #-::
   SendViaClipboard("—")
   return

Various special characters, self-explanatory:

   >+1::
   SendViaClipboard("¹")
   return
   
   >+2::
   SendViaClipboard("²")
   return
   
   >+3::
   SendViaClipboard("³")
   return
   
   >+8::
   SendViaClipboard("×")
   return
   
   >+=::
   SendViaClipboard("±")
   return
   
   >+m::
   SendViaClipboard("µ")
   return
   

For these to work, you need a unicode version of AutoHotkey. The latest version should have unicode support, or did I download AutoHotkey_L? I can't remember.

Probably the most useful special character, a bullet point:

   >+.::
   SendViaClipboard("•")
   return

Type four spaces:

   >^Space::
   Send {Space}{Space}{Space}{Space}
   return


This is an example of an ad-hoc workflow that AutoHotkey enables. When debugging with gdb under rxvt (Cygwin or MinGW/MSYS) on Windows, and I need to pipe an input file into the program I'm debugging, I can't simply type gdb> r < input.txt due to the buggy gdb implementation, but, with the shortcuts below, I can get what I want, by typing Win+Shift+D, then the name of the input file, then Win+Shift+C:

   #+d::
   Send b main{Enter}
   Sleep 200
   Send r{Enter}
   Sleep 700
   Send p dup2(open("
   return
   
   #+c::
   Send ", 0), 0){Enter}
   Sleep 700
   Send c{Enter}
   return

The following shortcuts work very well for Matlab. The numpad operator keys become prefixed by a dot, which I find I need to use all the time:

   NumpadDiv::
   Send {.}/
   return
   
   NumpadMult::
   Send {.}*
   return
   
   NumpadSub::
   SendRaw {.}^
   return

The following lets me press the ` key to toggle snap mode when using Inkscape. A great thing is that it even works while I am dragging something with the mouse (not easy to press the toolbar button when you're holding something):

   #IfWinActive ahk_class gdkWindowToplevel
   `::
   Send `%
   return

Screenshots

There is also a script that I use all the time, if you can find it on the AutoHotkey website. It's called ScreenCapture.ahk and it lets me press Win+C over a window to copy the screenshot of that window to clipboard. (It has a number of other useful options, such as saving to a file automatically. It is customisable by right-clicking on its system tray icon and selecting Edit This Script.)

Modifying the system PATH variable with two clicks

See this post. This goes onto the Quick Launch bar for me.