pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.72k stars 836 forks source link

from with caps_lock and left_shift appears to not work ? #2997

Closed magnayn closed 2 years ago

magnayn commented 2 years ago

I'm trying to build a layer that uses shift+capslock as the keys to hold down to enable, but I'm having problems.

I try to put the config in the JSON, with:

"manipulators" : [ {
          "type" : "basic",
          "to" : [ {
            "set_variable" : {
              "name" : "hyper-mode",
              "value" : 1
            }
          } ],
          "from" : {
            "key_code" : "caps_lock",
            "modifiers": {
                                        "mandatory": [
                                            "left_shift"
                                        ]
                                    }
          },
          "to_after_key_up" : [ {
            "set_variable" : {
              "name" : "hyper-mode",
              "value" : 0
            }
          } ],

But it doesn't seem to work. The rule without the shift requirement does. Bug or error on my part?

MuhammedZakir commented 2 years ago

The rule looks okay. There isn't any syntax error, right? Check Log tab in Karabiner-Elemenets for errors. Another reason could be that some other config is interfering. Try this config in a new profile.

What version of KE and macOS are you using?

magnayn commented 2 years ago

KE 14.3.0 on Monterey (12.2, M1 Air)

So with the following config, caps_lock and 'x' yields 'mmz' as expected, left_shift+caps_lock and 'x' only yields 'MM', but no Z.

So it looks like the first part is firing (hence the 'm's) but the second doesn't if the optional shift is present..

{
    "global": {
        "check_for_updates_on_startup": true,
        "show_in_menu_bar": true,
        "show_profile_name_in_menu_bar": false
    },
    "profiles": [
        {
            "complex_modifications": {
                "parameters": {
                    "basic.simultaneous_threshold_milliseconds": 50,
                    "basic.to_delayed_action_delay_milliseconds": 500,
                    "basic.to_if_alone_timeout_milliseconds": 1000,
                    "basic.to_if_held_down_threshold_milliseconds": 500,
                    "mouse_motion_to_scroll.speed": 100
                },
                "rules": [
                    {
                        "description": "Auto generated layer conditions",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "caps_lock",
                                    "modifiers": {
                                        "optional": [
                                            "left_shift"
                                        ]
                                    }
                                },
                                "to": [
                                    { 
                                        "key_code": "m"
                                    },
                                    {
                                        "key_code": "m"
                                    },
                                    {
                                        "set_variable": {
                                            "name": "hyper-mode",
                                            "value": 1
                                        }
                                    }
                                ],
                                "to_after_key_up": [
                                    {
                                        "set_variable": {
                                            "name": "hyper-mode",
                                            "value": 0
                                        }
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "key_code": "escape"
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "a to 1",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "name": "hyper-mode",
                                        "type": "variable_if",
                                        "value": 1
                                    }
                                ],
                                "from": {
                                    "key_code": "x"
                                },
                                "to": [
                                    {
                                        "key_code": "z"
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            },
            "devices": [
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "fn_function_keys": [],
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 641,
                        "vendor_id": 1452
                    },
                    "ignore": false,
                    "manipulate_caps_lock_led": true,
                    "simple_modifications": []
                },
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "fn_function_keys": [],
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 17,
                        "vendor_id": 1130
                    },
                    "ignore": false,
                    "manipulate_caps_lock_led": true,
                    "simple_modifications": []
                }
            ],
            "fn_function_keys": [
                {
                    "from": {
                        "key_code": "f1"
                    },
                    "to": [
                        {
                            "consumer_key_code": "display_brightness_decrement"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f2"
                    },
                    "to": [
                        {
                            "consumer_key_code": "display_brightness_increment"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f3"
                    },
                    "to": [
                        {
                            "apple_vendor_keyboard_key_code": "mission_control"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f4"
                    },
                    "to": [
                        {
                            "apple_vendor_keyboard_key_code": "spotlight"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f5"
                    },
                    "to": [
                        {
                            "consumer_key_code": "dictation"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f6"
                    },
                    "to": [
                        {
                            "key_code": "f6"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f7"
                    },
                    "to": [
                        {
                            "consumer_key_code": "rewind"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f8"
                    },
                    "to": [
                        {
                            "consumer_key_code": "play_or_pause"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f9"
                    },
                    "to": [
                        {
                            "consumer_key_code": "fast_forward"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f10"
                    },
                    "to": [
                        {
                            "consumer_key_code": "mute"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f11"
                    },
                    "to": [
                        {
                            "consumer_key_code": "volume_decrement"
                        }
                    ]
                },
                {
                    "from": {
                        "key_code": "f12"
                    },
                    "to": [
                        {
                            "consumer_key_code": "volume_increment"
                        }
                    ]
                }
            ],
            "name": "Default",
            "parameters": {
                "delay_milliseconds_before_open_device": 1000
            },
            "selected": true,
            "simple_modifications": [],
            "virtual_hid_keyboard": {
                "country_code": 0,
                "indicate_sticky_modifier_keys_state": true,
                "mouse_key_xy_scale": 100
            }
        }
    ]
}
MuhammedZakir commented 2 years ago

What is the output of EventViewer for caps_lock+left_shift+x? ~Does it detect all three keypresses?~

Edit: You probably need to add left_shift to from.modifiers in second rule for it to fire when left_shift is pressed. You probably don't need caps_lock, but adding it is better imho (unless you use that combination for some other rule). I usually add caps_lock to all my "general" rules to prevent rules from not working when caps lock is on.

magnayn commented 2 years ago

Ah - yes - that worked - I can make the 1st part have a mandatory for left_shift, and the rule itself optional for left_shift, and it passes through correctly.

Thankyou! I was spending ages trying to grok what was happening initially through the lens of goku, which wasn't helping at all :)