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

So I want to map both keys:
Capslock to Esc
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

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.

Related

Sending keys from ahk so ahk registers them

Is it possible to Send key strokes (e.g., ctrl+alt+b xyz) using ahk and have activated corresponding hotkey ?
E.g., I have ^!b:: that shows MsgBox. I have ^!c:: from which I'd like to Send, ^!b and I want ^!b:: code to be activated.
My goal: I have various hotkeys in combination with Input. I want to have a hotkey to repeat last command.
Thank you

Hotkey to remap keys does not trigger hotstring

I have a hotkey and hotstring that don't seem to work together:
9::(
:?ob0:(::){left 1}
To give some context, in one part of the code I remapped all the symbols to the number below them and vice versa so 9 prints the parenthesis (. Later on I put a hotstring that would type a closed parenthesis after an open one and then places the cursor in between.
Seems simple enough because they both work individually but together when I press the key for 9 and press the Spacebar I only get the open parenthesis ( as if the hotstring was ignored.
Am I missing something obvious?
Try using a combination of Send and InputLevel.
#InputLevel 1
9::SendEvent (
#InputLevel 0
;; Add closing parenthesis
:?ob0:(::){left 1}
Explanation
#InputLevel
By default, hook hotkeys and hotstrings ignore keyboard and mouse events generated by any AutoHotkey script. This behavior can be overridden using SendLevel or #InputLevel
By setting the 9 hotkey to a higher InputLevel, it is able to the activate other hotstrings.
SendEvent
Bizarrely, remapping a numkey to its Shift+# equivalent produced no input when #InputLevel 1 was active.
i.e. Couldn't use 1::!, 2::#, 3::#, ..., 8::*, 9::(, etc.
A Send command was used to workaround this remapping limitation
By default, Send and SendEvent are synonymous with each other.
Notes
SendPlay is not affected by InputLevel.
Remarks for Remapping Keys may explain why 9::( wouldn't trigger other hotkeys.
"Although a remapped key can trigger normal hotkeys, by default it cannot trigger mouse hotkeys or hook hotkeys."
Related
#InputLevel, Send, Remapping (Remarks)

How to disable global remapping effect in AutoHotKey?

I want to make the Shift key behave like PageDown, then I write a script
~Shift::
KeyWait, Shift
Send, {PgDn}
However, when I want to type 'A', I pressed the key Shift and the key a, PageDown was triggered.
How to disable PageDown effect when I want to type 'A'?
Try this:
$Shift:: Send {PgDn}
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.
https://autohotkey.com/docs/Hotkeys.htm#Symbols

Remap Capslock to Esc and disable original Esc key in AutoHotkey

Remapping Capslock to Esc like so works:
Capslock::Esc
But when I add the following remappings (Esc, Alt-Esc, Ctrl-Esc):
Esc::
!Esc::
^Esc::
return
... for disabling the original Esc key, the Capslock remapping no longer works.
How can I remap Capslock to Esc and disable the original Esc key completely?
I hope you can help me, please.
As #vasili told, your Capslock goes to Esc, which is disabled.
From example in documentaition, I have found that, if you want to switch two keys you should write something like this:
a::b
b::a
So using this logic I tried to put some usually not used key:
Capslock::Esc
Esc::F15
^!Esc::F15
!Esc::F15
^Esc::F15
F1 through F24 - The 12 or more function keys at the top of most keyboards.
Here's an easier one using wildcard (*) and without mapping to unused key:
Capslock::Esc ; Remap Capslock to Esc
*Esc::return ; Disable Esc pressed with zero or any combination of modifiers
If it doesn't work, add a $ to block the trigger loop:
Capslock::Esc ; Remap Capslock to Esc
$*Esc::return ; Disable Esc pressed with zero or any combination of modifiers
To disable just certain combinations of Esc:
Capslock::Esc
$Esc::
$!Esc::
$^Esc::
return

Autokey: Capslock and a character will not map to Left

I'm trying to use Capslock to modify hjkl to arrows to simulate vim but I keep getting an error.
Capslock & h::Left
I get an error:
Line Text: Left
Error: This line does not contain a recognised action
Capslock is later remapped to Esc.
If I use the mapping to fire off a new window it works without fault.
Is there a way to achieve this?
My keyboard doesn't have a left windows key so I cannot use the windows key.
Try this:
Capslock & h::send, {left}
It works for me this way.