Code Monkey home page Code Monkey logo

Comments (8)

evan-liu avatar evan-liu commented on September 27, 2024

Hi @garlandcrow , thanks for trying out the project. Can you try if this works for your need?

rule('delay layer').manipulators([

  map(1)
    .toDelayedAction(toSetVar('delay-layer-1'), [
      toKey(1),
      toSetVar('delay-layer-1', 0),
    ])
    .toAfterKeyUp(toSetVar('delay-layer-1', 0))
    .toIfAlone(toKey(1))
    .parameters({ 'basic.to_delayed_action_delay_milliseconds': 200 }),
  
  withCondition(ifVar('delay-layer-1'))({
    2: toKey(3), //
  }),

])

If it does, or you made it work with some modifications, please let me know and I will make a delayedLayer() method. Or create a PR if you'd like to :)

from karabiner.ts.

evan-liu avatar evan-liu commented on September 27, 2024

Sorry @garlandcrow , I've tried it myself but couldn't find a workable solution. The problem is that to_delayed_action is sent even if the key has been released, which causes 2 problems:

  1. If the key is released before the delay time, the variable is set to 1 and stay at 1 (as to_delayed_action.to_if_invoked is sent after key up)
  2. If the key is released fast, then another key is pressed before the delay, to_delayed_action.to_if_canceled is sent so the key is sent twice (the first one by to_if_alone).

The best I got is to use 2 variables to solve the first problem but no solution for the second problem (type 1, release, then 2 will send 112 instead of 12)

  rule('delay layer').manipulators([
    map(1)
      .toIfAlone(1)
      .to(toSetVar('delay-layer-1-down'))
      .toDelayedAction(toSetVar('delay-layer-1-delay'), [
        toKey(1),
        toSetVar('delay-layer-1-delay', 0),
      ])
      .toAfterKeyUp([
        toSetVar('delay-layer-1-down', 0),
        toSetVar('delay-layer-1-delay', 0),
      ])
      .parameters({
        'basic.to_delayed_action_delay_milliseconds': 200,
      }),

    withCondition(
      ifVar('delay-layer-1-down'),
      ifVar('delay-layer-1-delay'),
    )({
      2: toKey(3),
    }),
  ]),

Please let me know if you find a solution as I would love to use this layer to replace simlayer too.

from karabiner.ts.

garlandcrow avatar garlandcrow commented on September 27, 2024

Thanks for trying this! I had tried something similar to your first one, but not as nice and had those problems where the var was sticking so I stopped and was going to read more about all the things karabiner has and give another go. I'll definitely let you know if I get something working as this is the last barrier to me having a super usable MacBook.

from karabiner.ts.

evan-liu avatar evan-liu commented on September 27, 2024

Will tap-press good enough for you? Like a double tap but the second tap need to hold to keep the layer active.

Update: Sorry I tried but couldn't make it work either. What I was thinking (but doesn't work):

  rule('delay layer').manipulators([
    map(1)
      .condition(ifVar('11-delay').unless())
      .toVar('11-delay')
      .toDelayedAction(
        [toSetVar('11-delay', 0), toKey(1)],
        [toSetVar('11-delay', 0)],
      )
      .parameters({
        'basic.to_delayed_action_delay_milliseconds': 200,
      }),

    map(1)
      .condition(ifVar('11-delay'))
      .toVar('11-layer')
      .toAfterKeyUp(toSetVar('11-layer', 0))
      .toIfAlone(1)
      .parameters({
        'basic.to_if_alone_timeout_milliseconds': 200,
      }),

    withCondition(ifVar('11-layer'))({
      2: toKey(3), 
    }),
  ]),

from karabiner.ts.

evan-liu avatar evan-liu commented on September 27, 2024

Hi @garlandcrow , I'm not sure if it would still be useful for you, but I think I figured it out. If you would like to give it a try:

rule('delayedLayer').manipulators([
  map(1)
    .condition(ifVar('delayed-1').unless())
    .toIfHeldDown([
      toSetVar('delayed-1'),
      toNotificationMessage('delayed-1', 'πŸ’‘ Delayed Layer 1'),
    ])
    .toAfterKeyUp([
      toSetVar('delayed-1', 0),
      toRemoveNotificationMessage('delayed-1'),
    ])
    .toIfAlone(1)
    .toDelayedAction(
      [],
      [
        toKey(1),
        toSetVar('delayed-1', 0),
        toRemoveNotificationMessage('delayed-1'),
      ],
    )
    .parameters({
      'basic.to_if_held_down_threshold_milliseconds': 200,
      'basic.to_delayed_action_delay_milliseconds': 200,
    }),

  withCondition(ifVar('delayed-1'))({
    2: toKey(3),
  }),
]),

from karabiner.ts.

garlandcrow avatar garlandcrow commented on September 27, 2024

Oh just saw this! Ya let me try tonight, that would be amazing to have 🀞

from karabiner.ts.

garlandcrow avatar garlandcrow commented on September 27, 2024

Yea think you nailed it, seems to work perfect so far and IMO is exactly how you would want this to work, especially for fast typers. I'm changing over all my karabiner layers to be implemented this way, will post something if have any issues in everyday use. Well done!!

from karabiner.ts.

evan-liu avatar evan-liu commented on September 27, 2024

Sorry, but I found some issues when I tried it more. Sometimes, the key gets triggered twice when typed fast with other keys. I guess it is a typing habit; maybe you can find proper parameters that avoid that with your typing speed. Maybe try more after changing each key.

from karabiner.ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.