7

I have this problem (again) - pressing one key (b for me) sometimes makes it to be registered twice. https://discussions.apple.com/thread/7840547

Is there a way to use karabiner-elements to modify such that when a key is pressed twice within a short time the second key will not be registered? https://pqrs.org/osx/karabiner/complex_modifications/

bmike
  • 235,889
HK Tong
  • 95

2 Answers2

10

For your special case I would suggest you use Karabiner Elements. and edit its ~/.config/karabiner/karabiner.json this way (added to/after "rules"):

EDIT / fail-safe version:
– Copy/paste the code below into TextEdit and "Save as..." WhateverNameYouLike.json
– Next manually move a copy to ~/.config/karabiner/assets/complex_modifications/
– Finally import from KE: tab "Complex Modifications", buttons [+ Add rule] & [+ Enable]

{ "title": "Keep solitary letter/key ''b'' from multiple press!",
  "rules": [
     { "description": "Keep 'b' from being pressed twice",
       "manipulators": [
        { "from": { "key_code": "b" },
          "parameters": {"basic.to_if_held_down_threshold_milliseconds": 10},
          "to_if_held_down":[
                 { "key_code": "b",
                   "repeat": false }],
          "type": "basic"
                }  
            ]
        }
    ]    
}

As you can see letter "b" is NOT re-mapped but in "to_if_held_down" kept from being repeated by "repeat": false; obviously letter 'b' may be substituted with any other failing letter.
(The threshold is defined to a minimal 1/100 second, so you won't notice any difference ...)

Please report if this code does for you what it's supposed to do.
[EDIT:] This solution works for the user in (ex-) trouble.
(I had to simulate the situation by testing in an app that does repeat keys if held down – but actually yours may be a non-solvable mechanical problem …)

Note:
This method, though, may not be advisable/applicable, if the holding-down of a key (e.g.: "a") in an app opens a small window above it offering (e.g.:) "ä" / "å" / "ậ" or similar choices – IF you need those special characters.
This behaviour would be prevented by "repeat": false.
But then:
You can activate "Show Keyboard & Character Viewers in menu bar" in System Preferences and get them from the menu bar...

clemsam lang
  • 1,132
  • Thanks understanding my question, and validating that my question is valid. However my problem is not solved, nothing seemed to have changed. This is my karabiner.json currently: https://gist.github.com/tonghuikang/a7d65b98e30f6f37765e696f8e8dd4da – HK Tong Oct 07 '18 at 15:14
  • Hi, I just looked into your json file – and saw that you actually have THREE instances of "Complex Modifications" where ONE is absolutely sufficient. Then, you did not paste the whole "function" above as ONE PIECE. … So. I pasted a version at your gist.github.com/tonghuikang/a7d65b98e30f6f37765e696f8e8dd4da . Try that one! – clemsam lang Oct 07 '18 at 23:48
  • This works, thanks! I changed from "10" to "1", it seems to work more reliably too. – HK Tong Oct 11 '18 at 14:58
1

A Python3 helper script to the above answer, which maps all the keys:

import json
import string
letters = list(string.ascii_lowercase)

for x in letters: output = {'title': f'Double Type {x}', 'rules': [ { 'description': f'Keep {x} from a double keypress', 'manipulators': [ { 'from': {'key_code': f'{x}'}, 'parameters': {"basic.to_if_held_down_threshold_milliseconds": 10}, 'to_if_held_down': [ { 'key_code': f'{x}', 'repeat': 'false' } ], 'type': 'basic' }
] } ] } with open(f'doubletype_{x}.json', 'w')as outfile: json.dump(output, outfile)

Copying files to directory

import glob import shutil from os.path import expanduser

home = expanduser("~")

print('Copying files...') for file in glob.glob('doubletype_*'): shutil.copyfile(file, f'{home}/.config/karabiner/assets/complex_modifications/{file}') print('Copying files complete!')

This will generate 26 files (one for each letter), and copy them to the appropriate directory.

Joe
  • 111