Snap Tap/Null Movement/Last Input Priority/Simultaneous Opposing Cardinal Directions (SOCD)

I’ve optimised the macros a bit more.

The worker (snap-leftright-worker) will now self-terminate if more than 5 seconds have passed and you release both keys. As long as you keep at least one of the keys pressed it will keep working (looping). And it will always run for at least 5 seconds even if you release both keys during that time.

This limits the amount of forking to a maximum of 1 fork per 5 seconds, and it also limits the runtime of the worker to a maximum of 5 more seconds once you let go of the keys.

It will indicate when the worker is running by showing <-> on the Led display.

The initiator (snap-leftright) is now also shorter and more concise. Less code to execute on each keypress. Faster to set the new mode when it registers a new keypress.

snap-leftright:

if ($thisKeyId == $keyId.j) setVar snap_mode 1
else if ($thisKeyId == $keyId.l) setVar snap_mode 2
else setVar snap_mode 0
if ($snap_running == 0) fork snap-leftright-worker
delayUntilRelease
ifKeyActive $keyId.j final setVar snap_mode 1
ifKeyActive $keyId.l final setVar snap_mode 2
setVar snap_mode 0

snap-leftright-worker:

setVar snap_running 1
setVar snap_state 0
setLedTxt 0 '<->'
loop:
if ($snap_state == 0) {
    if ($snap_mode == 1) {
        releaseKey right
        pressKey left
    }
    else if ($snap_mode == 2) {
        releaseKey left
        pressKey right
    }
}
else if ($snap_state == 1) {
    if ($snap_mode == 0) {
        releaseKey left
        releaseKey right
    }
    else if ($snap_mode == 2) {
        releaseKey left
        pressKey right
    }
}
else if ($snap_state == 2) {
    if ($snap_mode == 0) {
        releaseKey right
        releaseKey left
    }
    else if ($snap_mode == 1) {
        releaseKey right
        pressKey left
    }
}
setVar snap_state $snap_mode
if ($snap_mode != 0) goTo loop
ifNotPlaytime 5000 goTo loop
setVar snap_running 0
setLedTxt 1 '<->'
5 Likes