You are not logged in.

#1 2015-02-11 19:35:23

l0vot
Member
Registered: 2011-08-26
Posts: 117

setkeycodes refuses to set capslock to a different key

I hate the caps-lock key, it's worse than useless and placed in prime rel-estate on most keyboards, at first I dealt with it by physically removing it from my keyboards, but later I realized it could be mapped to a more useful key, if only I could figure out how to re-map it at a low enough level that it would work before X starts, setkeycodes appears to be what I'm looking for but it won't re-map caps-lock for some reason, and returns an error:

~]# setkeycodes 0x58 28
KDSETKEYCODE: Invalid argument
failed to set scancode 58 to keycode 28

Any ideas?

Offline

#2 2015-02-11 20:05:07

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: setkeycodes refuses to set capslock to a different key

X has several options available for remapping Caps. For example I swap Caps and Left Ctrl:

$ cat /etc/X11/xorg.conf.d/
Section "InputClass"
        Identifier "system-keyboard"
	Driver "evdev"
        Option "XkbLayout" "carpalx"
        Option "XkbOptions" "ctrl:swapcaps"
EndSection

AFAIK, swapping caps in the console requires a custom keytable (/usr/share/kbd/keymaps/). That's how I do it, but I had to create a custom one for my keymap anyway.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#3 2015-02-11 20:12:00

l0vot
Member
Registered: 2011-08-26
Posts: 117

Re: setkeycodes refuses to set capslock to a different key

@alphaniner: I need a method that works before X starts, and continues to work after X starts.

Offline

#4 2015-02-11 20:18:18

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: setkeycodes refuses to set capslock to a different key

When used together, these two separate methods provide the same outcome. If you're looking for one single method to cover both, you may be out of luck:

setkeycodes(8) wrote:

...
BUGS
       The keycodes of X have nothing to do with those of Linux.

My interpretation of that is that changes made by setkeycodes (perhaps even any changes affecting console) will have no effect under X.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#5 2015-02-11 20:48:30

l0vot
Member
Registered: 2011-08-26
Posts: 117

Re: setkeycodes refuses to set capslock to a different key

alphaniner wrote:

When used together, these two separate methods provide the same outcome. If you're looking for one single method to cover both, you may be out of luck:

setkeycodes(8) wrote:

...
BUGS
       The keycodes of X have nothing to do with those of Linux.

My interpretation of that is that changes made by setkeycodes (perhaps even any changes affecting console) will have no effect under X.

Setkeycodes is supposed to change the code reported by a key press, which should translate over to X. There has to be a way to re-map keys globally, even if setkeycodes can't.

Offline

#6 2015-06-18 06:42:55

Herodotus
Member
Registered: 2015-06-16
Posts: 24

Re: setkeycodes refuses to set capslock to a different key

This article may help: https://wiki.archlinux.org/index.php/Ma … o_keycodes

setkeycodes needs no 0x. For me, e.g. "setkeycodes 45 33" binds NumLock on laptop keyboard to 'f'. I don't think setkeycodes works at all with USB keyboards. You need "evtest" (MSC_SCAN, field "value") not "showkey" to get USB scancodes, then these can only be used with udev hwdb, AIUI.

This is how I map left alt to control, and caps to left alt:

$ cat /etc/udev/hwdb.d/10-my-sane-modifiers.hwdb    
keyboard:usb:* # match all keyboards for now
keyboard:usb:v05AFp8277* # but especially my Kensington Slim Type
 KEYBOARD_KEY_70039=leftalt    # bind capslock to leftalt
 KEYBOARD_KEY_700e2=leftctrl   # bind leftalt to leftctrl

keyboard:dmi:* # laptop keyboard, match all
 KEYBOARD_KEY_3a=leftalt    # bind capslock to leftalt
 KEYBOARD_KEY_38=leftctrl   # bind leftalt to leftctrl

$ sudo udevadm --debug hwdb --update; sudo udevadm trigger
     # recompile database and apply it
$ sleep 4; setxkbmap us ,qwerty -option altwin:left_meta_win
     # run something like this to activate meta key
     # (and update xorg.conf using e.g. localectl to make it permanent)

The setup still has the problem that I need to run "sudo udevadm trigger" every time I restart X. Which is weird because the commands also fix the console keymap... Still ironing it out.

Last edited by Herodotus (2015-06-18 11:13:26)

Offline

#7 2015-06-19 05:12:41

snakeroot
Member
Registered: 2012-10-06
Posts: 164

Re: setkeycodes refuses to set capslock to a different key

@10vot, you should consider using kmscon, which accepts X-style keyboard mappings.

Offline

Board footer

Powered by FluxBB