次の方法で共有


Windows Hot Keys with AutoHotKey

AutoHotkey_logoI’m a big fan of keeping my hands on the keyboard as much as possible and having real quick easy ‘one-touch’ access to my favorite apps, web sites, and tasks.  It’s just amazing how much more productive one can be when using the keyboard instead of the mouse.  Think of any common app you use in which you have a keyboards shortcut memorized, Ctrl-C to copy, Ctrl-V to paste, IE? Alt-D for the address bar, Word? Ctrl-S to save, Vista? Win key for the Start Menu, etc now imagine the power of having most all of your common tasks that quickly available, yup, pure power.

Now here’s the ultimate hotkey tool, AutoHotKey .  It is a simple ‘scripting’ like app.  It doesn’t have a graphical user interface, but is configured through plain text .ahk files.  Not only can you create hotkeys, but also script other parts of Windows, but I’ll focus this post on the hotkeys.  It is open source, been around a long time, is small, takes little memory, has a great help doc, a strong community, and is easy to use.

AutoHotKey will also allow you to override Windows default hotkeys, like Win-X for the mobility center in Vista.  I have a single .ahk file that loads at startup so the hotkeys are always hooked up.  To do this, first install AutoHotKey, then:

  1. With any text editor (aka Notepad), create a new .ahk file
  2. Add some lines to it for each hotkey (like the ones below)
  3. Add a shortcut to the “Startup” folder in your Start Menu

Some basic hot keys I use are:

Win-X Open favorite web browser
Win-W Open favorite text editor
Win-O Execute the contents of the clipboard
Win-C Open a command prompt
Win-2 Turn off the laptop display to conserver power
Win-` Google Search with the clipboard contents
Win-Ctrl-` Use Google’s ‘I Feel Lucky’ to open the clipboard contents
Win-Shift-O Open a URL in the clipboard
Win-Ctrl-1 Set the screen resolution to 1024x768
Win-Ctrl-2 Set the screen resolution to 1280x1024
Win-Ctrl-6 Set the screen resolution to 1600x1200
Win-Ctrl-8 Set the screen resolution to 800x600
Win-Ctrl-9 Set the screen resolution to 1920x1200
Win-Ctrl-0 Set the screen resolution to the highest the monitor supports
Win-Ctrl-Z Open Microsoft Outlook
Win-Ctrl-X Open Microsoft Excel
Win-Ctrl-W Open Microsoft Word
Win-Ctrl-O Open Microsoft OneNote
Win-Ctrl-V Open Microsoft Visual Studio
Win-Ctrl-B Open Microsoft Live Writer (to Blog)
Win-Shift-S Open a specific OneNote page, “Stream of Consciousness”
Win-Shift-Ctrl-E Edit my master AutoHotKey .ahk file to easily add new hotkeys.
Win-Shift-Ctrl-R Reload my master .ahk file to apply recent changes.
Win-Shift-Ctrl-T Open the AutoHotKey help (.chm) file for reference.
Win-Shift-Ctrl-Y Open AutoHotKey’s Spy Utility

To give an idea for other things you can assign hotkeys for, I’ve got hotkeys to open favorite text files, folders, remote desktop connections, specialty applications, enter login credentials, create a new email to my wife, and a few hotkeys that perform misc repetitive tasks depending on the application.  For other shortcuts, I use SlickRun, which is little commands to the same types of resources, just many more of them.

DownloadIconSmall   Download HotKeys.ahk (the file below) (also download AutoHotKey)
 ; ============================================================================
; == Basic keyboard shortcuts
; ============================================================================

; #=Win ^=Ctrl +=Shift !=Alt

; Open favorite webbrowser
#x::   Run about:home

; Open favorite text editor
#w::   Run %edit%

; Execute the contents of the clipboard
#o::   Run %clipboard%

; Open a command prompt
#c::   Run %ComSpec%

; Google Search for clipboard contents
#g::   Run https://www.google.com/search?q=%clipboard%
#`::   Run https://www.google.com/search?q=%clipboard%

; Use Google "I Feel Lucky" to navigate to the clipboard contents
#^`::  Run https://google.com/search?btnI=I`%27m+Feeling+Lucky&q=%clipboard%
#^g::  Run https://google.com/search?btnI=I`%27m+Feeling+Lucky&q=%clipboard%

; Open the clipboard contents with Internet Explorer
#+o::  Run "%ProgramFiles%\Internet Explorer\iexplore.exe" %clipboard%

; Set screen resolutions
#^1::  Run "%tools%\QRes.exe" /x:1024 /y:768  /c:32
#^2::  Run "%tools%\QRes.exe" /x:1280 /y:1024 /c:32
#^6::  Run "%tools%\QRes.exe" /x:1600 /y:1200 /c:32
#^8::  Run "%tools%\QRes.exe" /x:800  /x:600  /c:32
#^9::  Run "%tools%\QRes.exe" /x:1920 /y:1200 /c:32
#^0::  Run "%tools%\SetHighestResolution.exe"

; Open Microsoft Office Applications
#^z::  Run "%ProgramFiles%\Microsoft Office\Office12\OUTLOOK.EXE"
#^x::  Run "%ProgramFiles%\Microsoft Office\Office12\EXCEL.EXE"
#^w::  Run "%ProgramFiles%\Microsoft Office\Office12\WINWORD.EXE"
#^o::  Run "%ProgramFiles%\Microsoft Office\Office12\ONENOTE.EXE"

; Open Windows Live Writer
#^b::  Run "%ProgramFiles%\Windows Live\Writer\WindowsLiveWriter.exe"

; Open Visual Studio
#^v::  Run "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"

; Edit the master AutoHotKey file
#^+e:: Edit

; Open the AutoHotKey help file for reference
#^+t:: Run "%ProgramFiles%\AutoHotkey\AutoHotkey.chm"

; Open the AutoHotKey spy utility
#^+y:: Run "%ProgramFiles%\AutoHotkey\AU3_Spy.exe"

; Reload this AutoHotKey script
#^+r::
  SoundPlay *64
  Reload
  Sleep 1000
  MsgBox 4, , Script reloaded unsuccessful, open it for editing?
  IfMsgBox Yes, Edit
return

; Turn off the monitor (to save laptop battery power)
#2::   
  Run "%tools%\nircmd.exe" monitor off
  Sleep 1000
  Run "%tools%\nircmd.exe" monitor off
return

Some of these commands use the tools: NirCmd, QRes, SetHighestResolution

These also depend on some system environment variables being set:

  • edit = path to favorite text editor, eg: c:\windows\notepad.exe (my favorite, Notepad2)

  • comspec = path to your favorite command prompt, eg: c:\windows\system32\cmd.exe

    (my favorite, 4NT)

  • tools = directory to directory of command line tools, eg: c:\tools

Related Community Topics

Related Posts

Question for You: What are some of the things you use AutoHotKey for?

Comments

  • Anonymous
    June 14, 2008
    It's time MS built baked something like Automator (OS X) into Windows 7.

  • Anonymous
    June 15, 2008
    I like this one a lot: http://glob.com.au/hotkey/ . I did not try AutoHotKey but it doesn't seem to have a UI. Anyway, GlobHotKey does and since I don't change my hotkeys too often it's the best solution for me. (But it does not override default hotkeys as far as I know. )

  • Anonymous
    June 19, 2008
    I use one of those fancy Microsoft keyboards with the "Favorites" buttons 1-5 across the top. I don't think I'm quite so glued to my keyboard as Noah is, but I had a nifty idea for the favourites keys. I'm wondering how to write a program that will let me do combinations of these keys. For instance, I could press favourite key #3, which would bring up a menu of my remote desktops (1-5) and then I select one to launch with the same keys. The problem is that these keys seem to be tightly bound to IntelliType and I've found very little on the net about how to use them in a program. I've been programming for a while, and have just started C#. If anyone can point me in the direction of anything useful, I'd be really grateful! Thanks.

  • Anonymous
    June 19, 2008
    The comment has been removed

  • Anonymous
    June 25, 2008
    p.header {margin-bottom: 0px; margin-top: 2em; font: bold 11pt arial;} p.miniheader {margin-bottom: 0px;

  • Anonymous
    July 09, 2008
    Thanks, Noah! I'll give that a go and post back when I make some progress on the project. My initial messing-around indicates that this isn't going to be easy at all - the keys 1-5 certainly aren't standard, so the keyboard hook will be involved!

  • Anonymous
    October 08, 2008
    I manually type in the current date into notes I make in Salesforce which is a web based database.  I probably type in the date 10.8 10/8 or something like that 100 times a day.  Any chance of creating a hotkey the automatically populates today's date into a text field.  I would assume this would be some of kind script that would have to be written to work in all Microsoft programs?  Any advice or guideance would be huge.  Thanks.

  • Anonymous
    March 24, 2009
    I've been using autohotkey but i like the syntax of AutoIt better (AutoHotKey was made from AutoIt so they are still very much alike) Both of those scripting languages are awesome the one you choose are personal preference

  • Anonymous
    November 17, 2009
    The comment has been removed

  • Anonymous
    November 17, 2010
    nircmd is not required for turning off monitor. Autohotkey bring of it. This code is enough: SendMessage, 0x112, 0xF170, 2,, A

  • Anonymous
    May 12, 2012
    I'm a little late, but AutoHotkey is spelled AutoHotkey (lowercase k)...you'd think someone from Microsoft, with (presumably) a bunch of computer-related degrees, could spell the name of software correctly?...or wait, do I mean "MicroSoft"?...think he misspells that too?

  • Anonymous
    September 25, 2012
    kurakuraninja, ha, you're absolutely right, thanks, I've gone back through and fixed the spelling where I can, namely on my current blog at http://noahcoad.com.

  • Anonymous
    September 25, 2012
    goblinhan, thanks for that SendMessage tip!  Do you know of an easy way to look up WIndows message codes like that?