Jump to content

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

Using Capslock as another modifier key


  • Please log in to reply
5 replies to this topic
nispio
  • Members
  • 6 posts
  • Last active: Mar 30 2010 03:47 AM
  • Joined: 26 Mar 2010
I know that a lot of people have asked questions about turning capslock into a control key, but my problem is a little different.

I want to use the capslock as its own modifier key. When I am holding the capslock key, I want to be able to use i,j,k, and l as arrow keys, along with some other, similar modifications like that. But because I use programs that use ctrl+j or ctrl+i, etc. for application-specific functions, I don't want to just assign it to control. Here is what I have tried:

Capslock & i::Send {Up}
Capslock & j::Send {Left}
Capslock & k::Send {Down}
Capslock & l::Send {Right}
Capslock::return

The problem with that is that if I press anything besides one of the hotkeys I have defined (i,j,k,l) the capslock will toggle. The desired behavior would be that if I press Capslock & anything else, nothing happens at all.

Next I tried:
>^i::Send {Up}
>^j::Send {Left}
>^k::Send {Down}
>^l::Send {Right}
Capslock::RControl

The problem with this is that it works, but only one time. For example, if I hold down capslock, and press 'i' three times, it will arrow up the first time, and then type 'i' twice. I need to be able to hold capslock down and use ijkl as arrow keys, so this won't work either.

Next I tried:

>^i::Send {Up}
>^j::Send {Left}
>^k::Send {Down}
>^l::Send {Right}
*Capslock::Send {RControl Down}
*Capslock::Send {RControl Up}

But this was always sending Ctrl+Up instead of just Up.

I have tried all sorts of combinations of * $ and ~, as well as scrambling the order of things around, and none of it has fixed my problems. Maybe I am trying to do something that just can't be done, but there has got to be some way that I can use capslock as a modifier key without losing my ctrl, alt, and shift keys for their regular functions. Any suggestions would be greatly appreciated.

nispio
  • Members
  • 6 posts
  • Last active: Mar 30 2010 03:47 AM
  • Joined: 26 Mar 2010
I managed to find a piece of code in an old thread that I was able to modify to almost meet my need:

$*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, x-1 w1 +NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
j::Left
l::Right
i::Up
k::Down
#IfWinExist


It's the closes I've gotten yet. I don't know a lot yet about ahk, but it looks to me like any time the capslock key is held down, an "invisible" window is created, and while that window exists, I can use a special set of mapping rules. (Sorry if my terminology is way off)

Anyway, the only problem with this new script is that it allows other key strokes to pass through, when I would prefer that it only pass through the keys that I specify. Is there a way that I can modify this code to silence other button presses while capslock is held down? Or, alternatively, does someone know of a better way to achieve this?

a_h_k
  • Members
  • 685 posts
  • Last active: Sep 28 2015 12:32 AM
  • Joined: 02 Feb 2008

The problem with that is that if I press anything besides one of the hotkeys I have defined (i,j,k,l) the capslock will toggle. The desired behavior would be that if I press Capslock & anything else, nothing happens at all

The simplest way would probably be to manually add all the keys you want excluded...
Capslock & i::Send {Up}
Capslock & j::Send {Left}
Capslock & k::Send {Down}
Capslock & l::Send {Right}
[color=darkred]Capslock & <key1>::return[/color]
[color=darkred]Capslock & <key2>::return[/color]   ;the same way that Capslock is ignored
[color=darkred]Capslock & <key3>::return[/color]
     [color=darkred]...[/color]
Capslock::return


nispio
  • Members
  • 6 posts
  • Last active: Mar 30 2010 03:47 AM
  • Joined: 26 Mar 2010

The simplest way would probably be to manually add all the keys you want excluded...


Okay, so I will just use the #IfWinExist block to cancel any keys that I don't want to do anything when capslock is being held.

$*Capslock::
Gui, 99:+ToolWindow
Gui, 99:Show, x-1 w1 +NoActivate, Capslock Is Down
keywait, Capslock
Gui, 99:Destroy
return

#IfWinExist, Capslock Is Down
j::Left
l::Right
i::Up
k::Down
h::return
u::return
o::return
';::return
; etc., etc.
#IfWinExist

Unless anybody else has a better suggestion? I was hoping for something a little less "brute force."

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
This is much less burute force but, I'm having trouble with it. It frequently lets keys slip past :?
Capslock::

Loop

{

Input , Key, L1 T0.1

If (Key="j")

  send {Left}

If (Key="l")

  send {Right}

If (Key="i")

  send {Up}

If (Key="k")

  send {Down}

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

  Break

}

Return
If somebody knows why I would like to know.

a_h_k
  • Members
  • 685 posts
  • Last active: Sep 28 2015 12:32 AM
  • Joined: 02 Feb 2008

This is much less burute force but, I'm having trouble with it. It frequently lets keys slip past :?

I think it's because while the If's are being evaluated (just after whenever there's been a jkli keypress), the Input is not currently being executed, and the system hotkeys for jkli are in effect, and so the keys are sent as normally done (& not "captured"/"withheld" from system by the Input)
In another words, there are 2 alternating sets of hotkeys - one is the Input hotkeys & the other is the system hotkeys
Like GetKeyState, Input is not an actual "hotkey" (like <key>:: & Hotkey,<key>). These commands can, in certain applications, work perfectly .. but this is not one of them!

So for this use, i think the only reliable method is to use actual hotkeys, and not "approximations" of hotkeys. Speaking of such, might i suggest using the Hotkey command?. It's for creating the multiple hotkeys, but without all the code - see if you can work this out... ;)