-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit provides a new plugin “LongPress” that allows producing different Keys when keys are held for a short time instead of only tapped. It is based on the existing “AutoShift” plugin and contains its functionality, but extends it for a broader area of application. Signed-off-by: Marco Herrn <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// -*- mode: c++ -*- | ||
|
||
#include <Kaleidoscope.h> | ||
|
||
#include <Kaleidoscope-LongPress.h> | ||
#include <Kaleidoscope-EEPROM-Settings.h> | ||
#include <Kaleidoscope-EEPROM-Keymap.h> | ||
#include <Kaleidoscope-FocusSerial.h> | ||
#include <Kaleidoscope-Macros.h> | ||
|
||
enum { | ||
TOGGLE_LONGPRESS, | ||
}; | ||
|
||
// clang-format off | ||
KEYMAPS( | ||
[0] = KEYMAP_STACKED | ||
( | ||
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, | ||
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, | ||
XXX, | ||
|
||
M(TOGGLE_LONGPRESS), Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, | ||
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_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, | ||
|
||
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, | ||
XXX | ||
), | ||
) | ||
// clang-format on | ||
|
||
// Defining a macro (on the "any" key: see above) to turn LongPress on and off | ||
const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) { | ||
switch (macro_id) { | ||
case TOGGLE_LONGPRESS: | ||
if (keyToggledOn(event.state)) | ||
LongPress.toggle(); | ||
break; | ||
} | ||
return MACRO_NONE; | ||
} | ||
|
||
// This sketch uses the LongPressConfig plugin, which enables run-time | ||
// configuration of LongPress configuration settings. All of the plugins marked | ||
// "for LongPressConfig" are optional; LongPress itself will work without them. | ||
KALEIDOSCOPE_INIT_PLUGINS( | ||
EEPROMSettings, // for LongPressConfig | ||
EEPROMKeymap, // for LongPressConfig | ||
Focus, // for LongPressConfig | ||
FocusEEPROMCommand, // for LongPressConfig | ||
FocusSettingsCommand, // for LongPressConfig | ||
LongPress, | ||
LongPressConfig, // for LongPressConfig | ||
Macros // for toggle LongPress Macro | ||
); | ||
|
||
void setup() { | ||
// Enable AutoShift for letter keys and number keys only: | ||
LongPress.setAutoshiftEnabled(LongPress.letterKeys() | LongPress.numberKeys()); | ||
// Add symbol keys to the enabled autoshift categories: | ||
LongPress.enableAutoshift(LongPress.symbolKeys()); | ||
// instead of shifting, produce a backslash on long pressing slash | ||
LONGPRESS( | ||
kaleidoscope::plugin::LongPressMapping(KeyAddr(1, 1), Key_Backslash), | ||
kaleidoscope::plugin::LongPressMapping(Key_E, LSHIFT(Key_E)), ) | ||
// Set the LongPress long-press time to 150ms: | ||
LongPress.setTimeout(150); | ||
// Start with LongPress turned off: | ||
LongPress.disable(); | ||
|
||
Kaleidoscope.setup(); | ||
} | ||
|
||
void loop() { | ||
Kaleidoscope.loop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cpu": { | ||
"fqbn": "keyboardio:avr:model01", | ||
"port": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_fqbn: keyboardio:avr:model01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# LongPress | ||
|
||
|
||
FIXME!!!! This needs to be rewritten! | ||
|
||
AutoShift allows you to type shifted characters by long-pressing a key, rather | ||
than chording it with a modifier key. | ||
|
||
## Using the plugin | ||
|
||
Using the plugin with its defaults is as simple as including the header, and | ||
enabling the plugin: | ||
|
||
```c++ | ||
#include <Kaleidoscope.h> | ||
#include <Kaleidoscope-AutoShift.h> | ||
|
||
KALEIDOSCOPE_INIT_PLUGINS(AutoShift); | ||
``` | ||
With AutoShift enabled, when you first press a key that AutoShift acts on, its | ||
output will be delayed. If you hold the key down long enough, you will see the | ||
shifted symbol appear in the output. If you release the key before the timeout, | ||
the output will be unshifted. | ||
## Turning AutoShift on and off | ||
The `AutoShift` object provides three methods for turning itself on and off: | ||
- To turn the plugin on, call `AutoShift.enable()`. | ||
- To turn the plugin off, call `AutoShift.disable()`. | ||
- To toggle the plugin's state, call `AutoShift.toggle()`. | ||
Note: Disabling the AutoShift plugin does not affect which `Key` categories it | ||
will affect when it is re-enabled. | ||
## Setting the AutoShift long-press delay | ||
To set the length of time AutoShift will wait before adding the `shift` modifier | ||
to the key's output, use `AutoShift.setTimeout(t)`, where `t` is a number of | ||
milliseconds. | ||
## Configuring which keys get auto-shifted | ||
AutoShift provides a set of key categories that can be independently added or | ||
removed from the set of keys that will be auto-shifted when long-pressed: | ||
- `AutoShift.letterKeys()`: Letter keys | ||
- `AutoShift.numberKeys()`: Number keys (number row, not numeric keypad) | ||
- `AutoShift.symbolKeys()`: Other printable symbols | ||
- `AutoShift.arrowKeys()`: Navigational arrow keys | ||
- `AutoShift.functionKeys()`: All function keys (F1-F24) | ||
- `AutoShift.printableKeys()`: Letters, numbers, and symbols | ||
- `AutoShift.allKeys()`: All non-modifier USB Keyboard keys | ||
These categories are restricted to USB Keyboard-type keys, and any modifier | ||
flags attached to the key is ignored when determining if it will be | ||
auto-shifted. Any of the above expressions can be used as the `category` parameter in the functions described below. | ||
- To include a category in the set that will be auto-shifted, call `AutoShift.enable(category)` | ||
- To remove a category from the set that will be auto-shifted, call `AutoShift.disable(category)` | ||
- To set the full list of categories that will be auto-shifted, call `AutoShift.setEnabled(categories)`, where `categories` can be either a single category from the above list, or list of categories combined using the `|` (bitwise-or) operator (e.g. `AutoShift.setEnabled(AutoShift.letterKeys() | AutoShift.numberKeys())`). | ||
## Advanced customization of which keys get auto-shifted | ||
If the above categories are not sufficient for your auto-shifting needs, it is | ||
possible to get even finer-grained control of which keys are affected by | ||
AutoShift, by overriding the `isAutoShiftable()` method in your sketch. For | ||
example, to make AutoShift only act on keys `A` and `Z`, include the following | ||
code in your sketch: | ||
```c++ | ||
bool AutoShift::isAutoShiftable(Key key) { | ||
if (key == Key_A || key == key_Z) | ||
return true; | ||
return false; | ||
} | ||
``` | ||
|
||
As you can see, this method takes a `Key` as its input and returns either `true` | ||
(for keys eligible to be auto-shifted) or `false` (for keys AutoShift will leave | ||
alone). | ||
|
||
## Plugin compatibility | ||
|
||
If you're using AutoShift in a sketch that also includes the Qukeys and/or | ||
SpaceCadet plugins, make sure to register AutoShift after those other plugins in | ||
order to prevent auto-shifts from getting clobbered. The recommended order is | ||
as follows: | ||
|
||
```c++ | ||
KALEIDOSCOPE_INIT_PLUGINS(Qukeys, SpaceCadet, AutoShift) | ||
``` | ||
It's not generally recommended to use AutoShift on the same key(s) handled by | ||
either Qukeys or SpaceCadet, as this can result in confusing behaviour. | ||
## Further reading | ||
Starting from the [example][plugin:example] is the recommended way of getting | ||
started with the plugin. | ||
[plugin:example]: /examples/Keystrokes/AutoShift/AutoShift.ino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name=Kaleidoscope-LongPress | ||
version=0.0.0 | ||
sentence=Provide different key strokes on long press | ||
maintainer=Kaleidoscope's Developers <[email protected]> | ||
url=https://github.com/keyboardio/Kaleidoscope | ||
author=Marco Herrn <[email protected]> | ||
paragraph= |
20 changes: 20 additions & 0 deletions
20
plugins/Kaleidoscope-LongPress/src/Kaleidoscope-LongPress.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* -*- mode: c++ -*- | ||
* Kaleidoscope-LongPress -- Provide different key strokes on long press | ||
* Copyright (C) 2024 Keyboard.io, Inc | ||
* | ||
* 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 the Free Software | ||
* Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "kaleidoscope/plugin/LongPress.h" // IWYU pragma: export |
Oops, something went wrong.