abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyEventHandler.java
diff options
context:
space:
mode:
authorJules Aguillon2025-02-23 12:12:29 +0100
committerGitHub2025-02-23 12:12:29 +0100
commit68be82a4f92f47300b9960cf9cf65040c96f17ed (patch)
treece79243fe3c1fff7b799af2040a7a76377e4ad5f /srcs/juloo.keyboard2/KeyEventHandler.java
parent581b31bf99bf7a4088ef12ea7e03fbc75d5acfed (diff)
downloadunexpected-keyboard-68be82a4f92f47300b9960cf9cf65040c96f17ed.tar.gz
unexpected-keyboard-68be82a4f92f47300b9960cf9cf65040c96f17ed.zip
Macro keys (#878)
Add "macro" keys that behave as if a sequence of keys is typed. Macro can be added to custom layouts or through the "Add keys to the keyboard option". The syntax is: symbol:key1,key2,.. The symbol cannot contain a : character. 'key1', 'key2', etc.. are: - 'String with \' escaping' The key will generate the specified string. - keyevent:123 The key will send a keyevent. - The name of any special key
Diffstat (limited to 'srcs/juloo.keyboard2/KeyEventHandler.java')
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java34
1 files changed, 31 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 6809d88..d2546ab 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -97,11 +97,10 @@ public final class KeyEventHandler
case Keyevent: send_key_down_up(key.getKeyevent()); break;
case Modifier: break;
case Editing: handle_editing_key(key.getEditing()); break;
- case Compose_pending:
- _recv.set_compose_pending(true);
- break;
+ case Compose_pending: _recv.set_compose_pending(true); break;
case Slider: handle_slider(key.getSlider(), key.getSliderRepeat()); break;
case StringWithSymbol: send_text(key.getStringWithSymbol()); break;
+ case Macro: evaluate_macro(key.getMacro()); break;
}
update_meta_state(old_mods);
}
@@ -319,6 +318,35 @@ public final class KeyEventHandler
send_key_down_up_repeat(KeyEvent.KEYCODE_DPAD_DOWN, d);
}
+ void evaluate_macro(KeyValue[] keys)
+ {
+ final Pointers.Modifiers empty = Pointers.Modifiers.EMPTY;
+ // Ignore modifiers that are activated at the time the macro is evaluated
+ mods_changed(empty);
+ Pointers.Modifiers mods = empty;
+ final boolean autocap_paused = _autocap.pause();
+ for (KeyValue kv : keys)
+ {
+ kv = KeyModifier.modify(kv, mods);
+ if (kv == null)
+ continue;
+ if (kv.hasFlagsAny(KeyValue.FLAG_LATCH))
+ {
+ // Non-special latchable keys clear latched modifiers
+ if (!kv.hasFlagsAny(KeyValue.FLAG_SPECIAL))
+ mods = empty;
+ mods = mods.with_extra_mod(kv);
+ }
+ else
+ {
+ key_down(kv, false);
+ key_up(kv, mods);
+ mods = empty;
+ }
+ }
+ _autocap.unpause(autocap_paused);
+ }
+
/** Repeat calls to [send_key_down_up]. */
void send_key_down_up_repeat(int event_code, int repeat)
{