Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Remap CapsLock


  • Please log in to reply
7 replies to this topic
hlbnet
  • Members
  • 19 posts
  • Last active: Apr 24 2009 08:02 AM
  • Joined: 23 Nov 2008
I discovered the AutoHotkey tools this morning and I'm very enthousiast with its capabilities. I ask myself how could use a keyboard and mouse everyday without it before ?

I tried my very first script, which almost works, but not completely.
My goal is to remap a few keyboard keys that I can't access easily with my small hands while typing text. My first script will remap a few keys to behave like the arrow keys.

I don't feel confortable with the actual position of the arrow keys (Up, Down, Left, Right). Since I never use the CapsLock, my idea is to use the CapsLock key to make the keys ijkl behave respectively like Up, Left, Down, Right.

I have two additionnal requirements :

- I want to be able to use the CapsLock key both as a modifier and in lock mode. It means that, if CapsLock is locked, I want the ijkl keys to behave like arrow keys. If CapsLock is not locked, maintaining it down while typing ijkl would also activate the remap.

- I want any other modifier (Shift, Ctrl, Alt, Win) to be preserved. I mean that when I press "CapsLock+Ctrl+i", I would obtain the same result as pressing Ctrl+Up. Similarly, when I press Ctrl+i when CapsLock is locked, I would obtain the same result.

My script almost works except the last point of my requirement : with my current script, when I press Ctrl+i when CapsLock is locked, the key is not remapped. It behaves exactly like a standard Ctrl+i.

Where am I wrong ?

Here is the script :
#SingleInstance Force
#UseHook On

CapsLock & i::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Up}
Else, SendInput {Blind}i
Return

i::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Up}
Else, SendInput {Blind}i
Return

CapsLock & j::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Left}
Else, SendInput {Blind}j
Return

j::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Left}
Else, SendInput {Blind}j
Return

CapsLock & k::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Down}
Else, SendInput {Blind}k
Return

k::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Down}
Else, SendInput {Blind}k
Return

CapsLock & l::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Right}
Else, SendInput {Blind}l
Return

l::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Right}
Else, SendInput {Blind}l
Return

[Title edited. Please write descriptive titles for your topics. ~jaco0646]

hlbnet
  • Members
  • 19 posts
  • Last active: Apr 24 2009 08:02 AM
  • Joined: 23 Nov 2008
I have found the solution : adding a star (*) in front of some hotkeys definitions. Here is my new script (seems to work well, I need to test a little more to be sure) :
#SingleInstance Force
#UseHook On

CapsLock & i::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Up}
Else, SendInput {Blind}i
Return

*i::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Up}
Else, SendInput {Blind}i
Return

CapsLock & k::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Down}
Else, SendInput {Blind}k
Return

*k::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Down}
Else, SendInput {Blind}k
Return

CapsLock & j::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Left}
Else, SendInput {Blind}j
Return

*j::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Left}
Else, SendInput {Blind}j
Return

CapsLock & l::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Right}
Else, SendInput {Blind}l
Return

*l::
GetKeyState, CapsLockMode, CapsLock, T
IfEqual, CapsLockMode, D, SendInput {Blind}{Right}
Else, SendInput {Blind}l
Return


VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
~*Capslock::

Gui, 99:+ToolWindow

If !GetKeyState("Capslock", "T")

	Gui, 99:Destroy

Else Gui, 99:Show, x-1 y-1 +NoActivate, Dummy IJKL to Arrow Keys

return

#IfWinExist, Dummy IJKL to Arrow Keys

i::Up

j::Left

k::Down

l::Right

#IfWinExist


hlbnet
  • Members
  • 19 posts
  • Last active: Apr 24 2009 08:02 AM
  • Joined: 23 Nov 2008
Thank you for this very short solution.

I do not yet fully understand how it works, but I will study it further with the documentation.

I tried it and it works ... almost.
The only small problem with this solution comes when you use the CapsLock as a modifier : the CapsLock is not automatically unlocked.

I would like that using CapsLock as a modifier do not let the key locked.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
OK, it wasn't easy to implement all of those features, but this 'should' fit the bill (though it blocks the capslock key when it is pressed alone)
1: Pressing [shift][capslock] toggles the capslock state normally
2: Pressing [capslock] without pressing a remapped key while holding down [capslock] will toggle the hotkeys
3: Pressing a hotkey while [capslock] is held down will cause the hotkeys to be toggled off once [capslock] is released
Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, x-1 y-1 +NoActivate, Dummy IJKL to Arrow Keys
Keywait, Capslock
If A_ThisHotkey != Capslock
   Gui, 99:Destroy
else Gui, 99:Show, x-1 y-1 +NoActivate, Dummy IJKL to Arrow Keys +CapsToCancel
return
#IfWinExist, Dummy IJKL to Arrow Keys +CapsToCancel
Capslock::return
CapsLock Up::Gui, 99:Destroy
#IfWinExist, Dummy IJKL to Arrow Keys
i::Up
j::Left
k::Down
l::Right
#IfWinExist


hlbnet
  • Members
  • 19 posts
  • Last active: Apr 24 2009 08:02 AM
  • Joined: 23 Nov 2008
Yes, it works very well and with a very short script !
And you added the requirement to be able to keep the real CapsLock functionality by using the Shift+CapsLock.
That is very impressive.

Next, I will try to remap my whole keyboard with these principles. I have a lot of other ideas than just making the arrow keys more accessible.

By the way, I don't need the real CapsLock functionality, because I never use it. And, I thought I could use the little "light" of the keyboard that is normally associated with the CapsLock to indicate that my own remappings are active.

Thank you very much for your help !

hyborg
  • Guests
  • Last active:
  • Joined: --
Hi all! Let me introduce my way for this task. I think it's less complex then others.

; CapsLock navigation
Suspend On

i::Up
j::Left
k::Down
l::Right
u::Home
o::End
p::PgUp
`;::PgDn
a::Control 

CapsLock::Suspend Off
CapsLock Up::Suspend On


hyborg
  • Guests
  • Last active:
  • Joined: --
BTW, you still can switch a Capslock by Shift+Caps or Ctrl+Caps :)