Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Karabiner Elements, how can I toggle the WASD keys to arrow keys. Only while Caps lock active?

Love this program and thankful for any help

Like the title states, I have my left hand on my SHIFT KEY, OPTION KEY and COMMAND key all the time. but I hate when I have to use my arrow keys to move shapes. I would like the ability to change WASD as arrow keys to nudge shapes around. This also allows for the pinky to hit the left SHIFT KEY so that I could move shape 10px at a time. However, I want to be able to toggle to the arrow function by pressing Caps lock and holding it until I release. Doing this will enable me to make more use of hotkeys while building/UI.

To summarize:

  1. Program active
  2. keyboard is in default state when Caps lock is off
  3. While Caps lock is on I am able to use WASD as arrow keys
  4. Once I hit Caps lock, keys will return to default state.

Thank you so much for whatever help you guys can throw my way. Hope this has already been addressed and is easy fix

like image 622
epecho Avatar asked Feb 21 '18 04:02

epecho


People also ask

Is there a way to use WASD keys with Karabiner?

This is a modification of the script "TouchCursor Mode" from the Karabiner site, which toggles a variable when pressing capslock, then uses WASD as keys or arrows depending on that variable. Similar technique to the one used by @user9680958. Show activity on this post. 1. Setup Karabiner: Have fun. Show activity on this post.

Is there a way to toggle Caps Lock with WASD keys?

Note that this script replaces the functionality of caps lock, meaning: it works as an arrow key toggler, not as an uppercase key toggler. This is a modification of the script "TouchCursor Mode" from the Karabiner site, which toggles a variable when pressing capslock, then uses WASD as keys or arrows depending on that variable.

How to modify MAC function keys using Karabiner elements?

Check out the steps below to use modify Mac function keys using Karabiner Elements: Select the Function Keys tab in the Karabiner-Elements Preferences window. Tap on the dropdown button beside Target device to select the target device on which you want these changes to function.

Do you use Karabiner before or after El Cap?

But it is still not that compelling comparing with the karabiner before El Cap which provides tons of customizations inside the app. Thus I want to share a tool that I’m using for sometime, there is one tool that I’m using that can extend lots of functionalities based on the hyper keys using KM.


2 Answers

This works for me:

{
    "description": "WASD arrow Keys toggled by Capslock",
    "manipulators": [
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_unless",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "caps_lock",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "wasd_arrow_keys_mode",
                        "value": 1
                    }
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "caps_lock",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "wasd_arrow_keys_mode",
                        "value":  0
                    }
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "a",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "left_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "s",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "down_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "w",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "up_arrow"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "name": "wasd_arrow_keys_mode",
                    "type": "variable_if",
                    "value": 1
                }
            ],
            "from": {
                "key_code": "d",
                "modifiers": {
                    "optional": [
                        "any"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "right_arrow"
                }
            ],
            "type": "basic"
        }
    ]
}

You can either place the code inside the brackets of the "rules": [] element of the file ~/.config/karabiner/karabiner.json, or create a new JSON file in ~/.config/karabiner/assets/complex_modifications, wrapping the code above in:

{
  "title": "WASD arrow Keys toggled by Capslock",
  "rules": [
    (insert code here)
  ]
}

If you opt for the separate JSON file, once saved you can enable it through the Karabiner-Elements UI via Complex Modifications > Add rule.

I‘m using Karabiner beta 12.1.56 but it should work on Karabiner stable.

Note that this script replaces the functionality of caps lock, meaning: it works as an arrow key toggler, not as an uppercase key toggler.

This is a modification of the script "TouchCursor Mode" from the Karabiner site, which toggles a variable when pressing capslock, then uses WASD as keys or arrows depending on that variable. Similar technique to the one used by @user9680958.

like image 199
Jano Avatar answered Oct 06 '22 03:10

Jano


Both solutions for caps lock mode and caps hold mode:

  • p.s. you can easily switch the script down below to "wasd" or "hjkl", etc.

1. Setup Karabiner:

  • Download Karabiner
  • When opening it requires to enable some stuff in the Settings (just follow the steps it requests from you)

Set up the Script:

  1. Create a JSON file on your desktop:

    • cmd + space to open the spotlight
    • type in terminal
    • type in cd
    • type in cd desktop
    • touch myscript.json
    • copy paste one of the codes down below in the new file
  2. Go back to the terminal

    • Type in cd
    • Type cd desktop
    • Type mv myscript.json ~/.config/karabiner/assets/complex_modifications
  3. Now open Karabiner Elements and go to "Complex modifications"

    • Press "add Rule"
    • Now there should be your custom rule to enable
    • Have fun.

Code 1 for Caps lock "to enter arrow key mode" and press again "to exit arrow key mode":

{
  "title": "ijkl arrow Keys toggled by Capslock",
  "rules": [
    {
        "description": "ijkl arrow Keys toggled by Capslock",
        "manipulators": [
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_unless",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "caps_lock",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "set_variable": {
                            "name": "wasd_arrow_keys_mode",
                            "value": 1
                        }
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "caps_lock",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "set_variable": {
                            "name": "wasd_arrow_keys_mode",
                            "value":  0
                        }
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "j",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "left_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "k",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "down_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "i",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "up_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "l",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "right_arrow"
                    }
                ],
                "type": "basic"
            }
        ]
    }
  ]
}

Code 2 If you want to hold Caps while using the arrow Keys use this one instead:

{
  "title": "ijkl arrow Keys toggled by Capslock",
  "rules": [
    {
        "description": "ijkl arrow Keys toggled by Capslock",
        "manipulators": [
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_unless",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "caps_lock",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "set_variable": {
                            "name": "wasd_arrow_keys_mode",
                            "value": 1
                        }
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "caps_lock",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "set_variable": {
                            "name": "wasd_arrow_keys_mode",
                            "value":  0
                        }
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "j",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "left_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "k",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "down_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "i",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "up_arrow"
                    }
                ],
                "type": "basic"
            },
            {
                "conditions": [
                    {
                        "name": "wasd_arrow_keys_mode",
                        "type": "variable_if",
                        "value": 1
                    }
                ],
                "from": {
                    "key_code": "l",
                    "modifiers": {
                        "optional": [
                            "any"
                        ]
                    }
                },
                "to": [
                    {
                        "key_code": "right_arrow"
                    }
                ],
                "type": "basic"
            }
        ]
    }
  ]
}
like image 40
RePuLseHQ King Avatar answered Oct 06 '22 05:10

RePuLseHQ King