pqrs-org / Karabiner-archived

Karabiner (KeyRemap4MacBook) is a powerful utility for keyboard customization.
https://pqrs.org/osx/karabiner/
The Unlicense
3.82k stars 309 forks source link

Non-global Delay Threshold of Key #762

Open braham-snyder opened 8 years ago

braham-snyder commented 8 years ago

Firstly, thanks a ton for this indispensable application.

I'm a huge fan of key-chords like those given by __SimultaneousKeyPresses__. My only qualm using it is its (near-)global delay threshold. KEYTOKEY_DELAYED_ACTION avoids this global delay, but seems to require fairly messy things for otherwise similar behavior (some of which is noted in the samples):

<item>
    <name>simul return and escape</name>
    <identifier>simul return and escape</identifier>

    {{ CAPS_OR_NO_MODS }}

    <modifierdef>RET</modifierdef>

    <block>
      <!-- allows repeatable delayed action -->
      <modifierstuck_only>ModifierFlag::RET</modifierstuck_only>

      <autogen>
        __KeyToKey__
        KeyCode::K,
        KeyCode::RETURN,

        Option::KEYTOKEY_AFTER_KEYUP,
        KeyCode::VK_STICKY_RET_FORCE_OFF

      </autogen>

      <autogen>
        __KeyToKey__
        KeyCode::L,
        KeyCode::RETURN,

        Option::KEYTOKEY_AFTER_KEYUP,
        KeyCode::VK_STICKY_RET_FORCE_OFF

      </autogen>

    </block>

    <autogen>
      __HoldingKeyToKey__
      <!-- Holding threshold set to 0ms to retain repeat -->
      KeyCode::L,

      <!-- ======================================== -->
      <!-- normal press -->
      @begin
      KeyCode::VK_NONE,

      <!-- Delay threshold set to 10ms or less for virtually instant delayed
           actions -->
      Option::KEYTOKEY_DELAYED_ACTION,
      KeyCode::L,

      Option::KEYTOKEY_DELAYED_ACTION_CANCELED_BY, KeyCode::K,
      KeyCode::VK_STICKY_RET_FORCE_ON
      @end

      <!-- ======================================== -->
      <!-- holding -->
      @begin
      KeyCode::L,
      @end
    </autogen>

    <autogen>
      __HoldingKeyToKey__
      KeyCode::J,

      <!-- ======================================== -->
      <!-- normal press -->
      @begin
      KeyCode::VK_NONE,

      Option::KEYTOKEY_DELAYED_ACTION,
      KeyCode::J,

      Option::KEYTOKEY_DELAYED_ACTION_CANCELED_BY, KeyCode::K,
      KeyCode::ESCAPE,
      KeyCode::VK_KEYTOKEY_DELAYED_ACTION_DROP_EVENT,
      @end

      <!-- ======================================== -->
      <!-- holding -->
      @begin
      KeyCode::J,
      @end
    </autogen>

    <autogen>
      __HoldingKeyToKey__
      KeyCode::K,

      <!-- ======================================== -->
      <!-- normal press -->
      @begin
      KeyCode::VK_NONE,

      Option::KEYTOKEY_DELAYED_ACTION,
      KeyCode::K,

      Option::KEYTOKEY_DELAYED_ACTION_CANCELED_BY, KeyCode::J,
      KeyCode::ESCAPE,
      KeyCode::VK_KEYTOKEY_DELAYED_ACTION_DROP_EVENT,

      Option::KEYTOKEY_DELAYED_ACTION_CANCELED_BY, KeyCode::L,
      KeyCode::VK_STICKY_RET_FORCE_ON
      @end

      <!-- ======================================== -->
      <!-- holding -->
      @begin
      KeyCode::K,
      @end
    </autogen>
  </item>

Additionally--unlike __SimultaneousKeyPresses__--this configuration precludes the (admittedly niche) ability to repeat the resulting key (e.g., control) with only one of the original keys still held down (e.g., holding only O after pressing I + O) . (You can't recover the first, canceled key even with VK_PARTIAL_KEYUP, correct?)

I think I can use replacementdefs to clean this up a bit, but it still seems messy. Any chance __SimultaneousKeyPresses__'s delay could be limited to the relevant keys? Or is there a better way to achieve this sort of thing?