Add an .isModifierActive method

Useful when writing an event handler that needs to check if a modifier is
active, but may run before OneShot has a chance to re-register the given
modifier.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 417ff1a07e
commit 7d024cabc0

@ -94,6 +94,12 @@ modifiers and one-shot layer keys. It has the following methods:
> useful for macros that need to fiddle with either modifier or layer state: if
> one-shots are not active, they need not restore the original state.
### `.isModifierActive(key)`
> Returns if the modifier `key` has a one-shot state active. Use this together
> with `Keyboard.isModifierActive` to catch cases where a one-shot modifier is
> active, but not registered yet.
### `.cancel([withStickies])`
> The `cancel()` method can be used to cancel any pending one-shot effects,

@ -38,7 +38,7 @@ namespace Akela {
#define isModifier(key) (key.raw >= Key_LCtrl.raw && key.raw <= Key_RGUI.raw)
#define isLayerKey(key) (key.flags == (KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP) && key.keyCode >= MOMENTARY_OFFSET && key.keyCode <= MOMENTARY_OFFSET + 23)
#define isOneShot(idx) (bitRead (State, idx))
#define isOneShot(idx) (bitRead (State, (idx)))
#define setOneShot(idx) (bitWrite (State, idx, 1))
#define clearOneShot(idx) (bitWrite (State, idx, 0))
@ -258,6 +258,14 @@ namespace Akela {
return (State && !hasTimedOut () && !shouldCancel);
}
bool
OneShot::isModifierActive (Key key) {
if (key.raw < Key_LCtrl.raw || key.raw > Key_RGUI.raw)
return false;
return isOneShot (key.keyCode - Key_LCtrl.keyCode);
}
void
OneShot::cancel (bool withStickies) {
shouldCancel = true;

@ -37,6 +37,8 @@ namespace Akela {
static void cancel (bool withStickies);
static void cancel (void) { cancel (false); };
static bool isModifierActive (Key key);
void inject (Key key, uint8_t keyState);
private:

Loading…
Cancel
Save