How to combine capslock with modifier keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

How to combine capslock with modifier keys

22 Dec 2019, 03:51

I want to use capslock as my main modifier key because this way it doesn't interfere with existing hotkeys of other programs.

This works:

Code: Select all

SetCapsLockState, AlwaysOff
Capslock & i::
But this doesn't:

Code: Select all

SetCapsLockState, AlwaysOff
Capslock & #i::
How do I combine capslock with Ctrl, Shift and Win keys?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: How to combine capslock with modifier keys

22 Dec 2019, 04:03

What you are trying to do is not really supported by AHK, but please look at the docs for a workaround:
https://www.autohotkey.com/docs/Hotkeys.htm#combo wrote:Combinations of three or more keys are not supported. Combinations which your keyboard hardware supports can usually be detected by using #If and GetKeyState(), but the results may be inconsistent. For example: [...]
But please note that, depending on your computer keyboard, certain key combinations with three or more keys may not work (due to technical/hardware reasons like keyboard ghosting or jamming - if that's the case, there is no solution for it with AHK or any other software).

There is also the custom LongHotkeys class by Helgef that you could try for 3+ key combos...
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: How to combine capslock with modifier keys

22 Dec 2019, 04:43

Well I found a workaround

Code: Select all

*CapsLock::    cmd := 1 
*CapsLock up:: cmd := 0
#if cmd ;Capslock Combinations below
But this stops working if I use this code in more than 1 script (only the last saved one works). Any idea why?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: How to combine capslock with modifier keys

22 Dec 2019, 05:10

Afaik, that's part of the way AHK implements (global) hotkeys.

If you really need to spread these Capslock-hotkeys over different scripts, you can probably get around this by making these hotkeys window-/program-specific - again with #-directives... but then you could just put them into one script anyway, I guess.

Code: Select all

#if cmd && WinActive("ahk_exe Notepad.exe")	; if cmd is true and Notepad active
etc.
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: How to combine capslock with modifier keys

22 Dec 2019, 05:30

I wanted to spread them over different scripts because this seems easier to maintain to me. But I can't get it to work since some of them should work with the same ahk_class.
So my only choice is to put them into 1 large script?

Are there any problems (performance i.e.) that could come up if I have several thousand lines in 1 script?
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: How to combine capslock with modifier keys

22 Dec 2019, 13:18

What about

Code: Select all

#if getkeystate("capslock", "p") && WinActive("ahk_exe Notepad.exe")
Will this cause problems?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: How to combine capslock with modifier keys

22 Dec 2019, 13:27

Problems probably not, if your keyboard (meaning the hardware) supports all 3+ key combos that you want to use, without jamming or ghosting. But that's something that you can only test out yourself.
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: How to combine capslock with modifier keys

22 Dec 2019, 13:53

Seems to work without a problem 👍 Awesome! Thank you again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Fredrik F, Joey5, maxkill and 392 guests