Can I change secondary role according to the second key pressed?

Hi guys! I was wondering if it’s possible to program a key like a “Ctrl” like secondary role, with a normal letter as primary role, but, when the key is pressed accompanied by particular key, it changes “Ctrl” to “Alt”.
In other words, I want to have the key “R”, as “R” as primary role, and as “Ctrl” as secondary role but when I pressed “W”, I want that key (“R”) be “Alt” and the “W” became as “Tab”. And the secondary role be “Ctrl” with any other key but “W”.
Thanks in advanced!

You’d have to write a smart macro for that; it’s not available directly from the Agent “clickable” interface.

1 Like

Thanks @maexxx for answering, I’m gonna try to build the macro.

I just tried this, and the best I could come up with is this: For my test setup, I used the f key to work as Ctrl (secondary function), and d as the special key that will be sent with rightAlt (instead of Ctrl) when it’s pressed as f+d.

  1. I configured f with a secondary function to activate leftControl

  1. I created a macro called ‘ralt-s-s’ (but you can use any name of course) with this code:
ifKeyActive $keyId.f {
    releaseKey leftControl
    suppressMods holdKey RA-d
}
else holdKey d

The code is entered here as ‘Macro commands’:

  1. I mapped d to run this macro:

This is the result:

  • When I press d on it’s own, I get d. (You can also hold it for autorepeat.)
  • When I press f+d, I get a short tap on leftControl, and then rightAlt+d.
  • When I press f together with any other key, I get leftControl+the other key.

Autorepeat on f is lost, because holding it down is now the same as holding down leftControl.

If you want to use leftAlt instead of rightAlt, you have to change the ‘RA-’ in the macro to ‘LA-’. For my experiment it was easier to use rightAlt, because on my international keymap combining keys with rightAlt just types different international characters, and it’s easy for me to observe the effect.

2 Likes

Would just chaining ifSecondary with ifShortcut work?

ifSecondary {
    ifShortcut w final holdKey LA-tab
    final holdKey LC
}
holdKey r
2 Likes

Maybe, but you’d have to press the keys within the ifShortcut timeout, wouldn’t you? I haven’t tried it.

Another difference is which key needs the macro mapped to.

BTW, @kareltucek I think your example code should read ifShortcut tab… instead of ifShortcut r… (and the macro needs to be mapped to the r key).

1 Like

You would, but the question asks for a secondary role on an alphabetic key, which I assume has its own timeout which is shorter than the ifShortcut’s one.

I am not at all comfortable with composing time-machine functionality this way (it is like putting a time machine in a time machine), but by definition I think that is what was asked for, and what (by definition) should work.

BTW, @kareltucek I think your example code should read ifShortcut tab… instead of ifShortcut r… (and the macro needs to be mapped to the r key).

w actually. Good catch!

1 Like

See, I don’t think this is needed. They just want to use r as a Control key except for when it’s used with w, then they want Alt-w. So I reinterpreted this as: r acts as a control key, but when you press w, the Control (if caused by r) gets changed into Alt. That doesn’t need any time machinery (except for the initial secondary function on r).

It’s so fascinating what you can do with the macro language that you have created. So many options!

Er… yes, of course. Glad that between the two of us, we can eventually sort this out! :laughing:

Wow @maexxx , that was really amazing, the macro is really reliable. Thanks for your elaborated answer, I was struggling with the change between Control and Alt and how to detect the active key. I need to improve my skills on the macro language, the posibilties are huge.

Thanks, @kriker97, I am glad it works well for you.

BTW, a question to @kareltucek:

My piece of code

would not work without the releaseKey statement. But I thought suppressMods on the next statement should be sufficient? But it wasn’t. So I threw in the additional releaseKey, and then it worked.

I tested this on UHK80, haven’t tried it on UHK60.

2 Likes

Congratulations, you have found a bug :slight_smile:

2 Likes

That seems to be one of my special skills :smile:

2 Likes

:smiley: Please keep on reporting them!

2 Likes