如何在 Autohotkey 中将 CAPSLOCK 映射到 ESC 并将 ESC 映射到 CAPSLOCK?

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

所以我想映射两个键:

  1. Capslock 到 Esc
  2. Esc 到 Capslock

此脚本适用于 CapslockEsc,但实际上不适用于 EscCapslock。它导致 Capslock 然后 Esc 被发送。我只想要 Capslock 发送:

Capslock::Esc
Esc::Capslock

基于格里芬的评论

$Capslock::Esc
$Esc::Capslock

您遇到的问题是您的一个热键触发了另一个热键,这可以通过使用 $ 修饰符来避免。

来自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.