I’ve been trying to figure out how to configure my spacebar to perform two functions on one key. This is specific to games with seperate dodge and jump mechanics. Helldivers 2 has this baked in to its controller configuration, I want to emulate the same behaviour in other games.
Desired behaviour:
Tap key, dodge (timing is more critical as this is normally a combat function)
Hold key, jump (less critical)
I have niavely tried:
tapKey space
holdKey ;
Unfortunately, both both ‘space’ and ‘;’ trigger immediately, so it would seem there is something wrong with my undestanding of ‘tapKey’
Those are commands, not conditionals. They both execute, one after another, the only difference being that holdKey holds the key (scancode) for as long as the activation key (i.e., physical key) is held, while tapKey just briefly activates and then immediately releases.
For timeout based conditional, you may want to use secondary roles with the advanced configuration (disable both triggerByPress and triggerByRelease, making it trigger by timeout only). With 4.x Agent you can do this all using gui. Although this has the problem that it will activate the dodge on key release rather than press, which is probably something you don’t want.
Admittedly, I should introduce some abstraction for hold conditional. But it would have the same timing drawbacks as the above.
As @kareltucek already wrote, your macro commands will be executed in order. If you want to make a distinction between a primary function (short tap on key) and a secondary function (holding the key), you need to be explicit about this.
You will also need to set the criteria for the distinction, i.e. the time interval that differenciates between primary (tap) and secondary (hold) function.
ChatGPT eventually got me to this solution. I wanted a long-press of C to perform Copy (ctrl-C) and similarly for Z, X, and V.
set secondaryRole.defaultStrategy advanced set secondaryRole.advanced.timeout 500 set secondaryRole.advanced.timeoutAction secondary set secondaryRole.advanced.triggerByRelease 0
ifSecondary advancedStrategy final tapKey LC-c ifPrimary advancedStrategy final tapKey c
Can this be simplified? My first attempt didn’t copy and always typed a C even on long-press.
set secondaryRole.advanced.timeout 500 ifSecondary final tapKey LC-c tapKey c
Also, can I perform a visual indicator (flash the backlight or LED) or play a short sound for the long-press?
I’m just dipping my toes into homerow mods, and I have the following typing behavior settings in $onKeymapChange XXX for the keymaps I want to use secondary roles on:
set keystrokeDelay 10
set secondaryRole.defaultStrategy advanced
set secondaryRole.advanced.triggeringEvent release
set secondaryRole.advanced.timeout 300
set secondaryRole.advanced.timeoutAction secondary
set secondaryRole.advanced.doubletapToPrimary 1
set secondaryRole.advanced.safetyMargin -50
set secondaryRole.advanced.triggerByMouse 1
set secondaryRole.advanced.minimumHoldTime 130
set secondaryRole.advanced.acceptTriggersFromSameHalf 0
You may need to tweak the timings a bit, but that should be a decent starting point.
Otherwise, I have simple typing behavior set for other keymaps (gaming especially) so I don’t trigger anything weird unexpectedly.
With those settings, I can then use the following macro to achieve what I think you’re after:
ifSecondary final tapKey LC-c
holdKey c
That should allow you to type normally, but copy on hold. Keep in mind that in order to use the OS key-repeat function, you’d need to double-tap and hold (doubletapToPrimary) that key, since a normal hold is performing the copy or whatever.