The Caps Lock key takes up prime keyboard real estate, and it is not pulling its weight. This easy AutoHotkey script will turn Caps Lock Key into a modifier key so you can use it for customizable shortcuts. Here’s how to use Caps Lock Key as a Modifier Key on Windows.

The Basics

This script will let you press Caps Lock+G key to quickly Google text from anywhere in Windows. Or else press Caps Lock+D key to look up the dictionary definition of a word. These shortcuts are customizable, of course.

Best of all, this clever script still lets you use Caps Lock key normally. You can toggle key on and off by quickly pressing it twice. If you do not then, Caps Lock will function as a modifier key for shortcuts.

AutoHotkey 101

AutoHotkey is a free application for Windows that sits in the background and runs scripts. You can write these scripts yourself or can also download them. Scripts generally wait for a keypress and to perform an action. In this way, AutoHotkey is a quick way of remapping keys in Windows or else, assigning different actions to keys.

For example, we have shown how you can use AutoHotkey to disable the Windows key. Just preventing it from opening the Start menu and taking you out of full-screen PC games. No need to try the keycap off the keyboard.

Install AutoHotkey and Get the Script

Download the AutoHotkey application and install it to begin. Then, download the CapsLock Modifier script.

Now extract the AHK script file from the ZIP archive file and place it in any folder on your computer. To run it with AutoHotkey, right-click the script and then select “Run Script.”

Related:  How To Delete Files That Won’t Delete In Windows

The script is now running in the background. To toggle Caps Lock on and off just quickly double-tap the Caps Lock key.

If you do not double-tap keys, Caps Lock just functions as a modifier key. With the functions built into the script, you can use the following shortcuts anywhere in Windows:

1. Press Caps Lock + d – to find the dictionary definition of a selected word.
2. Press Caps Lock + g – to search Google for the selected text anywhere in Windows.
3. Press Caps Lock + t – to find the selected word in a thesaurus.
4. Press Caps Lock + w – to search for the selected text on Wikipedia.

To control AutoHotkey, look for the AutoHotkey icon in your notification area, it has a green background with a white H on it. To stop running the script, just right-click on the AutoHotkey icon and select “Exit.”

How Does It Work?

If you like to see what the script does, just right-click it and select “Edit Script” instead. This will open the script in Notepad, and then you can examine its code.

The script is quite short and easy to understand. We also recommend not downloading and running strange scripts without looking at them and understanding them first.

This script was sent to source  by Dave Kellog. Here is the magic part of the script that makes Caps Lock function as a modifier key if it is pressed twice:

CapsLock::
KeyWait, CapsLock ; Wait forever until Capslock is released.
KeyWait, CapsLock, D T0.2 ; ErrorLevel = 1 if CapsLock not down within 0.2 seconds.
if ((ErrorLevel = 0) && (A_PriorKey = "CapsLock") ) ; Is a double tap on CapsLock?
{
SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On" ; Toggle the state of CapsLock LED
}
return

This bit waits to see if Caps Lock key is pressed twice and sets Caps Lock on or off. Otherwise, the script captures Caps Lock and uses it for modifier shortcuts only.

Related:  How To Change External Monitor Brightness In Windows 10

The rest of the script contains the shortcut actions and a helpful clipboard function that saves the contents of your clipboard and restores them. That part is necessary though, as the modifier functions use the clipboard to take actions on the selected text.

If You Want to see the full script without downloading it? Here it is:

#NoEnv                      ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn                     ; Enable warnings to assist with detecting common errors.
#SingleInstance FORCE       ; Skip invocation dialog box and silently replace previously executing instance of this script.
SendMode Input              ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


;================================================================================================
;  CapsLock processing.  Must double tap CapsLock to toggle CapsLock mode on or off.
;================================================================================================
; Must double tap CapsLock to toggle CapsLock mode on or off.
CapsLock::
    KeyWait, CapsLock                                                   ; Wait forever until Capslock is released.
    KeyWait, CapsLock, D T0.2                                           ; ErrorLevel = 1 if CapsLock not down within 0.2 seconds.
    if ((ErrorLevel = 0) && (A_PriorKey = "CapsLock") )                 ; Is a double tap on CapsLock?
        {
        SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"  ; Toggle the state of CapsLock LED
        }
return



;================================================================================================
; Hot keys with CapsLock modifier.  See https://autohotkey.com/docs/Hotkeys.htm#combo
;================================================================================================
; Get DEFINITION of selected word.    
CapsLock & d::
    ClipboardGet()
    Run, http://www.google.com/search?q=define+%clipboard%     ; Launch with contents of clipboard
    ClipboardRestore()
Return

; GOOGLE the selected text.
CapsLock & g::
    ClipboardGet()
    Run, http://www.google.com/search?q=%clipboard%             ; Launch with contents of clipboard
    ClipboardRestore()
Return

; Do THESAURUS of selected word
CapsLock & t::
    ClipboardGet()
    Run http://www.thesaurus.com/browse/%Clipboard%             ; Launch with contents of clipboard
    ClipboardRestore()
Return

; Do WIKIPEDIA of selected word
CapsLock & w::
    ClipboardGet()
    Run, https://en.wikipedia.org/wiki/%clipboard%              ; Launch with contents of clipboard
    ClipboardRestore()
Return

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;================================================================================================
; Clipboard helper functions.
;================================================================================================
ClipboardGet()
{
    OldClipboard:= ClipboardAll                         ;Save existing clipboard.
    Clipboard:= ""
    Send, ^c                                            ;Copy selected test to clipboard
    ClipWait 0
    If ErrorLevel
        {
        MsgBox, No Text Selected!
        Return
        }
}


ClipboardRestore()
{
    Clipboard:= OldClipboard
}

We have seen AutoHotkey scripts that turn Caps Lock Key into a modifier key before, never one that keeps Caps Lock Key around as a toggle if you double-press it. It is very clever.