Caps lock + other keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Caps lock + other keys

Post by TheNomadicAspie » 02 Jul 2021, 19:17

I'm trying to use a script I found on here to press shift + alt + f when caps lock and f are pressed together, and to otherwise set the caps lock function on when the button is pressed twice, but I can't seem to figure it out. Could someone help me figure out what I'm doing wrong?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

CapsLock::
   KeyWait, CapsLock                      ; wait for Capslock to be released
   KeyWait, CapsLock, D T0.2              ; and pressed again within 0.2 seconds
   if ErrorLevel
      return
   else if (A_PriorKey = "CapsLock")
      SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
   return
*CapsLock:: return                        ; This forces capslock into a modifying key.

#If, GetKeyState("CapsLock", "f") ;Your CapsLock hotkeys go below
{
Send {LShift down}
Send {LAlt down}
Send f
Send {LAlt up}
Send {LShift up}
}

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

Re: Caps lock + other keys

Post by mikeyww » 02 Jul 2021, 19:44

You found a broken script. #If is used with hotkeys & hotstrings.

Code: Select all

CapsLock::SetCapsLockState, % A_PriorHotkey = "CapsLock" && A_TimeSincePriorHotkey < 500 ? "On" : "Off"
CapsLock & f::Send !+f

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 02 Jul 2021, 21:48

Thank you! This is going to make my life so much easier now.

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 02 Jul 2021, 21:55

mikeyww wrote:
02 Jul 2021, 19:44
You found a broken script. #If is used with hotkeys & hotstrings.

Code: Select all

CapsLock::SetCapsLockState, % A_PriorHotkey = "CapsLock" && A_TimeSincePriorHotkey < 500 ? "On" : "Off"
CapsLock & f::Send !+f
If I can ask one more thing, how can I send the characters 40j if I press and release Ctrl within 0.5 seconds without pressing anything else? I use Vim as a text/code editor and wanted to create a way to scroll 40 lines at a time.

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

Re: Caps lock + other keys

Post by mikeyww » 03 Jul 2021, 07:17

Code: Select all

~Ctrl::KeyWait, Ctrl
Ctrl Up::Send % A_TimeSincePriorHotkey < 500 && Instr(A_PriorKey, "Control") ? "40j" : ""

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 03 Jul 2021, 11:30

Awesome thanks again.

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 03 Jul 2021, 11:51

mikeyww wrote:
03 Jul 2021, 07:17

Code: Select all

~Ctrl::KeyWait, Ctrl
Ctrl Up::Send % A_TimeSincePriorHotkey < 500 && Instr(A_PriorKey, "Control") ? "40j" : ""
And how can I send enter after other commands? I'm trying to send :set number {Enter} when CapsLock +n is pressed, so I did:

CapsLock & n::Send `:set number, {Enter}

But that's not working. I also did:

CapsLock & n::ControlSend, `:set number `{Enter}

And that's saying I need a second parameter, and the documentation says I can leave the first parameter to specify the window blank, so I did:

CapsLock & n::ControlSend,, `:set number `{Enter}

With the same failed result. I thought maybe putting the send command on the second line would cause the program to do that next as long as there wasn't another key wait statement, so I did this:

CapsLock & n::Send `:set number
Send {Enter}

But that doesn't work either.

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

Re: Caps lock + other keys

Post by mikeyww » 03 Jul 2021, 12:21

Please post your entire script.

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 03 Jul 2021, 13:09

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

CapsLock::SetCapsLockState, % A_PriorHotkey = "CapsLock" && A_TimeSincePriorHotkey < 500 ? "On" : "Off"
CapsLock & f::Send !+f
CapsLock & v::Send ^!v
CapsLock & n::Send `:set number
Send {Enter}
CapsLock & r::Send `:set relativenumber
Send {Enter}

~Ctrl::KeyWait, Ctrl
Ctrl Up::Send % A_TimeSincePriorHotkey < 500 && Instr(A_PriorKey, "Control") ? "40j" : ""

#~Shift::KeyWait, Shift
#Shift Up::Send % A_TimeSincePriorHotkey < 500 && Instr(A_PriorKey, "Shift") ? "40k" : ""
I tried using the same script as Ctrl to Send 40k to scroll up 40 lines when tapping shift, but it triggers even when I use shift normally to capitalize letters. I'm guessing I would need to somehow only trigger that command if shift was tapped quickly and without pressing other buttons?

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

Re: Caps lock + other keys

Post by mikeyww » 03 Jul 2021, 15:09

If you have a multi-line hotkey routine, keep the hotkey on a line by itself, and put Return at the end of the routine.

It looks like you have included the Win key (#) with your Shift. That may require some other adjustments. I am not able to examine it further at the moment as I am traveling.

TheNomadicAspie
Posts: 140
Joined: 07 Jan 2020, 15:39

Re: Caps lock + other keys

Post by TheNomadicAspie » 03 Jul 2021, 15:18

mikeyww wrote:
03 Jul 2021, 15:09
If you have a multi-line hotkey routine, keep the hotkey on a line by itself, and put Return at the end of the routine.

It looks like you have included the Win key (#) with your Shift. That may require some other adjustments. I am not able to examine it further at the moment as I am traveling.
Got it, I'll try to get it working from there. I was actually trying to comment out those lines with #, but I see it's been deprecated and I should use ; instead. Thanks for the help.

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

Re: Caps lock + other keys

Post by mikeyww » 03 Jul 2021, 20:55

Things you can try:

Code: Select all

CapsLock::SetCapsLockState, % A_PriorHotkey = "CapsLock" && A_TimeSincePriorHotkey < 500 ? "On" : "Off"

CapsLock & n::
SetCapsLockState, AlwaysOff
Send :set number{Enter}
SetCapsLockState, Off
Return

CapsLock & r::
SetCapsLockState, AlwaysOff
Send :set relativenumber{Enter}
SetCapsLockState, Off
Return

~Ctrl::KeyWait, Ctrl
Ctrl Up::Send % A_TimeSincePriorHotkey < 500 && Instr(A_PriorKey, "Control") ? "40j" : ""

Freshclean777
Posts: 4
Joined: 28 Nov 2022, 17:05

Re: Caps lock + other keys

Post by Freshclean777 » 28 Nov 2022, 17:46

Hi! I know that it is an old thread but I have approximately the same problem.

I have a physical qwerty keyboard turned into azerty layout with azerty keyboard chosen in windows 10. I am trying to remappe \ | key to work as < and > ( < when capsLock key is off ; > when capsLock key is on)

Also ~` key to work as ² when capsLock key is off, * when capsLock is on, µ when Altgr is holding before pressing it.

Thanks.

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

Re: Caps lock + other keys

Post by mikeyww » 28 Nov 2022, 18:10

Welcome to this AutoHotkey forum!

Code: Select all

\::Send <
#If GetKeyState("CapsLock", "T")
\::Send >
#If

Freshclean777
Posts: 4
Joined: 28 Nov 2022, 17:05

Re: Caps lock + other keys

Post by Freshclean777 » 23 Dec 2022, 14:52

mikeyww wrote:
28 Nov 2022, 18:10

Welcome to this AutoHotkey forum!

Code: Select all

\::Send <
#If GetKeyState("CapsLock", "T")
\::Send >
#If
Thank Mikeyww. It's working fine.
How to send (*) when I press (AltGr + \)? CapsLock key on or off.

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

Re: Caps lock + other keys

Post by mikeyww » 23 Dec 2022, 15:07

Code: Select all

<^>!\::Send *

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Caps lock + other keys

Post by iseahound » 23 Dec 2022, 15:29

FYI that first script is one of mine and should be used like this:

Code: Select all

CapsLock::
   KeyWait CapsLock                      ; wait for Capslock to be released
   KeyWait CapsLock, D T0.2              ; and pressed again within 0.2 seconds
   if ErrorLevel
      return
   else if (A_PriorKey = "CapsLock")
      SetCapsLockState % GetKeyState("CapsLock","T") ? "Off" : "On"
   return
*CapsLock:: return                       ; This forces capslock into a modifying key.

#If GetKeyState("CapsLock", "P")
#include *i macros.ahk                      ; Load custom hotkeys from a separate file
#1::        MsgBox You pressed CapsLock + Win + 1
2::        MsgBox You pressed CapsLock + 2
#+3::       MsgBox You pressed CapsLock + Win + Shift + 3
#If
I don't remember exactly why I avoided a one liner, but the following snippet causes my CapsLock key to blink when pressed.

Code: Select all

CapsLock::SetCapsLockState, % A_PriorHotkey = "CapsLock" && A_TimeSincePriorHotkey < 500 ? "On" : "Off"

Freshclean777
Posts: 4
Joined: 28 Nov 2022, 17:05

Re: Caps lock + other keys

Post by Freshclean777 » 24 Dec 2022, 09:23

mikeyww wrote:
23 Dec 2022, 15:07

Code: Select all

<^>!\::Send *
Not working as expected. It's send Â*. I don't know why.

Freshclean777
Posts: 4
Joined: 28 Nov 2022, 17:05

Re: Caps lock + other keys

Post by Freshclean777 » 24 Dec 2022, 10:06

mikeyww wrote:
23 Dec 2022, 15:07

Code: Select all

<^>!\::Send *
It's working. How to send special caractor like µ.
I have tried this :
<^>!\::Send µ
But it's sending (µ)

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

Re: Caps lock + other keys

Post by boiler » 24 Dec 2022, 10:54

Freshclean777 wrote:
24 Dec 2022, 10:06
It's working. How to send special caractor like µ.
I have tried this :
<^>!\::Send µ
But it's sending (µ)
Save your script with “UTF-8 with BOM” encoding.

Post Reply

Return to “Ask for Help (v1)”