Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like my right Ctrl key to behave like the Caps key. When I press it, it is as if I hold the left Ctrl key. And when I press it again, it release the lock.

Is there a way to do that, but only for the right Ctrl key (not the left one)?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can use Autohotkey to do this. A basic toggle script:

x = 0

RCtrl::
if x {
    SendInput {Ctrl up}
    x = 0
} else {
    SendInput {Ctrl down}
    x = 1
}
return
  1. Install Autohotkey

  2. Save the script somewhere as a .ahk file

  3. Run it by double clicking (opening) the .ahk file

  4. If you want it to run at startup, add it to the start menu startup folder

You can replace the SendInput Ctrls with LCtrls if you want it to specifically 'hold' the left control key. It's not case sensitive, by the way.


If you don't wish to install Autohotkey, here's a standalone executable of the above I generated using Autohotkey's compile function. Use it in the same way the .ahk was described above. Use at your own risk.


To block the left control key while control is locked:

x = 0

RCtrl::
if x {
    SendInput {Ctrl up}
    x = 0
} else {
    SendInput {Ctrl down}
    x = 1
}
return

*$LCtrl::
if (!x) {
    SendInput {LCtrl down}
}
return

*$LCtrl up::
if (x && !GetKeyState("Ctrl")) {
    SendInput {Ctrl down}
} else if (!x) {
    SendInput {LCtrl up}
}
return

Yea... it got complicated. To make holding the key work as usual, it's necessary to hook and pass on both the down and up events. The non-blocking modifier (~) cannot be used, because we need to block on certain cases. To make things worse, pressing Alt + Ctrl does something weird where the control key is blocked, but... things break when it's released. The GetKeyState checks if it's up when it's supposed to be down, and sets it to down if it's wrong. Yep, complicated.

It probably would have been easier to just reset the lock state when the left control key is released. Ah well.

share|improve this answer
2  
It would be nice to know what the downvote is for. –  Bob Apr 24 '12 at 18:17
    
This is just perfect, thanks! I even used the scroll lock key to display the state of the Ctrl key. –  Matthieu Napoli Apr 25 '12 at 9:55
    
I've just noticed, be warned that if you press the left control it will end up sending a Ctrl Up, unlocking it.. so catch the ~Ctrl Up hotkey and use that to turn off your scroll lock light. Or catch LCtrl and block it completely when the lock is active. –  Bob Apr 25 '12 at 12:36
    
I'm really struggling with the "blocking" of the left key :'(. Here is a part of my code: LCtrl:: if x {} else { Send {LCtrl} }. Now the left Ctrl key doesn't work at all :( –  Matthieu Napoli Apr 25 '12 at 13:54
    
Yea, it gets complicated. I've edited in a version that blocks the left control key when locked. For future reference, when you do nothing ({}), you're blocking the key. When you send {LCtrl}, you're sending a press and immediate release. To simulate holding you have to hook both key up and key down. –  Bob Apr 25 '12 at 15:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.