Is there a simple way to disable a group of keys in complex modifications in Karabiner-Elements?

Consider an example:

Under the following condition

  "set_variable": {
      "name": "con-1",
      "value": 1

I want to disable all alphabets/numbers/simbols (or most of them at least), except for a and b.

Just for reference, this page discusses how to disable individual keys. Applying this approach to many many keys is not efficient.

I appreciate your insight in advance.

1 Answer 1


EDIT: I just added two "[ ]" brackets to the final "to":[{ -part, as their lack got s.o.an [error] !


So, here is a "final version" (some notes to/from a first attempt are appended at bottom):

... some sample code that excludes any typing except letters "a" & "b".
This example is set to only work in TextEdit (for testing purposes) but of course you can change/delete this "conditions" (in last manipulator).

– The "Excluding" is prepared by Shft-Ctrl-A which solely sets "none_but_ab" to true (1).
– Next in line is a Stop-manipulator (security first); it sets "none_but_ab" to "0" after holding "x" 2 sec.
– Both following parts out-put our "a" and "b" letters, excluding them from following annihilation.
– The fatal last manipulator grabs "any: key_code" and renders it to "none" …
– Be careful with your Stop-mechanism: singular keys work best, modified combos may fail!

– Some more ideas:
By adding "command" ("shift") to the last "from", you could prevent app-Cmd-shortcuts (capital letters).
Karabiner El. can start before login (Preferences > 'Copy the current …'); "password" would be affected!
I also would like to know how "Shift" could be applied to "any":"key_code", forcing capital letters, or if numbers can somehow be "selected". Well, let's see …

{ "description": "=============  vk_none but a,b  ============= ",
   "manipulators": [
           "from": { "key_code": "a",
                     "modifiers": {
                         "mandatory": ["left_shift", "left_control"]
                   }              },
             "to": [
                    { "set_variable": {
                      "name": "none_but_ab",
                      "value": 1 }    }
           "type": "basic"
           "from": { "key_code": "x" },
     "parameters": { "basic.to_if_held_down_threshold_milliseconds": 2000 },
"to_if_held_down": [
                    { "key_code": "x" },
                    { "set_variable": {
                      "name": "none_but_ab",
                      "value": 0 }    }
           "type": "basic"
         { "from": { "key_code": "a" },
             "to": [ { "key_code": "a" } ],
           "type": "basic" }, 
         { "from": { "key_code": "b" },
             "to": [ { "key_code": "b" } ],
           "type": "basic" },
     "conditions": [
                    { "name": "none_but_ab",
                      "type": "variable_if",
                      "value": 1 },
                    { "bundle_identifiers": [
                              "^com.apple.TextEdit" ],
                      "type": "frontmost_application_if"
           "from": { "any": "key_code",
                     "modifiers": {
                          "optional": ["any"] }
             "to": [ { "key_code": "vk_none" } ],
           "type": "basic"

(Here are some remains from a first (deleted) answer at this:

note the twisted "any: key_code" part that calls every key, including "modifiers…any"

Interestingly 'from-to' units within{manipulators: …} Karabiner.json are worked through from top to bottom until one is executable.
So if you want particular letters (a, b) to work nonetheless, you must call them previously.

Starting value for any variable is "0" … values will "live" while Karabiner is running!

… while experimenting I made my monitor sleep, but when I typed my pw – one letter simply was not recognised. I had to start from an external drive and change my code. )

  • [I add former comments (to the deleted 2nd "answer"): ] ________________________________ Most importantly - thanks for the great answers. – bmike♦ _______________________________ Oh, you're welcome – and probably right. I'll later on look into what information from my 1st try is worth appending to the newer one; just was so concentrated, I didn't do it right away. Thanks for your reputation points! – clemsam lang Oct 18, 2018 at 6:50
  • 1
    Thanks for your insight. I am trying to create a simple version of vi mode. I want to nullify keys other than those used in Normal Mode, like 'jkhlwbgG0$oOiI'. But your code gives an error '[error] [grabber] complex_modifications json error: to should be array: {"conditions":[{"name":"none_but_ab","type":"variable_if","value":1},{"bundle_identifiers":["^com.apple.TextEdit"],"type":"frontmost_application_if"}],"from":{"any":"key_code","modifiers":{"optional":["any"]}},"to":{"key_code":"vk_none"},"type":"basic"} '. Am I missing something?
    – T_T
    Oct 18, 2018 at 6:58
  • I at first was not quite sure that I understood your question (I had pasted my posted code into karabiner.json and it worked). It seems "[error] …" just expects "[ ]" brackets. These are only needed in "from" when there is more than one {} in your "from": [ {…}, {…}, {…} ] but "to" wants them EVERY time – funny that my code worked nonetheless … but I DID change this above !!! Oct 18, 2018 at 11:22
  • 1
    Thanks for your wonderful code! I used it in my simple Vim mode for KE. You can find it in a file Nullify_keys.json in here if you are interested.
    – T_T
    Oct 19, 2018 at 4:12
  • Hi, I am not sure if what I think is true: I looked into your GitHub code – do you really have to repeatedly call some doublet keys like "b" and "e" ? … If they are "recognised" in your 1st "from…to" the second one won't even be called. I suspect, you might omit these (2nd) doublets. Nice work, your "Vim modes" ! Oct 19, 2018 at 6:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .