hold(set(foo,1)) ?
Hello,
So ive been reading the macros docs and im not able to figure out how to solve my problem.
The thing is when i map 'alt-f' to 'alt-j', as soon as the injection is finished the keys are released, although i keep the alt key pressed physically. I've also been in the advanced section of the mappings and tried the 'release input' feature with no luck.
Ive tried this:
alt_l = hold(key(alt_L).set(foo, 1)) f = if_eq(foo, 1, key(j), key(f))
What ive tried to do here is to have foo set to 1 only when alt_L is being pressed, so that f is modified only during the alt keystroke.
It does not work. I don't think it's even setting foo to 1, cause the desired translation (alt-f to alt-j) does not take place at all.
The conceptual solution would be to have a function that has a var set to a value only during the time of an event happening -as a key press-.
I also believe that there has to be a way to do this with current features. I just don't know how.
Thanks in advance.
So it looks like you were missing the $ in the if_eq's variable read, which means it wont read the variable. You're also never unsetting foo or setting it to something that's not 1.
My exact setup for this, which I mainly use for cross device macros is...
Control L:
set(LEFTCTRL,1).
hold_keys(KEY_LEFTCTRL).
set(LEFTCTRL,0)
F1:
if_eq(
$LEFTCTRL,1,
then=hold_keys(KEY_F13),
else=hold_keys(KEY_F1)
)
I've been saving interesting and tricky macros for input-remapper on my Github page and this looks like one that I would like to add. I include the problem it is designed to resolve, the macro/string used to do so, and comments for how it does each step. Would you mind breaking this down for me so I can add it to my page? To me, it looks like the intent is to press one key and bind it to a macro that presses Alt-J then Alt-F, but the key presses don't look like what I recall seeing in similar macros.
@TherinS In this example the LEFTCTRL key retains its core functionality as LEFTCTRL, but it sets an input-remapper internal variable set(LEFTCTRL,1) that says "left ctrl is being held down." When you release the LEFTCTRL, it sets set(LEFTCTRL,0) which says "left ctrl is not being held down".
If you want to have layered macros that aren't affected by the key functionality of actually pressing LEFTCTRL, then this solution isn't ideal as LEFTCTRL is still actively triggered via hold_keys(KEY_LEFTCTRL). If you don't want that you could replace it something like hold() which would do nothing over and over until you let go of LEFTCTRL.
Now any other key combo can have a check if_eq($LEFTCTRL,1,... it to ask "is LEFTCTRL down?" If it's 1, yes, then do this, if not, then do that.
My example simply replaces any interaction with F1 to F13 if I'm holding LEFTCTRL so F1 by itself is F1 but LEFTCTRL + F1 becomes LEFTCTRL + F13
If you want to replace Alt-J with Alt-F in specific instances you will need a 3rd key to switch J with F.
If you always want Alt-J to trigger Alt-F then LAlt can be set to...
set(LEFTALT,1).
hold_keys(KEY_LEFTALT).
set(LEFTALT,0)
...and J can be...
if_eq(
$LEFTALT,1,
hold_keys(KEY_F),
hold_keys(KEY_J)
)
Do I understand this correctly? When you press and hold alt, and then press and hold f, you want j to be injected. If you continue to hold them down, I suppose you expect "jjjjjjjjjjj" to be written.
This is how I'd do it, but maybe I'm missing something:
If you enable 'release input':
- finger presses alt
- system writes alt down
- finger presses f
- input-remapper writes alt up
- input-rempaper writes j down
- lifting fingers
- input-remapper writes j up
If you disable it:
- finger presses alt
- system writes alt down
- finger presses f
- input-rempaper writes j down
- lifting fingers
- input-remapper writes alt up
- input-remapper writes j up