Disable caps lock caps functionallity while being able to bind it ingame

Ask gaming related questions
rmonou8
Posts: 3
Joined: 15 Jul 2023, 10:24

Disable caps lock caps functionallity while being able to bind it ingame

Post by rmonou8 » 15 Jul 2023, 10:28

I know i can bind it to like f21 and bind that but are there better ways ?


[Mod action: Moved topic to gaming section.]

User avatar
mikeyww
Posts: 26973
Joined: 09 Sep 2014, 18:38

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by mikeyww » 15 Jul 2023, 10:54

Welcome to this AutoHotkey forum!

No. Binding it is the best way to bind it!

Code: Select all

#Requires AutoHotkey v2.0
game := 'ahk_exe game.exe'
; game := 'ahk_exe notepad.exe'

CapsLock:: {
 If WinActive(game)
  Send 123
}

AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by AHKxx » 23 Feb 2024, 15:14

Hi. I'm piggybacking on this older thread, rather than start a new one pretty much the same question... I hope that's ok....

I am still using AHK 1.1. I would like to completely disable my caps lock key.
I don't want to bind its functionality elsewhere.
I don't want to assign any other key to it.
I want it to do nothing at all.

I keep hitting it by accident, and the LED on the key does not work, so I can't even tell if it is on. I'd rather have it do nothing at all.

I have tried binding it to itself (CapsLock::CapsLock), but that doesn't work.

I've tried binding it to (CapsLock::Esc), and that works often enough, but there are cases where accidentally sending an ESC creates more problems than accidentally switching to caps.

I tried CapsLock::Null but AHK didn't compile.

Any clues?

Thank you!

User avatar
mikeyww
Posts: 26973
Joined: 09 Sep 2014, 18:38

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by mikeyww » 23 Feb 2024, 15:17

Hello,

Use Return instead of Null.

SetCapsLockState

AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by AHKxx » 23 Feb 2024, 15:34

Thank you for that nearly instant reply!

That works. It has an interesting effect. If I just press the caps key, it does nothing. But if I press and hold the key and then type another key, it toggles the caps function. Is that a byproduct, of the method being used, or somehow part of the design?

It's actually kind of useful, though there is some risk of accidentally switching into all caps. Not a bad tradeoff, though. Interesting!

Thanks again!

User avatar
mikeyww
Posts: 26973
Joined: 09 Sep 2014, 18:38

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by mikeyww » 23 Feb 2024, 16:04

It depends on what else is in your script. If you close all scripts but run a script with that individual hotkey, you might not see that behavior.

Code: Select all

#Requires AutoHotkey v2.0
SetCapsLockState 'AlwaysOff'
CapsLock::Return
It works here. You can use #HotIf to create other contexts that enable the key.

AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by AHKxx » 23 Feb 2024, 16:10

Interesting. There ARE other scripts/commands in the .ahk file that I've placed this commands. Maybe if I make it the last item in the file? I will experiment!

Thank you! :bravo:

User avatar
mikeyww
Posts: 26973
Joined: 09 Sep 2014, 18:38

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by mikeyww » 23 Feb 2024, 16:22

What is a script? A script is simply a plain text file with the .ahk filename extension containing instructions for the program. That sentence comes from the documentation.

AHK is an event-driven program. This means that a hotkey is triggered by an event (e.g., you press the key), regardless of where the hotkey is in your script. Well, the order can matter if you have variants or specific contexts, but otherwise, just moving a hotkey will not necessarily change whether the hotkey is triggered, and that is part of the point of AutoHotkey.

The issue with your script is (probably) not the order of hotkeys but what each hotkey subroutine contains, or what contexts you have defined for them.

A hotkey for CapsLock is not a hotkey for a custom combination that includes CapsLock, and is not a hotkey for CapsLock that also includes a modifier key. It is also not a hotkey for CapsLock that falls under a different context as defined by #HotIf. When any of those other hotkeys exist, they will be triggered as distinct hotkeys if their context is active.

AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by AHKxx » 21 Mar 2024, 17:05

Well for the last few weeks I've been running a script where the only only thing in it is:

Code: Select all

CapsLock::Return 
This works at first, where pressing the CapsLock key does nothing at all. But sooner or later something happens where it gets defeated, and everything is typed in capitals, though pressing the CapsLock key continues to have no effect. The capslock key ends up effectively locked in on state, and the way to get out of this is to exit the script so the key can be used as normal.

I'm not sure what causes it to no longer work. It seems as though it might be some accidental key combination, where I'm unintentionally pressing the caps lock key at the same time I'm pressing another key, or there is an overlap of the two key presses, that somehow causes the CapsLock key to go into its On state, even as pressing capslock continues to not do anything. Not really sure, but it kind of seems like something like that is happening.

As is probably obvious, this is all at the limits of my understanding of how AHK works. But I'm hoping there might be a variation of this code that might be more robust and foolproof. I'm still using AHK v1 for now.

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

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by boiler » 21 Mar 2024, 17:20

If you accidentally press Shift+CapsLock while that script is running, then you will still be able to turn caps on because that key combination is not blocked. You should be able to turn it off again by pressing Shift+CapsLock again.

If you want to also block Shift+CapsLock, then add that hotkey as well:

Code: Select all

CapsLock::return
+CapsLock::return

Or you can bock all modifier keys with CapsLock by using the wildcard modifier symbol:

Code: Select all

*CapsLock::return

AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Disable caps lock caps functionallity while being able to bind it ingame

Post by AHKxx » 21 Mar 2024, 17:33

Thank you!.

That's definitely what was happening, I was pressing the shift key at the same time, locking it into the shifted On state. Basically, that is a variation of the very typo I am trying to make impossible to type, by defeating the bleeping CapsLock key.

I've now set it to

Code: Select all

*CapsLock::Return
And it appears all is well. Makes perfect sense that I would need to set if for all modifiers. Though I had no idea that an asterisk could be used as a wildcard for all modifiers.

Thanks again. And thanks again to mikeyww for the original solution!

Post Reply

Return to “Gaming”