How to Use Caps Lock as a Modifier Key on Windows

The caps lock key on a PC keyboard.likhit jansawang / Shutterstock.com

The caps lock key occupies first-class space on the keyboard and does not weigh on its weight. This simple AutoHotkey script will turn caps lock into modifier key so you can use it for customizable shortcuts.

The basics

This script will allow you to press Caps Lock + G to quickly Google text from anywhere in Windows or press Caps Lock + D to find the dictionary definition of a word. These shortcuts are of course customizable.

Even better, this clever script still lets you use Caps Lock normally. You can turn caps lock on or off by double-pressing it quickly. If you don't, caps lock will work like a modifier key for shortcuts.

AutoHotkey 101

AutoHotkey is a free Windows application that runs in the background and runs scripts. You can write these scripts yourself or download them. Scripts usually wait for a key press and execute an action. In this way, AutoHotkey is a quick way to remap keys in Windows or to assign different actions to keys.

For example, we have shown how you can use AutoHotkey to deactivate Windows key, preventing it from opening the Start menu and removing you from full screen PC games. No need to remove the keyboard cap.

Install AutoHotkey and get the script

Download AutoHotkey and install it to get started. Next, download the CapsLock modifier script.

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 on the script and select "Run Script".

Run an AutoHotkey script from the file explorer.

The script now runs in the background. To turn caps lock on or off, press the caps lock key twice quickly.

If you don't double-tap, caps lock works only as a modifier key. With the functions built into the script, you can use the following shortcuts anywhere in Windows:

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

Want more shortcuts? You can create your own with a little knowledge of AutoHotkey scripts.

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 script execution, right click on the AutoHotkey icon and select "Exit".

Exit AutoHotkey and end a script.

RELATED: How to Write an AutoHotkey Script

How it works?

If you want to see what the script does, right-click it and select "Edit Script" instead. This will open the script in Notepad and you can examine its code. The script is quite short and easy to understand. We recommend that you do not download and run strange scripts without first looking at them and understanding them.

This script was sent to us by Dave Kellog. Here is the magic part of the script that makes caps lock work like a modifier key if pressed twice:

Caps Lock::
KeyWait, CapsLock; Wait indefinitely until Capslock is released.
KeyWait, CapsLock, D T0.2; ErrorLevel = 1 if CapsLock is not stopped within 0.2 seconds.
if ((ErrorLevel = 0) && (A_PriorKey = "CapsLock")); Is it a double tap on CapsLock?
{
SetCapsLockState,% GetKeyState ("CapsLock", "T")? "Off on"; Toggle CapsLock LED State
}
come back

This bit waits to see if caps lock is pressed twice and turns caps lock on or off. Otherwise, the script captures the caps lock and uses it for modifier shortcuts.

The rest of the script contains shortcut actions and a useful clipboard function that saves the contents of your clipboard and restores them. This part is quite necessary, since the modification functions use the clipboard to perform actions on the selected text.

Want to see the full script without downloading it? It is here:

#NoEnv; Recommended for performance and compatibility with future versions of AutoHotkey.
; #Prevent ; Activate warnings to help you detect common errors.
#SingleInstance FORCE; Ignore the invocation dialog and silently replace the previously executed instance of this script.
SendMode entry; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir% A_ScriptDir%; Ensures a consistent boot directory.

; ================================================== = ===============================================
; CapsLock treatment. You must press CapsLock twice to activate or deactivate CapsLock mode.
; ================================================== = ===============================================
; You must press CapsLock twice to activate or deactivate CapsLock mode.
Caps Lock::
KeyWait, CapsLock; Wait indefinitely until Capslock is released.
KeyWait, CapsLock, D T0.2; ErrorLevel = 1 if CapsLock is not stopped within 0.2 seconds.
if ((ErrorLevel = 0) && (A_PriorKey = "CapsLock")); Is it a double tap on CapsLock?
{
SetCapsLockState,% GetKeyState ("CapsLock", "T")? "Off on"; Toggle CapsLock LED State
}
come back

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

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

; Make THESAURUS of the selected word
CapsLock & t ::
ClipboardGet ()
Run http://www.thesaurus.com/browse/%Clipboard%; Launch with clipboard content
ClipboardRestore ()
Come back

; Make WIKIPEDIA of the selected word
CapsLock & w ::
ClipboardGet ()
Run, https://en.wikipedia.org/wiki/%clipboard%; Launch with clipboard content
ClipboardRestore ()
Come back

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

; ================================================== = ===============================================
; Clipboard help functions.
; ================================================== = ===============================================
ClipboardGet ()
{
OldClipboard: = ClipboardAll; Save the existing clipboard.
Clipboard: = ""
Send, ^ c; Copy the selected test to the clipboard
ClipWait 0
If ErrorLevel
{
MsgBox, no text selected!
Come back
}
}

ClipboardRestore ()
{
Clipboard: = OldClipboard
}

We've already seen AutoHotkey scripts that turn caps lock into modifier keys, but never a script that keeps caps lock like a toggle if you press it twice. It’s very smart. Thanks again to Dave Kellog for sending it to us.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.