Avoid macro duplication for numbers row

Sometimes I miss the F-numbers row a bit and I created a macro which taps a number on a short press and a F-key on a long press.

E.g. the script for 1/F1 is:

delayUntilReleaseMax 200
ifPlaytime 199 final tapKey f1
tapKey 1

As I do not like to repeat myself (DRY principle), I though about a ‘one macro’-solution instead of 12.

I thought that it might be possible with the KEYIDs, subtraction and string concatenation.
But both seem not be possible in macros.

Any suggestion is welcome.

1 Like

Indeed not possible.

Best suggestion I have is to open a github ticket and try to talk me and Laszlo into allowing saving scancodes into registers and using them in SHORTCUT parameters… …the trouble is that those commands take shortcuts, which is one grade more general concept than a single numeric scancode.

Also, these are not KEYIDs (integers identifying physical positions on keyboard), they are SHORTCUTS (aka scancodes, possibly accompanied with modifier masks).

Thinking about this a bit more, there is this dark magic: activateKeyPostponed [atLayer LAYERID] KEYID which allows you to induce key activation from different layer, so you could map the f1-f12 in (e.g.) fn2 layer at corresponding locations, and then 1-10 in yet another layer and have:

delayUntilReleaseMax 200
ifPlaytime 199 final activateKeyPostponed atLayer fn2 $thisKeyId
activateKeyPostponed atLayer fn3 $thisKeyId

Edit: updated deprecated syntax


This looks interesting, although I am not sure if it worth the hassle. (I will wonder what these extra layers do, when I look at my configuration after 6 months.)
But I will try it, perhaps it useful for something else.

Regarding your comment, my idea was to convert a KEYID to a scancode symbol.

In (probably incomplete) pseudo code:

scancode = null
if #keyid between 65 and 70:
  scancode = #keyid - 64
else if #keyid between 0 and 5:
  scancode = #keyid + 7
ifPlaytime 199 final tapKey ("f" + scancode)
tapKey scancode 

I have only skipped over your other thread, but imho KEYID and scancode symbols get easily confused by people which do not exactly know the in and outs of a keyboard. (aka new customers, and also people like me which write their macros and then forget about them, because they are working.)


With the 10.3 firmware update, I revisited my question and I think the arithmetic part is now possible.
The part which is missing, is that tapKey expects a SHORTCUT, but I can only provide a STRING.

Take this (useless) script as an example:

setVar scancode ($thisKeyId - 64)
tapKey "$scancode"

which is not valid because: Unrecognized key abbreviation: "$scancode"

I get that a conversion from STRING to SHORTCUT does not exist, as it is a cast which might fail which would result in runtime errors.
(I do not think macro runtime errors are possible at the moment, or are they?)

Macro runtime errors are possible. For instance non-existent goTo target will generate one.

The way you suggest using the syntax is not entirely unreasonable, but it is not implemented at the moment, and poses a number of technical issues that I am not sure I can justify.

The suggestion to use the activateKeyPostponed [ append | prepend ] atLayer <layer> <keyId> still applies.

Admittedly, it would be nice if it was possible to parametrize a macro without a need to duplicate it, but I don’t see any reasonable way to do it.

Just for a short clarification, my current setup is not bothering me.
I just wanted to try the new conditions and arithmetic operations added with 10.2 and 10.3. :slight_smile:

I am quite impressed that they were added to the macro syntax, because the macros are now nearly a full programming language.

1 Like

I want to try this dark magic too. Thanks @kareltucek , I was wondering how to do something like this, but it wasn’t clear in my mind to ask for this, and now I find it, the forum is great.

1 Like