esamattis / deno_karabiner

Write Complex Modifications for Karabiner-Elements using Typescript and Deno.
https://deno.land/x/karabiner
MIT License
18 stars 3 forks source link

Equivalent of simlayer from Goku #2

Open mariodavid opened 3 years ago

mariodavid commented 3 years ago

Hi,

I just found your library and it looks quite good. Especially because I find it hard to get my head around the DSL from Goku and wanted to give your idea a try.

What I'm searching for is the equivalent of a simlayer from goku (see: https://github.com/yqrashawn/GokuRakuJoudo/blob/master/tutorial.md#advance3).

What I would like to do is to have a layer that is activating on "holding down f".

What I did until now is this:

import {
    HyperKey,
    KarabinerComplexModifications,
} from "https://deno.land/x/karabiner@v0.2.1/karabiner.ts";

const f_mode = new HyperKey({
    id: "f_mode",
    description: "F Mode",
    from: {
        key_code: "f"
    }
});

f_mode.bindKey({symbol: "j", description: "j", key: "j", to: [{key_code: "left_arrow"}]});
f_mode.bindKey({symbol: "k", description: "k", key: "k", to: [{key_code: "down_arrow"}]});
f_mode.bindKey({symbol: "i", description: "i", key: "i", to: [{key_code: "up_arrow"}]});
f_mode.bindKey({symbol: "l", description: "l", key: "l", to: [{key_code: "right_arrow"}]});

const mods = new KarabinerComplexModifications();

mods.addRule(f_mode.getRules());
mods.writeToProfile("Deno");

When I hold down f it works (using jkil for navigation), but when I only tab f it does not print the regular f character.

Would you be able to take a look and help me out?

Cheers Mario

esamattis commented 3 years ago

You can do it with to_if_alone, to_if_held_down and halt but unfortunately the HyperKey abstraction does not support this (for now at least). But you can certainly do it with custom mods.addRule() calls.

I did something like this for mute:

https://github.com/esamattis/deno_karabiner/blob/b30984f6daf803277c0444d760c68ba12b2e9c6c/example.ts#L710-L742