Skip to content

Home row mods: Rolled modifiers cancellation #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hochshi opened this issue Dec 19, 2022 · 0 comments
Open

Home row mods: Rolled modifiers cancellation #27

hochshi opened this issue Dec 19, 2022 · 0 comments

Comments

@hochshi
Copy link

hochshi commented Dec 19, 2022

I've extended your code example to easily apply to all combinations of same hand home row mods cancellation.
This applies to my layout but it can be used in any layout following the modifications already present in the post.
I'm not going to post it, so you I though you might be interested in sharing this.

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    // #define MT(mod, kc) (QK_MOD_TAP | (((mod)&0x1F) << 8) | ((kc)&0xFF))
    uint16_t mods;
    switch (keycode) {
        case LCTL_T(KC_R):
        case LALT_T(KC_S):
        case LGUI_T(KC_I):
        case LSFT_T(KC_T):
            /*
            Detect the tap.
            We're only interested in overriding the tap behaviour
            in a certain cicumstance. The hold behaviour can stay the same.
            */
            if (record->event.pressed && record->tap.count > 0) {
                mods = get_mods() & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_LCTL));
                if (mods) {
                    // temporarily disable modifier so we can send the tapped key
                    unregister_mods(mods);
                    if (mods & MOD_BIT(KC_LSFT)) {
                        tap_code(KC_T);
                    }
                    if (mods & MOD_BIT(KC_LGUI)) {
                        tap_code(KC_I);
                    }
                    if (mods & MOD_BIT(KC_LALT)) {
                        tap_code(KC_S);
                    }
                    if (mods & MOD_BIT(KC_LCTL)) {
                        tap_code(KC_R);
                    }
                    tap_code(keycode & 0xFF);
                    add_mods(mods);
                    return false;
                }
            }
            return true;
        case RCTL_T(KC_L):
        case RALT_T(KC_A):
        case RGUI_T(KC_E):
        case RSFT_T(KC_N):
            /*
            Detect the tap.
            We're only interested in overriding the tap behaviour
            in a certain cicumstance. The hold behaviour can stay the same.
            */
            if (record->event.pressed && record->tap.count > 0) {
                mods = get_mods() & (MOD_BIT(KC_RSFT) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_RALT) | MOD_BIT(KC_RCTL));
                if (mods) {
                    // temporarily disable modifier so we can send the tapped key
                    unregister_mods(mods);
                    if (mods & MOD_BIT(KC_RSFT)) {
                        tap_code(KC_N);
                    }
                    if (mods & MOD_BIT(KC_RGUI)) {
                        tap_code(KC_E);
                    }
                    if (mods & MOD_BIT(KC_RALT)) {
                        tap_code(KC_A);
                    }
                    if (mods & MOD_BIT(KC_RCTL)) {
                        tap_code(KC_L);
                    }
                    tap_code(keycode & 0xFF);
                    add_mods(mods);
                    return false;
                }
            }
            return true;
    }
    return true;
}

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant