# Implementing a "better shifting" function

**URL:** <https://community.keyboard.io/t/implementing-a-better-shifting-function/1630>\
**Category:** Programming\
**Created:** [June 13, 2018, 5:31pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630 "2018-06-13T17:31:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 5:31pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/1 "2018-06-13T17:31:25Z")

</div>

Inspired by [this article](http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#better-shifting), I decided to program my M01 to only allow me to type shifted alphanumeric keys on the left side if the right shift key is pressed, and vice versa.

I got it working by defining two new layers, appropriately named SHIFT\_LEFT and SHIFT\_RIGHT. The former has only the left half defined (with the right half being filled with XXX), and the latter is the opposite. Shifting is accomplished by using the LSHIFT() macro on all the keys.

This solution has a few bugs, though, and before I go about fixing them, I’m curious if there’s a better way. I considered making a simple plugin that basically disables keypresses on one half of the keyboard while that half’s shift key is pressed, but I’m not sure if this is possible in a plugin (let alone how to actually go about doing it, though I’m willing to learn).

(Obviously I could just install the software in that post, but I always like to avoid installing new software if I can.)

---

<div class="post-metadata">

**Author:** ![bagels](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/bagels/32/1040_2.png) [@bagels](https://community.keyboard.io/u/bagels)\
**Post date:** [June 13, 2018, 6:05pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/2 "2018-06-13T18:05:09Z")

</div>

It’d be fairly simple to write a plugin to do this. You’d basically watch for key press events on Shift and set a boolean flag to disable the opposite half. You’d disable the flag on Shift key release events. The other part of the plugin then would be to watch all non-shift key press events and block those events (return false) for the other half of the keyboard. You can tell which row and column where pressed in the keypress handler, so it’s trivial to do that by the column of the pressed key.

---

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 6:18pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/3 "2018-06-13T18:18:11Z")

</div>

I assume that that logic would just go into Plugin::onKeyswitchEvent(). I’m not sure what the EventHandlerResult return value would be, though.

---

<div class="post-metadata">

**Author:** ![bagels](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/bagels/32/1040_2.png) [@bagels](https://community.keyboard.io/u/bagels)\
**Post date:** [June 13, 2018, 6:23pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/4 "2018-06-13T18:23:31Z")

</div>

You might take a look at the SpaceCadet source for an example.

> <https://github.com/keyboardio/Kaleidoscope-SpaceCadet/blob/master/src/Kaleidoscope/SpaceCadet.cpp>

---

<div class="post-metadata">

**Author:** ![bagels](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/bagels/32/1040_2.png) [@bagels](https://community.keyboard.io/u/bagels)\
**Post date:** [June 13, 2018, 6:27pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/5 "2018-06-13T18:27:06Z")

</div>

Essentially, you return `EventHandlerResult::EVENT_CONSUMED` if you are suppressing the key press, and return `EventHandlerResult::OK` if you’re letting it go through.

---

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 6:27pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/6 "2018-06-13T18:27:35Z")

</div>

Awesome, thanks. I’ll see what I can do.

---

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 7:25pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/7 "2018-06-13T19:25:50Z")

</div>

So, I’ve got the plugin written, and it seems to build, but I’m not sure how/where to put the files so that my Model01-Firmware.ino can find them. I tried linking the directory into hardware/keyboardio/avr/libraries, but that didn’t work.

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [June 13, 2018, 7:30pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/8 "2018-06-13T19:30:07Z")

</div>

> [@tiltowaitt](#):
>
> I’m not sure how/where to put the files so that my Model01-Firmware.ino can find them

You’ll have to turn them into an [Arduino Library](https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification), and make that library available for Arduino. Putting them into a `hardware/keyboardio/avr/libraries` is on the right path: you need to name your plugin, create a subdirectory there with that name, create a `library.properties` file (copy one from the existing plugins and modify it, it’s a trivial format), put your source files under the `src/` directory of the plugin directory.

Then it should be accessible for Arduino.

If you need further help, let me know. If you can share your current sketch, I can walk you through extracting the plugin files into a proper plugin, in its own repo.

---

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 7:43pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/9 "2018-06-13T19:43:42Z")

</div>

Thanks. It turns out I had a typo in one of my header files. I can get it to build, now. It doesn’t _work_ yet, mind, but I’m getting there.

---

<div class="post-metadata">

**Author:** ![tiltowaitt](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/tiltowaitt/32/4764_2.png) [@tiltowaitt](https://community.keyboard.io/u/tiltowaitt)\
**Post date:** [June 13, 2018, 8:34pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/10 "2018-06-13T20:34:33Z")

</div>

And I got it working.

> **[tiltowait/Kaleidoscope-BetterShifting](https://github.com/tiltowait/Kaleidoscope-BetterShifting)**
>
> Kaleidoscope module for proper shifting technique. - tiltowait/Kaleidoscope-BetterShifting

Not sure if it will be of any use to anyone else, but there it is.

---

<div class="post-metadata">

**Author:** ![bagels](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/bagels/32/1040_2.png) [@bagels](https://community.keyboard.io/u/bagels)\
**Post date:** [June 15, 2018, 11:06pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/11 "2018-06-15T23:06:34Z")

</div>

Awesome job! I might take a look at it myself to see if I can force myself into shifting properly.

---

<div class="post-metadata">

**Author:** ![ericeslinger](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/ericeslinger/32/2007_2.png) [@ericeslinger](https://community.keyboard.io/u/ericeslinger)\
**Post date:** [June 22, 2018, 4:50pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/12 "2018-06-22T16:50:15Z")

</div>

hmm, would you be able to do something similar in splitting the left and right function keys? i’ve been thinking about splitting the keyboard’s function … function to be local to the side of the board where it is pressed (since i usually use the base of my thumb on the modified side anyway, and this allows a few other chords to be more easily accessible.

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [June 22, 2018, 6:35pm UTC](https://community.keyboard.io/t/implementing-a-better-shifting-function/1630/13 "2018-06-22T18:35:48Z")

</div>

> [@ericeslinger](#):
>
> hmm, would you be able to do something similar in splitting the left and right function keys?

You can map one of the `Fn` keys to `ShiftToLayer(SOME_LAYER)`, and the other to `ShiftToLayer(ANOTHER_LAYER)`, and voila! (I’m doing something similar - well, the same, only with OneShot layers -, and it works like a charm.)
