Karabiner-elements: 搂 and ` swapped on UK external keyboard

Created on 29 Nov 2016  路  19Comments  路  Source: pqrs-org/Karabiner-Elements

On an official Apple UK keyboard the 搂 (located to the left of 1) and ` (left of z) keys are swapped. The UK internal keyboard (2015 Macbook Pro) works as expected. The details of the devices follows:

screen shot 2016-11-29 at 10 11 31

I currently work around this by mapping _non_us_backslash_ and _grave_access_and_tilde_ to each other via the a Karabiner Simple Modification, but this obviously results in the keys being mapped incorrectly when I am not using an external keyboard.

Edit: Just in case I was not clear on this point, if I quit Karabiner-Elements the ` and 搂 keys both work as expected on internal and external keyboards.

stale

Most helpful comment

I would actually really like to see a way to assign different profiles to different devices

All 19 comments

the old solution was to make multiple profiles for when you are using the internal or external keyboard, and you could switch them easily, I wonder if there is a easy way to select profiles in karabiner-elements though

I would actually really like to see a way to assign different profiles to different devices

+1 to this - I have to have two files named karabiner_internal.json and karabiner_external.json and then overwrite the contents of karabiner.json manually every time I plug in my external keyboard, because of this bug. It would be a nice workaround to be able associate specific devices to specific json files on the devices tab.

@mkborregaard I have considered using USB events via Hammerspoon to do _something_ like your solution. Can you share how you listen to USB events in order to copy the correct JSON into place please?

I do it manually :-(

I do it manually as well, somebody does that with https://www.alfredapp.com/ (https://github.com/tekezo/Karabiner-Elements/issues/478)

It shouldn't be necessary though, as Karabiner-elements already listens for and detects the external keyboard.

+1 on this issue.

@surbitron9000 Try something like this:

local mod  = {}
local kb_ID = "Apple Keyboard"
local confPath = "/Users/<username>/.karabiner.d/configuration/karabiner.json"

local function usbChangedCb( usbEvt )
    if usbEvt.productName == kb_ID then
        if usbEvt.eventType == "added" then
            print( "External keyboard connected" )
            os.remove( confPath )
            hs.fs.link( confPath .. ".kb_ext", confPath )
        elseif usbEvt.eventType == "removed" then
            print( "External keyboard removed" )
            os.remove( confPath )
            hs.fs.link( confPath .. ".kb_int", confPath )
        end

    end
end

function mod.init()
    usbWatcher = hs.usb.watcher.new( usbChangedCb )
    usbWatcher:start()
end

return mod

Save it in your ~/.hammerspoon folder and import and initialize it in your init.lua
As you can see it uses os.remove, so make sure you have a backup of your json file.

@swummoq this could work but if you remove/add the external keyboard while the mac is
sleeping you will still need to do it manually

@lrusnac True, but i never do that. But it would be easy to add a hotkey in HS.

@swummoq Many thanks for the code. Much appreciated.

@swummoq Thank you a lot!

2all russian-speaking people: if you have the same issue when using capslock as language switcher try this modifications for external keyboard (pay attention for simple_modifications blocks):

{
    "profiles": [
        {
            "devices": [
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 592,
                        "vendor_id": 1452
                    },
                    "ignore": false,
                    "keyboard_type": 0
                },
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 628,
                        "vendor_id": 1452
                    },
                    "ignore": false,
                    "keyboard_type": 0
                }
            ],
            "fn_function_keys": {
                "f1": "vk_consumer_brightness_down",
                "f10": "mute",
                "f11": "volume_down",
                "f12": "volume_up",
                "f2": "vk_consumer_brightness_up",
                "f3": "vk_mission_control",
                "f4": "vk_launchpad",
                "f5": "vk_consumer_illumination_down",
                "f6": "vk_consumer_illumination_up",
                "f7": "vk_consumer_previous",
                "f8": "vk_consumer_play",
                "f9": "vk_consumer_next"
            },
            "name": "Default profile",
            "selected": true,
            "simple_modifications": {
                "caps_lock": "f19",
                "grave_accent_and_tilde": "non_us_backslash",
                "non_us_backslash": "grave_accent_and_tilde"
            }
        }
    ]
}

This for internal:

{
    "profiles": [
        {
            "devices": [
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 592,
                        "vendor_id": 1452
                    },
                    "ignore": false,
                    "keyboard_type": 0
                },
                {
                    "disable_built_in_keyboard_if_exists": false,
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": false,
                        "product_id": 628,
                        "vendor_id": 1452
                    },
                    "ignore": false,
                    "keyboard_type": 0
                }
            ],
            "fn_function_keys": {
                "f1": "vk_consumer_brightness_down",
                "f10": "mute",
                "f11": "volume_down",
                "f12": "volume_up",
                "f2": "vk_consumer_brightness_up",
                "f3": "vk_mission_control",
                "f4": "vk_launchpad",
                "f5": "vk_consumer_illumination_down",
                "f6": "vk_consumer_illumination_up",
                "f7": "vk_consumer_previous",
                "f8": "vk_consumer_play",
                "f9": "vk_consumer_next"
            },
            "name": "Default profile",
            "selected": true,
            "simple_modifications": {
                "caps_lock": "f19"
            }
        }
    ]
}

And this config for hammerspoon:

local usbWatcher = nil
local deviceName = "Apple Keyboard"
local confPath = "/Users/<username>/.karabiner.d/configuration/karabiner.json"

function usbDeviceCallback(data)
    if (data["productName"] == deviceName) then
        if (data["eventType"] == "added") then
            print( "External keyboard connected" )
            os.remove( confPath )
            hs.fs.link( confPath .. ".kb_ext", confPath )
        elseif (data["eventType"] == "removed") then
            print( "External keyboard removed" )
            os.remove( confPath )
            hs.fs.link( confPath .. ".kb_int", confPath )
        end
    end
end

usbWatcher = hs.usb.watcher.new(usbDeviceCallback)
usbWatcher:start()

Don't forget reload config and switch on console to be sure that everything is working perfectly. Anyway with this configuration you still will have same keys mismatch issue with internal keyboard at the moment when external keyboard is plugged-in. But it's better then nothing.

I would like to the same. I don't fully understand @swummoq's solution. Isn't there an easier way by now?

When I am mapping non_us_backslash and grave_access_and_tilde to each other, as in:

{
    "non_us_backslash": "grave_accent_and_tilde",
    "grave_accent_and_tilde": "non_us_backslash"
}

what happens is that I get back to square one. It seems to be that 搂 is swapped ` and then back to 搂 again. It used to work fine in the past, not sure what's up.

I am not too sad about it since I don't really use 搂 and now I have two tilde/backtick keys, but it's strange.

In the past I used to switch between different keyboard which have different layouts. Before KE had the ability to switch profiles, I made a CLI tool to switch between the profile on the fly:
https://github.com/nomaed/karabiner-profile-switch
Might be useful for someone.

Same problem, I have to add this config just to get my UK keyboard back to 'normal'

config image

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Is this a dup of #1032 ?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings