1
votes

I would like an AHK script that will disable Capslock except when used with arrow keys as a shortcut for Home and End (with and without text selection). I believe it would look something like this, but I can't get figure out how to include the Shift key as a modifier so I may select text as well.

Capslock::Return
Capslock & Right::End
Capslock & Left::Home
Capslock & Right & Shift::End (with Selection)
Capslock & Left & Shift::Home (with Selection)
2
@ etune, This page has all the information you're missing: autohotkey.com/docs/Hotkeys.htm It should be read by anyone using autohotkey for the first time.2501
I've read through the docs. Can't get the Shift modifier to work.etune
I can use alt as modifier as in !CapsLock::CapsLock to make alt-capslock behave as normal capslock. Mapping shift through +CapsLock... fails with a message Invalid hotkey. Without delving into the problem I suspect a bug or that remapping capslock is tricky and shift-capslock does not let itself be handled in this way.LosManos

2 Answers

1
votes

This AutoHotkey script should do what you want to achieve:

Note: on some keyboards it is difficult or even impossible to get certain key combinations to act as a hotkey, especially when there is more than one non-modifier key, e.g. CapsLock and Right are not modifiers, whereas Shift/Ctrl/Win/Alt are.

Note: I could not get !CapsLock::CapsLock to work. A long time ago, after a lot of trial and error at the time, I found some working code to assign a different key combination for CapsLock that I include below.

Capslock::Return

Capslock & Right::
if GetKeyState("Shift", "p")
SendInput +{End}
else
SendInput {End}
Return

Capslock & Left::
if GetKeyState("Shift", "p")
SendInput +{Home}
else
SendInput {Home}
Return

;!CapsLock::CapsLock

!CapsLock::
SetStoreCapslockMode, Off
SendInput {CapsLock}
SetStoreCapslockMode, On
Return
1
votes

Copy pasted and trialed and horrored from many, unfortunately forgotten, places is my solution here.

As you can se I have mapped alt-Capslock to normal Capslock
and Capslock by itself to Esc.
Following the same pattern I tried to grab shift-Capslock and alt-Capslock with a +CapsLock & h::Send {Backspace} but AHK complained about bad syntax.
You can also see that ; happens to have a special annotation and that is because I change keyboard and that key is sometimes ; and sometimes ö.

#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.

SetCapsLockState AlwaysOff

; Toggle Capslock with alt-Capslock.
!CapsLock::CapsLock

; Esc.
CapsLock::Send {Esc}

; Arrows.
CapsLock & j::Send {Left}
CapsLock & k::Send {Right}
CapsLock & SC027::Send {Down} ; or CapsLock & `;::Send {Down}
CapsLock & l::Send {Up}
CapsLock & u::Send ^{Left}
CapsLock & i::Send ^{Right}

; Backspace and Del.
CapsLock & h::Send {Backspace}

; Home and End.
CapsLock & m::Send {Home}
CapsLock & ,::Send {End}

; Mark word left.
CapsLock & y::Send ^+{Left}