Skip to content
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

How to disable first key in combination conditionally #1070

Open
jodhsinghnahal opened this issue Feb 27, 2025 · 1 comment
Open

How to disable first key in combination conditionally #1070

jodhsinghnahal opened this issue Feb 27, 2025 · 1 comment

Comments

@jodhsinghnahal
Copy link

jodhsinghnahal commented Feb 27, 2025

When I type jk this will also type j then esc.

 {
        "input_combination": [

            {
                "type": 1,
                "code": 36,
                "origin_hash": "d5d191ac440b53de83839d8e9d2bcb5f"
            },

            {
                "type": 1,
                "code": 37,
                "origin_hash": "d5d191ac440b53de83839d8e9d2bcb5f"
            }

        ],
        "target_uinput": "keyboard",
        "output_symbol": "KEY_ESC",
        "mapping_type": "key_macro"

    }

I also tried this but if I have text in firefox search bar with autocomplete it will still write the j.

{
        "input_combination": [

            {
                "type": 1,
                "code": 36
            }

        ],
        "target_uinput": "keyboard",
        "output_symbol": "set(foo, 1).hold_keys(j).set(foo, 0)",
        "mapping_type": "key_macro",
        "macro_key_sleep_ms": 1
    },

    {
        "input_combination": [

            {
                "type": 1,
                "code": 37
            }

        ],

        "target_uinput": "keyboard",
        "output_symbol": "if_eq($foo, 1, key(KEY_ESC).key(KEY_BACKSPACE), hold_keys(k))",
        "mapping_type": "key_macro",
        "macro_key_sleep_ms": 1
    }
@sezanzeb
Copy link
Owner

So you want to have a functioning "j" key, but if combined with "k" inject "esc" but not the "j"?

Turns out there is a solution, but it seems to exploit a race condition or something:

map j to:

set(j, 1)	
.if_single(
    hold_keys(j),
    wait(1).if_eq($j, 1, key(j)),
    200
)
.set(j, 0)

map k to:

if_eq(
    $j,
    1,
    set(j, 0).hold_keys(Escape),
    hold_keys(k)
)

By doing wait(1) it gives the second macro time to set j to 0. And as it turns out, wait(1) is still faster than other unrelated keys for some reason. So other keys that you press appear after j. Even wait(10) seems to be fine. Couldn't figure out what causes that lag, but it makes this possible.

@sezanzeb sezanzeb changed the title How to remap chord (jk to escape) How to disable first key in combination conditionally Feb 28, 2025
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

2 participants