Al-Baraa El-Hag
Al-Baraa El-Hag

Reputation: 871

How to map CAPSLOCK to ESC and ESC to CAPSLOCK in Autohotkey?

So I want to map both keys:

  1. Capslock to Esc
  2. Esc to Capslock

And this script works for Capslock to Esc but it doesn't really work for Esc to Capslock. It causes a Capslock then Esc to be sent. I only want a Capslock sent:

Capslock::Esc
Esc::Capslock

Upvotes: 0

Views: 997

Answers (1)

Spyre
Spyre

Reputation: 2344

Based on Griffin's Comment

$Capslock::Esc
$Esc::Capslock

The problem that you had was that one of the hotkeys you had was triggering another, which can be prevented by using the $ modifier.

From the docs:

This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself. The $ prefix forces the keyboard hook to be used to implement this hotkey, which as a side-effect prevents the Send command from triggering it. The $ prefix is equivalent to having specified #UseHook somewhere above the definition of this hotkey.

Upvotes: 4

Related Questions