Quantcast
Channel: Reliably remapping keys per input device - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Reliably remapping keys per input device

$
0
0

I have a Mac, and the modifier keys on the keyboard are in order from left to right: Ctrl, Alt, Super (aka. Cmd, , Windows-key). I'd like the order to be Ctrl, Super, Alt instead, and so I have proceeded to remap them.

There's a rub, tough, because I regularly attach an external keyboard which has the keys in the correct order already. If I swap the keys here, they end up wrong.

So I want to remap/swap the keys for apple keyboards specifically. As a substitute for this, I'd gladly accept remaping the keys for the specific keyboard stuck in my laptop only (as opposed to all apple keyboards automatically).


After researching this, I have ended up with a solution that is only half working.

I am running the following script on login (~/.kde/Autostart/custom-remap.sh), which attempts to remap the keys for my internal keyboard only:

#!/bin/bash -eDIRNAME=$(dirname $0)# Use xinput to target a specific keyboard only:APPLE_KEYBOARD_ID=$(    xinput list |    grep 'Apple Internal Keyboard' |    sed -n 's/.*id=\([0-9]\+\).*/\1/p')# Apply mappings from xkb/symbols/custom# Maps ctrl, win and alt-keys to be in PC standard positionssetxkbmap -device $APPLE_KEYBOARD_ID -print |    sed 's/\(xkb_symbols.*\)"/\1+custom(apple-keyboard-swaps)"/' |    xkbcomp -I$DIRNAME/xkb -i $APPLE_KEYBOARD_ID -synch - $DISPLAY

This relies on the following file, xkb/symbols/custom:

xkb_symbols "apple-keyboard-swaps" {    key <LWIN> { [ Alt_L ] };    key <LALT> { [ Super_L ] };    key <RWIN> { [ Alt_R ] };    key <RALT> { [ Control_R ] };};

This solution sometimes works perfectly, sometimes has no effect and recently it seemed like a hybrid result took root in my system: Neither of the Alt or Super keys would work properly, they seem to act a little bit as both.

"Sometimes" is really ill defined. I can get into either state after a reboot. Attaching/detaching my external keyboard might trigger a state change. Other times, seemingly at random, the state will switch while I'm using the computer. Running the script multiple times does not seem to affect the state (if it doesn't take the first time, it doesn't take the n-th time either).


How can I achieve the relevant remapping and have it working reliably?

(I am currently running Kubuntu 14.04, but it acted similarly under Kubuntu 13.10)


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images