Use Kaleidoscope-Ranges for the enable/disable keys

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent ec35d638d8
commit 842f6ed98a

@ -30,8 +30,8 @@ this sort of functionality on other keys, as well. Fortunately, the Space Cadet
plugin is configurable and extensible to support adding symbols to other keys. plugin is configurable and extensible to support adding symbols to other keys.
Along with `(` on your left `Shift` key and `)` on your right `Shift` key, Along with `(` on your left `Shift` key and `)` on your right `Shift` key,
you may wish to add other such programming mainstays as `{` to your left-side `cmd` key, you may wish to add other such programming mainstays as `{` to your left-side `cmd` key,
`}` to your right-side `alt` key, `[` to your left `Control` key, and `]` to your right `}` to your right-side `alt` key, `[` to your left `Control` key, and `]` to your right
`Control` key. You can map the keys in whatever way you may wish to do, so feel free to `Control` key. You can map the keys in whatever way you may wish to do, so feel free to
experiment with different combinations and discover what works best for you! experiment with different combinations and discover what works best for you!
[space-cadet]: https://en.wikipedia.org/wiki/Space-cadet_keyboard [space-cadet]: https://en.wikipedia.org/wiki/Space-cadet_keyboard
@ -53,7 +53,7 @@ void setup() {
``` ```
This assumes a US QWERTY layout on the host computer, though the plugin sends This assumes a US QWERTY layout on the host computer, though the plugin sends
the correct keymap code for each symbol. Because the mapping is entirely the correct keymap code for each symbol. Because the mapping is entirely
configurable, though, you may switch out keys at your leisure. configurable, though, you may switch out keys at your leisure.
If you wish to enable additional modifier keys (or disable the default behavior If you wish to enable additional modifier keys (or disable the default behavior
@ -108,7 +108,7 @@ properties:
> An object consisting of the key that is pressed, the key that should be sent > An object consisting of the key that is pressed, the key that should be sent
> in its place, and the timeout (in milliseconds) until the key press is > in its place, and the timeout (in milliseconds) until the key press is
> considered to be a "held" key press. The third parameter, the timeout, is > considered to be a "held" key press. The third parameter, the timeout, is
> optional and may be set per-key or left out entirely (or set to `0`) to use > optional and may be set per-key or left out entirely (or set to `0`) to use
> the default timeout value. > the default timeout value.
### `.time_out` ### `.time_out`
@ -125,7 +125,7 @@ properties:
> This method enables the SpaceCadet plugin. This is useful for interfacing > This method enables the SpaceCadet plugin. This is useful for interfacing
> with other plugins or macros, especially where SpaceCadet functionality isn't > with other plugins or macros, especially where SpaceCadet functionality isn't
> always desired. > always desired.
> >
> The default behavior is `enabled`. > The default behavior is `enabled`.
@ -133,12 +133,12 @@ properties:
> This method disables the SpaceCadet behavior. This is useful for interfacing > This method disables the SpaceCadet behavior. This is useful for interfacing
> with other plugins or macros, especially where SpaceCadet functionality isn't > with other plugins or macros, especially where SpaceCadet functionality isn't
> always desired. > always desired.
### `.active()` ### `.active()`
> This method returns `true` if SpaceCadet is enabled and `false` if SpaceCadet > This method returns `true` if SpaceCadet is enabled and `false` if SpaceCadet
> is disabled. This is useful for interfacing with other plugins or macros, > is disabled. This is useful for interfacing with other plugins or macros,
> especially where SpaceCadet functionality isn't always desired. > especially where SpaceCadet functionality isn't always desired.
### `Key_SpaceCadetEnable` ### `Key_SpaceCadetEnable`
@ -153,6 +153,10 @@ properties:
> behavior. This is only triggered on initial downpress, and does not > behavior. This is only triggered on initial downpress, and does not
> trigger again if held down or when the key is released. > trigger again if held down or when the key is released.
## Dependencies
* [Kaleidoscope-Ranges](https://github.com/keyboardio/Kaleidoscope-Ranges)
## Further reading ## Further reading
Starting from the [example][plugin:example] is the recommended way of getting Starting from the [example][plugin:example] is the recommended way of getting

@ -77,7 +77,8 @@ void SpaceCadet::begin() {
Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
//Handle our synthetic keys for enabling and disabling functionality //Handle our synthetic keys for enabling and disabling functionality
if (mapped_key.flags == (SYNTHETIC | IS_INTERNAL | SPACECADET_TOGGLE)) { if (mapped_key.raw >= kaleidoscope::ranges::SC_FIRST &&
mapped_key.raw <= kaleidoscope::ranges::SC_LAST) {
//Only fire the activate / deactivate on the initial press (not held or release) //Only fire the activate / deactivate on the initial press (not held or release)
if (keyToggledOn(key_state)) { if (keyToggledOn(key_state)) {
if (mapped_key == Key_SpaceCadetEnable) { if (mapped_key == Key_SpaceCadetEnable) {

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended * Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended
* Copyright (C) 2016, 2017 Gergely Nagy, Ben Gemperline * Copyright (C) 2016, 2017, 2018 Gergely Nagy, Ben Gemperline
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,16 +19,14 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-Ranges.h>
#ifndef SPACECADET_MAP_END #ifndef SPACECADET_MAP_END
#define SPACECADET_MAP_END (kaleidoscope::SpaceCadet::KeyBinding) { Key_NoKey, Key_NoKey, 0 } #define SPACECADET_MAP_END (kaleidoscope::SpaceCadet::KeyBinding) { Key_NoKey, Key_NoKey, 0 }
#endif #endif
#ifndef SPACECADET_TOGGLE #define Key_SpaceCadetEnable (Key) { .raw = kaleidoscope::ranges::SC_FIRST }
#define SPACECADET_TOGGLE B00000011 // Synthetic, internal #define Key_SpaceCadetDisable (Key) { .raw = kaleidoscope::ranges::SC_LAST }
#define Key_SpaceCadetEnable (Key) { 0, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | SPACECADET_TOGGLE }
#define Key_SpaceCadetDisable (Key) { 1, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | SPACECADET_TOGGLE }
#endif
namespace kaleidoscope { namespace kaleidoscope {
//Declaration for the method (implementing KaleidoscopePlugin) //Declaration for the method (implementing KaleidoscopePlugin)

Loading…
Cancel
Save