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 found that in coding I rarely use the square braces [] but use the curly braces {} often. On most keyboards, these are inputted using Shift+[ or Shift+].

Now I tried to use AutoHotkey to remap these keys by using:

[::{{}

Adding {} is raw mode basically, but it didn't work. Next I tried

{[}::{{}

but that also didn't work.

Any help?

share|improve this question
    
Darren, I've updated my answer. Let me know if there are any problems. :) –  iglvzx May 24 '12 at 3:45

2 Answers 2

Using curly brackets for raw key interpretation is only for the Send commands. So, to map [ to { and ] to } you can use:

[::Send, {{}
]::Send, {}}

Note: Remapping a key with its Shift equivalent is troublesome, as most if not all keyboards send the same scancode each time, the only difference being the introduction of the Shift key (which has its own scancode).

For example, pressing [ on my keyboard sends the scancode 01A and yields a [. Pressing LShift+[ sends the scancodes 02A and 01A, yielding a {.


Update:

I have successfully overcome the scancode issue with some clever logic! Using the following format, you should be able to switch any key with its Shift pair. Key repetition should also work.

*$[::
    if (GetKeyState("Shift"))
        Send, {[}
    else
        Send, {{}  
    return

*$]::
    if (GetKeyState("Shift"))
        Send, {]}
    else
        Send, {}}
    return

Expanding on this idea, @Bob wrote a more robust version of the script:

*$[::
    if (GetKeyState("Shift"))
        SendInput, {[ Down}
    else
        SendInput, {{ Down}
    return

*$]::
    if (GetKeyState("Shift"))
        SendInput, {] Down}
    else
        SendInput, {} Down}
    return

*$[ Up::
    if (GetKeyState("Shift"))
        SendInput, {[ Up}
    else
        SendInput, {{ Up}
    return

*$] Up::
    if (GetKeyState("Shift"))
        SendInput, {] Up}
    else
        SendInput, {} Up}
    return
share|improve this answer

If I were presented the problem without seeing the answer above, I'd just add a few hotstrings per the example below.

:*?:[::
    SendInput, {Shift Down}`[{Shift up}
    return

:*?:]::
    SendInput, {Shift Down}`]{Shift Up}
    return

:*?:{::
    SendInput, `[
    return

:*?:}::
    SendInput, `]
    return
share|improve this answer
    
Well done. No need to reinvent the wheel, huh? :) –  iglvzx May 24 '12 at 7:04

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.