Combos and Macro Location

Hi,
I am trying to create a macro to handle combos to simulate a numpad using only five keys (I am using the keys placed under A, S, D, F and a key in the thumb cluster). I made a layer where A, S, D and F are mapped as 1, 2, 3 and 4 and the thumb key is 5.

I would like that when I press number 1 and 5, together, 6 is printed. I would extend this logic to cover all missing numbers and symbols using other key combinations, pressing two or three keys at a time.

In this layer, I set the keys under A, S, D, F and the thumb key as follows:
(showing only code under F, but the five keys look the same, but using 2, 3, 4 and 5 instead of 1)

‘’’
holdKey 1
‘’’

I created this second file, I placed it under macro named ‘chordscape’.

‘’‘’
ifKeyActive 1 {
ifShortcut timeoutIn 100 5 final tapKey 6
else final holdKey 1
}
ifKeyActive 5 {
ifShortcut timeoutIn 100 1 final tapKey 6
else final holdKey 5
}
‘’’
I copied this setup from a member of the forum. I am not sure why this is not working ony setup. I am using the lastest version of the firmware.

Thank you for your help

Fernando

It’s not working because the key active is not 1 but a. Keys are named after the US-QWERTY equivalent.

Oh, and you need to do the same in the ifShortcut command:

ifKeyActive a {
  ifShortcut timeoutIn 100 g final tapKey 6
  else final holdKey 1
}

etc.

(untested, I just wrote that down from memory)

thank you! I made the change and it still does not work.
I imagine that it is because the my macro named ‘chordscape’ is not mapped to any key.
Like I said in my intial post, the macros mapped to a, s, d, f… are:
‘’’
holdKey 1
‘’’
where should I map the macro ‘chordscape’?

Well, you need to map it to all the keys where you want to detect chording.

The key that is the first one to be pressed as part of a chord needs to be the one with a macro. In the macro, using the ifShortcut command, you check for the other keys that make up the chord.

For example, if you want to check for a and s together to send 3 when pressed together, but send 1 (for a) and 2 (for s) (when typed on their own), you have to solve these rules:

a pressed alone => send 1
s pressed alone => send 2
a pressed first and then together with s => send 3
s pressed first and then together with a => send 3

You starting key for the chord is a, but also another starting key is s (if you want both directions to work the same).

You can do this by creating 2 macros. The first one will be mapped to a, and the second one will be mapped to s. If you do that with two different macros, you do not need the ifKeyActive checks, because the macro will only run when that key has been activated (pressed).

chord-a:

ifShortcut timeoutIn 300 s final tapKey 3
holdKey 1

chord-s:

ifShortcut timeoutIn 300 a final tapKey 3
holdKey 2

For chord-a this means:

  1. ifShortcut: if the key a is pressed and shortly (within 300 ms) followed by a simultaneous press of the s key, then the final (last) command executed will send the scancode for the number 3. The macro will then stop and no further commands will be executed. (That’s the effect of final.)

  2. holdKey: if it wasn’t a chord (shortcut), then this command will send the scancode for the number 1 (held down for as long as you hold down the key).

For chord-s it will be similiar but with a and s reversed, and sending the number 2 instead of 1.

I don’t think I can explain this any more simply. Writing UHK macros requires a bit of programming skills.

2 Likes