De-bounce butterfly keyboard double keypress with Karabiner-Elements

Posted

Grrr, to no one’s surprise, my MacBook Pro with butterfly keyboard is experiencing keyboard issues. In my case, a keypress on “j” is often triggered twice, resulting in “jj”. And with the lockdowns, I don’t want to risk a repair! So, here is a quick workaround using Karabiner-Elements v12.9.0.

Credit to “clemsam lang” and very smart people replying to this post on Stack Exchange. Though my version is slightly different...

In a previous post, I describe using a Karabiner-Elements’ custom Complex Modification to map my physical ~ key to Escape. So, only had to add another Complex Modification rule to “de-bounce” my stuck key:

  1. Open up Karabiner-Elements Preferences, under the Misc tab, hit Open config folder (~/.config/karabiner).
  2. Using a text editor of your choice (I use Visual Studio Code), edit the file karabiner.json.
  3. Add a new rule under complex_modifications:
    {
    …
    "profiles": [
    {
      "complex_modifications": {
        …
        "rules": [
          {
            "description": "De-bounce j",
            "manipulators": [
              {
                "from": { "key_code": "j" },
                "parameters": { "basic.to_if_held_down_threshold_milliseconds": 30 },
                "to_if_held_down": [ { "key_code": "j", "repeat": true } ],
                "type": "basic"
              }
            ]
          }
        ]
        …
      }
    }
    ]
    …
    }
  4. Save, and Karabiner-Elements will reload the configuration. Do check the Log for any errors...

I’ve not shown the entire karabiner.json file - ellipsis () indicates line I’ve removed for clarity. Also, if you already have existing rules, remember to place a comma between them, e.g. "rules": [ { … }, { … } ]

If you are facing similar issues on a different key, simply change the key_code above. Note that the key will lose long press accented / alternate characters. You know the popup like below. Fortunately, this doesn’t apply to the j key anyway, and in any case, I don’t use accented characters.

macOS Accent Character Selection Popup

Compared to the Stack Exchange post, I enabled repeat, but if that doesn’t work for you, set it to false - you will loose repeat keys in Apps that don’t support accented characters (like Terminal). However, I do face a tiny quirk - after holding the key down for a while, when I release the key, I get the one more character added. I don’t encounter this scenario enough for it to bother me.

Finally, I don’t know if the Complex Modification will impact games, or behaviour of other Apps. Good luck.