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.

Basically, what I'm looking for is: when CapsLock is on I want Space to return _ and I want Shift + Space to return .

Detail: This is kind of a continuation of this question I asked about the remapping the Shift + Space keys to be an underscore (_). I got a great answer but I've found it to be a bit complicated especially when I have a lazy pinky that doesn't like to take itself of the Shift key in time for me to hit the Space key. So now I'm wondering if anyone knows of a solution to make it so the Space key could remap to underscore when CapsLock is turned on. And, even better, if CapsLock is on and I hit the Shift + Space combination it will force a space character. Does that make sense? Go ahead and ask for clarification.

Oh, by the way, the solution for the question I asked earlier may have the power to do this. It's called AutoHotKey. If that'll do it, then I'm totally happy with that! Thanks!

share|improve this question

1 Answer 1

up vote 9 down vote accepted

AutoHotkey script:

+Space::
state := GetKeyState("CapsLock", "T")
if state
    SendPlay {Space}
else
    SendPlay _
return

Space::
state := GetKeyState("CapsLock", "T")
if state
    SendPlay _
else
    SendPlay {Space}
return

What it does:

  • If CapsLock is not active:

    • Space inserts space.

    • Shift + Space inserts underscore.

  • If CapsLock is active:

    • Space inserts underscore.

    • Shift + Space inserts space.

If you want Space to behave normally when CapsLock is not active, just eliminate the first block.

How to use:

  1. Download and install the latest version.

  2. Save the above script as underscore.ahk, using your favorite text editor.

  3. Double-click the file to run the script.

  4. If you wish, copy the script (or a link to it) in the Startup folder.

How it works:

  • +Space:: ... return executes ... when Shift + Space is pressed.

    +Space:: ... return executes ... when Space is pressed (without modifiers).

  • state := GetKeyState("CapsLock", "T") checks if CapsLock is active.

    • If it is, state is true and the block after if state gets executed.

    • If it isn't, state is false and the block after else gets executed.

  • SendPlay X inserts the character (sequence) X.

    You cannot use Send here, since it would trigger the script recursively, resulting in an infinite loop.

  • return terminates the script at the current point.

    The second return is optional, the first isn't. Without the latter, Shift + Space would cause both blocks to get executed.

share|improve this answer
    
@kentcdodds: You have to replace the previous script with this one. –  sudo May 3 '12 at 14:58
    
Do you think you could edit the answer to remove the part with capslock off and shift+space inserts underscore? Part of my problem is I have a lazy pinky, so when I'm chatting or typing normally I accidentally insert an underscore. So basically, I want normal functionality when caps lock is off. Thanks. –  kentcdodds May 3 '12 at 15:06
    
I've tried the script several times with a few variations and it seems to just turn my space key functionality off entirely... –  kentcdodds May 3 '12 at 15:29
    
@kentcdodds: I've tried both versions (with and without the first block), and they work fine. Close AutoHotKey completely and load just this new script to make sure the old script isn't running anymore. They won't work together. –  sudo May 3 '12 at 15:32

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.