Dedicated brackets key

@Jennigma - This post of @algernon’s is probably worth lifting io its own tutorial.

3 Likes

I think @algernon is actually using TapDance for his brackets. Based on the number of times he taps that key in your image, he gets a different type of bracket. I plan on using TapDance for brackets as well.

These are exciting times.

Edit: by the way, who came up with all the awesome and cute plugin names?

1 Like

I came up with some of them, @jesse came up with others, and for some we put our heads together to name.

3 Likes

Ok. I have tested it out.

Implemented code as shown above. Only minor quirk was that you define the shapeshift dictionary as shape_shift_dictionary, but refer to it as shapeShiftDictionary.

So now:
led = {
any = }
fn + shift + led = <
fn + shift + any = >

BUT
shift + led = [[[[[[[[[[[[[[[[[[[[[
shift + any = ]]]]]]]]]]]]]]]]]]]]]]]]
fn + led = (,(,(,(,(,(,(,(,(,(,(,(,(,(
fn + any = ).).).).).).).).

So I am thinking that maybe - just maybe - I can settle for a less advanced layout for now :wink:

However I’d be happy if you would treat this as a bug report and take a look at it when you get a chance.

Or maybe there is another approach? A macro perhaps?

// -*- mode: c++ -*-
// Copyright 2016 Keyboardio, inc. <jesse@keyboard.io>
// See "LICENSE" for license details

#ifndef BUILD_INFORMATION
#define BUILD_INFORMATION "locally built"
#endif


/**
 * These #include directives pull in the Kaleidoscope firmware core,
 * as well as the Kaleidoscope plugins we use in the Model 01's firmware
 */


// The Kaleidoscope core
#include "Kaleidoscope.h"

// Support for keys that move the mouse
#include "Kaleidoscope-MouseKeys.h"

// Support for macros
#include "Kaleidoscope-Macros.h"

// Support for controlling the keyboard's LEDs
#include "Kaleidoscope-LEDControl.h"

// Support for "Numlock" mode, which is mostly just the Numlock specific LED mode
#include "Kaleidoscope-Numlock.h"

// Support for an "LED off mode"
#include "LED-Off.h"

// Support for the "Boot greeting" effect, which pulses the 'LED' button for 10s
// when the keyboard is connected to a computer (or that computer is powered on)
#include "Kaleidoscope-LEDEffect-BootGreeting.h"

// Support for LED modes that set all LEDs to a single color
#include "Kaleidoscope-LEDEffect-SolidColor.h"

// Support for an LED mode that makes all the LEDs 'breathe'
#include "Kaleidoscope-LEDEffect-Breathe.h"

// Support for an LED mode that makes a red pixel chase a blue pixel across the keyboard
#include "Kaleidoscope-LEDEffect-Chase.h"

// Support for LED modes that pulse the keyboard's LED in a rainbow pattern
#include "Kaleidoscope-LEDEffect-Rainbow.h"

// Support for an LED mode that lights up the keys as you press them
#include "Kaleidoscope-LED-Stalker.h"

// Support for an LED mode that prints the keys you press in letters 4px high
#include "Kaleidoscope-LED-AlphaSquare.h"

// Support for Keyboardio's internal keyboard testing mode
#include "Kaleidoscope-Model01-TestMode.h"

// Support for swapping shifts effects on a key
#include "Kaleidoscope-TopsyTurvy.h"

// Change symbols for keys
#include "Kaleidoscope-ShapeShifter.h"

/** This 'enum' is a list of all the macros used by the Model 01's firmware
  * The names aren't particularly important. What is important is that each
  * is unique.
  *
  * These are the names of your macros. They'll be used in two places.
  * The first is in your keymap definitions. There, you'll use the syntax
  * `M(MACRO_NAME)` to mark a specific keymap position as triggering `MACRO_NAME`
  *
  * The second usage is in the 'switch' statement in the `macroAction` function.
  * That switch statement actually runs the code associated with a macro when
  * a macro key is pressed.
  */

enum { MACRO_VERSION_INFO,
       MACRO_ANY
     };



/** The Model 01's key layouts are defined as 'keymaps'. By default, there are three
  * keymaps: The standard QWERTY keymap, the "Function layer" keymap and the "Numpad"
  * keymap.
  *
  * Each keymap is defined as a list using the 'KEYMAP_STACKED' macro, built
  * of first the left hand's layout, followed by the right hand's layout.
  *
  * Keymaps typically consist mostly of `Key_` definitions. There are many, many keys
  * defined as part of the USB HID Keyboard specification. You can find the names
  * (if not yet the explanations) for all the standard `Key_` defintions offered by
  * Kaleidoscope in these files:
  *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_keyboard.h
  *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_consumerctl.h
  *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_sysctl.h
  *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_keymaps.h
  *
  * Additional things that should be documented here include
  *   using ___ to let keypresses fall through to the previously active layer
  *   using XXX to mark a keyswitch as 'blocked' on this layer
  *   using ShiftToLayer() and LockLayer() keys to change the active keymap.
  *   the special nature of the PROG key
  *   keeping NUM and FN consistent and accessible on all layers
  *
  *
  * The "keymaps" data structure is a list of the keymaps compiled into the firmware.
  * The order of keymaps in the list is important, as the ShiftToLayer(#) and LockLayer(#)
  * macros switch to key layers based on this list.
  *
  *

  * A key defined as 'ShiftToLayer(FUNCTION)' will switch to FUNCTION while held.
  * Similarly, a key defined as 'LockLayer(NUMPAD)' will switch to NUMPAD when tapped.
  */

/**
  * Layers are "0-indexed" -- That is the first one is layer 0. The second one is layer 1.
  * The third one is layer 2.
  * This 'enum' lets us use names like QWERTY, FUNCTION, and NUMPAD in place of
  * the numbers 0, 1 and 2.
  */

enum { QWERTY, FUNCTION, NUMPAD }; // layers

/* This comment temporarily turns off astyle's indent enforcement
 *   so we can make the keymaps actually resemble the physical key layout better
 */
// *INDENT-OFF*

const Key keymaps[][ROWS][COLS] PROGMEM = {

  [QWERTY] = KEYMAP_STACKED
  (___,          Key_1, Key_2, Key_3, Key_4, Key_5, TOPSY(LeftBracket),
   Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
   Key_PageUp,   Key_A, Key_S, Key_D, Key_F, Key_G,
   Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
   Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
   ShiftToLayer(FUNCTION),

   TOPSY(RightBracket),  Key_6, Key_7, Key_8,     Key_9,         Key_0,         Key_KeypadNumLock,
   Key_Enter,            Key_Y, Key_U, Key_I,     Key_O,         Key_P,         Key_Equals,
                         Key_H, Key_J, Key_K,     Key_L,         Key_Semicolon, Key_Quote,
   Key_RightAlt,         Key_N, Key_M, Key_Comma, Key_Period,    Key_Slash,     Key_Minus,
   Key_RightShift,       Key_LeftAlt,  Key_Spacebar, Key_RightControl,
   ShiftToLayer(FUNCTION)),

  [FUNCTION] =  KEYMAP_STACKED
  (___,      Key_F1,           Key_F2,          Key_F3,           Key_F4,          Key_F5,           LSHIFT(Key_9),
   Key_Tab,  Key_mouseWarpEnd, Key_mouseWarpNW, Key_mouseUp,      Key_mouseWarpNE, Key_mouseBtnL,    Key_mouseScrollUp,
   Key_Home, Key_Insert,       Key_mouseL,      Key_mouseDn,      Key_mouseR,      Key_mouseBtnR,
   Key_End,  Key_PrintScreen,  Key_mouseWarpSW, Key_mouseWarpEnd, Key_mouseWarpSE, Key_mouseBtnM,    Key_mouseScrollDn,
   ___, Key_Delete, ___, ___,
   ___,

   LSHIFT(Key_0),              Key_F6,                 Key_F7,                   Key_F8,                   Key_F9,          Key_F10,          Key_F11,
   Consumer_PlaySlashPause,    Key_Home,               Key_UpArrow,              Key_End,                  Key_LeftBracket, Key_RightBracket, Key_F12,
                               Key_LeftArrow,          Key_DownArrow,            Key_RightArrow,           ___,             ___,              ___,
   Key_PcApplication,          Key_Mute,               Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___,             Key_Backslash,    Key_Pipe,
   ___, ___, Key_Enter, ___,
   ___),


  [NUMPAD] =  KEYMAP_STACKED
  (___, ___, ___, ___, ___, ___, Key_LEDEffectNext,
   ___, ___, ___, ___, ___, ___, ___,
   ___, ___, ___, ___, ___, ___,
   ___, ___, ___, ___, ___, ___, ___,
   ___, ___, ___, ___,
   ___,

   M(MACRO_VERSION_INFO),  ___, Key_Keypad7, Key_Keypad8,   Key_Keypad9,        Key_KeypadSubtract, ___,
   ___,                    ___, Key_Keypad4, Key_Keypad5,   Key_Keypad6,        Key_KeypadAdd,      ___,
                           ___, Key_Keypad1, Key_Keypad2,   Key_Keypad3,        Key_Equals,         Key_Quote,
   ___,                    ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide,   Key_Enter,
   ___, ___, ___, ___,
   ___)
};

// https://community.keyboard.io/t/dedicated-brackets-key/534/6
static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = {
  {LSHIFT(Key_9), Key_Comma},
  {LSHIFT(Key_0), Key_Period},
  {Key_NoKey, Key_NoKey},
 };
 
/* Re-enable astyle's indent enforcement */
// *INDENT-ON*

/** versionInfoMacro handles the 'firmware version info' macro
 *  When a key bound to the macro is pressed, this macro
 *  prints out the firmware build information as virtual keystrokes
 */

static void versionInfoMacro(uint8_t keyState) {
  if (keyToggledOn(keyState)) {
    Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope "));
    Macros.type(PSTR(BUILD_INFORMATION));
  }
}

/** anyKeyMacro is used to provide the functionality of the 'Any' key.
 *
 * When the 'any key' macro is toggled on, a random alphanumeric key is
 * selected. While the key is held, the function generates a synthetic
 * keypress event repeating that randomly selected key.
 *
 */

static void anyKeyMacro(uint8_t keyState) {
  static Key lastKey;
  if (keyToggledOn(keyState))
    lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36);

  if (keyIsPressed(keyState))
    kaleidoscope::hid::pressKey(lastKey);
}


/** macroAction dispatches keymap events that are tied to a macro
    to that macro. It takes two uint8_t parameters.

    The first is the macro being called (the entry in the 'enum' earlier in this file).
    The second is the state of the keyswitch. You can use the keyswitch state to figure out
    if the key has just been toggled on, is currently pressed or if it's just been released.

    The 'switch' statement should have a 'case' for each entry of the macro enum.
    Each 'case' statement should call out to a function to handle the macro in question.

 */

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  switch (macroIndex) {

  case MACRO_VERSION_INFO:
    versionInfoMacro(keyState);
    break;

  case MACRO_ANY:
    anyKeyMacro(keyState);
    break;
  }
  return MACRO_NONE;
}



// These 'solid' color effect definitions define a rainbow of
// LED color modes calibrated to draw 500mA or less on the
// Keyboardio Model 01.


static kaleidoscope::LEDSolidColor solidRed(160, 0, 0);
static kaleidoscope::LEDSolidColor solidOrange(140, 70, 0);
static kaleidoscope::LEDSolidColor solidYellow(130, 100, 0);
static kaleidoscope::LEDSolidColor solidGreen(0, 160, 0);
static kaleidoscope::LEDSolidColor solidBlue(0, 70, 130);
static kaleidoscope::LEDSolidColor solidIndigo(0, 0, 170);
static kaleidoscope::LEDSolidColor solidViolet(130, 0, 120);



/** The 'setup' function is one of the two standard Arduino sketch functions.
  * It's called when your keyboard first powers up. This is where you set up
  * Kaleidoscope and any plugins.
  */

void setup() {
  // First, call Kaleidoscope's internal setup function
  Kaleidoscope.setup();

  // Next, tell Kaleidoscope which plugins you want to use.
  // The order can be important. For example, LED effects are
  // added in the order they're listed here.
  Kaleidoscope.use(
    // The boot greeting effect pulses the LED button for 10 seconds after the keyboard is first connected
    &BootGreetingEffect,

    // The hardware test mode, which can be invoked by tapping Prog, LED and the left Fn button at the same time.
    &TestMode,

    // LEDControl provides support for other LED modes
    &LEDControl,

    // We start with the LED effect that turns off all the LEDs.
    &LEDOff,

    // The rainbow effect changes the color of all of the keyboard's keys at the same time
    // running through all the colors of the rainbow.
    &LEDRainbowEffect,

    // The rainbow wave effect lights up your keyboard with all the colors of a rainbow
    // and slowly moves the rainbow across your keyboard
    &LEDRainbowWaveEffect,

    // The chase effect follows the adventure of a blue pixel which chases a red pixel across
    // your keyboard. Spoiler: the blue pixel never catches the red pixel
    &LEDChaseEffect,

    // These static effects turn your keyboard's LEDs a variety of colors
    &solidRed, &solidOrange, &solidYellow, &solidGreen, &solidBlue, &solidIndigo, &solidViolet,

    // The breathe effect slowly pulses all of the LEDs on your keyboard
    &LEDBreatheEffect,

    // The AlphaSquare effect prints each character you type, using your
    // keyboard's LEDs as a display
    &AlphaSquareEffect,

    // The stalker effect lights up the keys you've pressed recently
    &StalkerEffect,

    // The numlock plugin is responsible for lighting up the 'numpad' mode
    // with a custom LED effect
    &NumLock,

    // The macros plugin adds support for macros
    &Macros,

    // The MouseKeys plugin lets you add keys to your keymap which move the mouse.
    &MouseKeys,

    // Swap the effect of the shift key
    &TopsyTurvy,

    // Change key codes for key
    &ShapeShifter
  );

  // While we hope to improve this in the future, the NumLock plugin
  // needs to be explicitly told which keymap layer is your numpad layer
  NumLock.numPadLayer = NUMPAD;

  // We configure the AlphaSquare effect to use RED letters
  AlphaSquare.color = { 255, 0, 0 };

  // We set the brightness of the rainbow effects to 150 (on a scale of 0-255)
  // This draws more than 500mA, but looks much nicer than a dimmer effect
  LEDRainbowEffect.brightness(150);
  LEDRainbowWaveEffect.brightness(150);

  // The LED Stalker mode has a few effects. The one we like is
  // called 'BlazingTrail'. For details on other options,
  // see https://github.com/keyboardio/Kaleidoscope-LED-Stalker
  StalkerEffect.variant = STALKER(BlazingTrail);

  // We want to make sure that the firmware starts with LED effects off
  // This avoids over-taxing devices that don't have a lot of power to share
  // with USB devices
  LEDOff.activate();

  // activeate shapeshifter
  ShapeShifter.dictionary = shape_shift_dictionary;
}

/** loop is the second of the standard Arduino sketch functions.
  * As you might expect, it runs in a loop, never exiting.
  *
  * For Kaleidoscope-based keyboard firmware, you usually just want to
  * call Kaleidoscope.loop(); and not do anything custom here.
  */

void loop() {
  Kaleidoscope.loop();
}

Whops, my bad, sorry!

:frowning:

I hoped that using a modifier won’t trigger this issue, but it does. I’ll try to fix it this coming weekend.

It could be done with a macro, but… that’s a bit more complicated than one would expect. If you can hold on a little bit longer, I’d try fixing the TopsyTurvy and ShapeShifter plugins first.

1 Like

I brought up this exact issue in this thread. Jesse says he comfortably uses ring, pinky and middle fingers for those, on WASD! Seems totally outlandish to me! :smiling_face:

3 Likes

I was thinking the same about TopsyTurvy and ShapeShifter!

Those two, and TapDance, and a few others are mine. Happy to hear you like the whimsical names too :joy:

6 Likes

Rumor has it that for the Model 02, Plugin Naming Rights will be one of the Kickstarter reward levels.

Seriously though, they are fun names.

2 Likes

Working on this, but not sure how to handle the defect. Should I write as if the defect has been corrected?

I’d…probably write as if the defect had been corrected, but with a big bold note that there’s a defect? That’ll help inform users and be easiest to update when it’s resolved.

Note that @jesse has mentioned it’s binary, so next would be Model10 :wink:

2 Likes

But that means, with the given number of digits, there are not more than two Models to come. That’s… sad.

1 Like

@jesse @algernon @lasse -

here’s my excerpt of this thread. Please proofread, and I’ll link it in the sidebar when it passes muster. :slight_smile:

For now I’d just strongly recommend the “free” brackets key that @algernon first suggested. It is the one I ended up with (for the time being)

But the full solution is still very relevant. If instead of using a US layout I switched to a Danish layout I’d be in even more trouble.

  • ( = shift + 8
  • { = altgr + 7
  • [ = altgr + 8
  • < = the special <> key which also gives us \ with altgr on nordic keyboards

So instead of slaying this monster I vent on to slay the monster of inputting international characters on a US layout keyboard. That fight is won on MacOS, but I ran into issues on windows. So status monday morning is that my Model01 is almost, but not quite, ready to bring with me to work …

3 Likes

I’ve gone in a slightly different direction here. PgUp and PgDn didn’t seem to me to deserve unshifted keys; so I’ve done this:

  • moved [ / { to PgUp and ] / } to PgDn, with parentheses on the Fn-shifted versions
  • moved the cursor keys to IJKL, for the same reasons as you
  • moved PgUp to Fn-U and PgDn to Fn-O
  • moved Home to Fn-H and End to Fn-; (leaving Fn-P unused)

I like this a lot, as it puts all the motion keys together on the right hand, and makes the delimiters easier to type. (On the host I rotate the delimiters, so parentheses are unshifted, brackets are shifted, and braces are Fn-shifted; this is actually a remapping I’ve done for many years for standard keyboards. It’s not immediately obvious to me how to do this in the Model 01 firmware, though I guess there must be a way.)

I like what you’ve done with the mouse keys, though. I might copy that.

In @algernon post about you can see how to use TOPSY(LeftBracket) to swap the two.

The inverse T for mouse keys is a success. Warping NW and NE too. SE and SW not so much.
having T as left-click is cool since it easy for at gamer to learn. But not cool, if you need to drag og select text, so I am looking for another / alternative solution for that.

I moved the mouse keys around so they fall as follows:

     NW   up   NE   NoWarp
LBut left down rght RBut
PrSc SW   MBut SE   insert

See https://github.com/andrewgdotcom/Model01-Firmware/blob/master/layer-abg-function-inverted-t.h

The idea is that the left button is the one most often held down during a drag, so it is on a different finger from the three required for navigation. The warp keys are arranged in a square around the inverted-t so that they are in an intuitive position and can be used comfortably by the same three fingers.

4 Likes

If the ‘01’ were a constant in many programming languages, it would be in octal, but ignoring that convention it could be that the next product would be the Model010, with the Model011 to follow.

2 Likes

Naming it Model 010 would also prevent reduce the number of people calling it the “model ten” like they would if it were Model 10.

1 Like