Skip to content

three brackets one key

Jennifer Leigh edited this page Oct 30, 2017 · 3 revisions

Question from @lasse:

Excerpted from this thread.

I do a lot of java programming, so a dedicated key for brackets would be most welcome. I can’t change the layout of my windows computer, so I need the hardware to do the work. But since I write many more curly brackets, than square ones - and because hacking is fun - I would very much appreciate an outline of how you would go about it.

I mapped LED to { and ANY to }

But I can’t figure out how to map SHIFT+LED to [ and SHIFT+FN+LED to (. I want something like this:

image of key with three symbols

As a bonus I’d like to stack < on the key as well, if at all possible. That would be FN+SHIFT then.

I can see that @algernon has a brackets key like I want. But it's hard to figure out what I need to do to get the bracket key with the minimum number of plugins.

Answer from @algernon:

EDITOR'S NOTE: currently there are two defects affecting this implementation in the queue, but they are high on the list to get corrected:

  1. There are issues when you chord a Topsy key with a non-Topsy one. I will get around to fixing that… hopefully soon. It’s one of the nasty issues that are hard to fix well. On the flip side, it shouldn’t affect you all that much, because the brackets are rarely chorded with anything else!

  2. Keypresses are being repeated such that: shift + led = [[[[[[[[[[[[[[[[[[[[[ shift + any = ]]]]]]]]]]]]]]]]]]]]]]]] fn + led = (,(,(,(,(,(,(,(,(,(,(,(,(,( fn + any = ).).).).).).).).

Note that if you wanted LED and Any mapped to [ and ] respectively, then you’d get { and } for free with Shift+LED and Shift+Any. Then making Shift+Fn+LED produce ( is as “easy” as adjusting the key on the Fn layer that’s in the LED position to read LSHIFT(Key_9). This also gets you Fn+LED as (, mind you, without the need for shift.

In your scenario, though, LED becomes {, Shift+LED becomes [, Fn+LED becomes (, and Fn+Shift+LED becomes <, right?

This will be a nice chain to implement! We’ll do it in two steps, first the { and [ part, then the other.

For the first, we basically want to swap the effect SHIFT has on the [ key, and we’ll use the TopsyTurvy plugin for that, which was made just for this:

#include "Kaleidoscope-TopsyTurvy.h"

// ....

void setup() {
 Kaleidoscope.use(
    // All the usual plugins
    &TopsyTurvy
 );
}

And in the keymap, on the QWERTY layer, use TOPSY(LeftBracket) at the LED position, TOPSY(RightBracket) for the ANY position. This should be all you need.

Now, the second part is a bit trickier, because we want to completely replace the symbol we get when shifted. The parentheses are shifted symbols to begin with. We can’t use TopsyTurvy here because we change the symbol, not just flip the character produced when the key is shifted for the one produced when non-shifted.

As it happens, there is a plugin for this too! It bears the scary name of ShapeShifter. We’ll use the fact that < is a shifted symbol too, and that allows us to use the ShapeShifter plugin. If it sees a certain key chorded with Shift, it will still use Shift, but instead of pressing the original key, it will simulate another. So we’ll tell it to treat Shift+LSHIFT(9) as Shift+,. Hopefully this explanation isn’t very confusing. Reading it back… it might be…

But lets see the code, perhaps that clears things up!

#include "Kaleidoscope-ShapeShifter.h"

static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = {
 {LSHIFT(Key_9), Key_Comma},
 {LSHIFT(Key_0), Key_Period},
 {Key_NoKey, Key_NoKey},
};

void setup() {
  Kaleidoscope.use(..., &ShapeShifter);
  ShapeShifter.dictionary = shapeShiftDictionary;
}

And on the FUNCTION layer, use LSHIFT(Key_9) for the LED position, and LSHIFT(Key_0) for ANY.

You’ll lose the Consumer_ScanPreviousTrack key though, because that’s at the ANY position on the FUNCTION layer, so you may want to move that somewhere else.

Hope this helps!

Clone this wiki locally