Jump to content

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

Problem rebinding Ctrl to Capslock using


  • Please log in to reply
4 replies to this topic
charlesroper
  • Members
  • 2 posts
  • Last active: Oct 23 2010 09:21 PM
  • Joined: 01 Aug 2010
Hi,

I've got a problem rebinding Ctrl to Capslock. I posted a question on SuperUser but didn't get any responses that helped:

<!-- m -->http://superuser.com... ... autohotkey<!-- m -->

Does anyone know what the problem is here, and how to solve it?

Many thanks!

Charles

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

I am using AutoHotkey to rebind Ctrl to Capslock like this:

Capslock::Ctrl

I have also bound my home keys for movement while Capslock is held:

^h::Send {LEFT}
^j::Send {DOWN}
^k::Send {UP}
^l::Send {RIGHT}

Trouble is, I can hold Capslock and issue one movement combo, but subsequent taps of h,j,k or l while still holding Capslock results in one of those letters appearing in my editor. In other words, it's as if Capslock is being released, even though I am still holding it down. If I hold the actual Ctrl key and use the movement bindings, it works fine. Anyone know how to rectify this?

Using an activator key to enable other keys is a common use of AHK (iow: there are many examples on the forums)

The issue you're running into is that the Send command artificially releases modifier keys before sending the other key strokes.

Here's a different way to use hotkey-activated hotkeys. Note that the 'hjkl' hotkeys will only be enabled while capslock is held down
$Capslock::
	Gui, 93:+Owner ; prevent display of taskbar button
	Gui, 93:Show, y-99999 NA, Enable nav-hotkeys: hjkl
	Send {LCtrl Down}
	KeyWait, Capslock ; wait until the Capslock button is released
	Gui, 93:Cancel
	Send, {LCtrl Up}
Return

#IfWinExist, Enable nav-hotkeys: hjkl

	*h::Send {Blind}{LCtrl Up}{Left}{LCtrl Down}
	*j::Send {Blind}{LCtrl Up}{Down}{LCtrl Down}
	*k::Send {Blind}{LCtrl Up}{Up}{LCtrl Down}
	*l::Send {Blind}{LCtrl Up}{Right}{LCtrl Down}

#IfWinExist, ; end context-sensitive block


charlesroper
  • Members
  • 2 posts
  • Last active: Oct 23 2010 09:21 PM
  • Joined: 01 Aug 2010
Thank you, that works perfectly. To aid my understanding, what is the purpose of those Gui commands?

BTW:

what charlesroper should have wrote


Sorry if I committed a faux pas there - I didn't want to post an unnecessary description of the problem when I had already written it elsewhere. I guess some folk can't access SuperUser, though, and having my question repeated here will aid forum searches, thus justifying the redundancy. :)

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
The GUI in that example is simply a way to 'trick' the AHK #IfWinExist into obeying part of the script, rather than another window.

Notice the title of the gui (parameter 3 of the 'Gui, Show...' command ) matches the title on the line with #IfWinExist.

The gui number (93) is arbitrary.

  • Guests
  • Last active:
  • Joined: --
Ah-ha, gotcha. Many thanks! :D