2 problems when using Caps to define a custom combination

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
forAHK
Posts: 6
Joined: 16 May 2022, 22:43

2 problems when using Caps to define a custom combination

Post by forAHK » 16 May 2022, 23:25

2 problems when using Caps to define a custom combination.
------
I want to use the Caps key as a modifier key, and using "Shift+Caps" to toggle the Caps' status.
So I test this following script:

Code: Select all

; ;disable Caps native function, this may not be necessary because of the exist of the custom combination.  
CapsLock::return

; ;use shift+CapsLock to toggle CapsLock status
+CapsLock::
SetCapsLockState % !GetKeyState("CapsLock", "T") ;
return

; ;using Caps+d to send character 'a'
CapsLock & d::Send, a
The code has 2 problems:
1. When I press down the Caps, the light on the keyboard toggled immediately which is annoying. How can I disable it?
2. When I hold on CapsLock and then press a key other than 'd', such as "Caps+w", the CapsLock is not restored to the status before I pressed down the Caps key. How can I prevent it?

I came up with a new idea that I can remap the CapsLock key to another meaningless key by changing the registry using Sharpkeys, then using that Key to achieve my goal. That key should not have any meaning before I using it in case of any unexpected bug, so which key should I choose?

Thank you very much!

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: 2 problems when using Caps to define a custom combination

Post by Rohwedder » 17 May 2022, 01:34

Hallo,
try:

Code: Select all

#Inputlevel, 1 ;disable Caps native function:
CapsLock::VKFF ;remaps CapsLock to the unmapped VKFF
#Inputlevel, 0 ;instead of: "CapsLock & ..."  use: "VKFF & ..."

; use shift+CapsLock to toggle CapsLock status
+VKFF::SetCapsLockState % !GetKeyState("CapsLock", "T")
; using Caps+d to send character 'a'
VKFF & d::Send, a

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: 2 problems when using Caps to define a custom combination

Post by lexikos » 17 May 2022, 23:41

@forAHK
I already explained the behaviour in the topic you cross-posted in, and also noted the solution.

Code: Select all

; suppress normal CapsLock changes
SetCapsLockState % "Always" (GetKeyState("CapsLock", "T") ? "On" : "Off")

; use shift+CapsLock to toggle CapsLock status
+CapsLock::SetCapsLockState % "Always" (GetKeyState("CapsLock", "T") ? "Off" : "On")

; use Caps+d to send character 'a'
CapsLock & d::Send, a

Post Reply

Return to “Ask for Help (v1)”