using SetCapsLockState with #HotIf WinActive

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
saif03
Posts: 2
Joined: 04 Jun 2023, 17:21

using SetCapsLockState with #HotIf WinActive

Post by saif03 » 04 Jun 2023, 17:29

Hello,

I'm fairly new to Auto hot key and I want to disable capsLock functionality only when a certain application is active, so naturally I tried to combine #HotIf WinActice("App name") with setCapsLockState "AlwaysOff", but it doesn't seem to make any impact.

following is the script I'm trying.

#Requires AutoHotkey v2.0

#HotIf WinActive("App name")
SetCapsLockState "AlwaysOff"

return

If I replace SetCapsLock state, with something like ^q::MsgBox "You pressed Control+Q in app name", that seems to work fine. Does this mean #HotIf WinActive("App name") can only work with creating key board shortcuts and macros and not with SetCapsLockState?

User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: using SetCapsLockState with #HotIf WinActive

Post by boiler » 04 Jun 2023, 17:54

#HotIf only applies to hotkeys and hostrings remaps as described at the very top of its documentation page. This will disable the CapsLock key only when the designated window is active:

Code: Select all

#Requires AutoHotkey v2.0

#HotIf WinActive("App name")
CapsLock::return

saif03
Posts: 2
Joined: 04 Jun 2023, 17:21

Re: using SetCapsLockState with #HotIf WinActive

Post by saif03 » 05 Jun 2023, 06:16

Thanks for writing back, I wasn't aware that SetCapsLockState is not considered a hotkey / hot string. The solution you shared does disable the capslock key, but as I mentioned I'm only interested in disabling the capslock functionality and not the key itself. Basically the program I want to do this for is a game and I don't want to disable the key since it serves other functionality in game, I only want to disable the capslock toggling functionality linked to this key temporarily.

Post Reply

Return to “Ask for Help (v2)”