You are not logged in.

#1 2013-09-15 20:52:06

Kebertx
Member
Registered: 2012-01-02
Posts: 69

[SOLVED]Switching Caps Lock with Shift_L

I have a broken left shift key, and it's a bit of a pain to type with. I often use an external keyboard, so this doesn't always bother me, but when I take my laptop with me somewhere, I would like to be able to quickly swap Caps and Left Shift. For a while, I've done that like this:

xmodmap -e "keycode  66 = Shift_L NoSymbol Shift_L" 

But xmodmap is deprecated, and causing problems with qt5 applications, so I want to ditch it and do the same thing with setxbmap instead. Now, xkb is really nice, it is full of built in options for common remaps, and a quick look around shows my I can use any one of these to change how caps lock works:

  grp:caps_switch      Caps Lock (while pressed), Alt+Caps Lock does the original capslock action
  grp:caps_toggle      Caps Lock
  grp:shift_caps_toggle Shift+Caps Lock
  grp:shift_caps_switch Caps Lock (to first layout), Shift+Caps Lock (to last layout)
  grp:alt_caps_toggle  Alt+Caps Lock
  lv3:caps_switch      Caps Lock
  lv3:caps_switch_latch Caps Lock chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
  ctrl:nocaps          Caps Lock as Ctrl
  ctrl:swapcaps        Swap Ctrl and Caps Lock
  grp_led:caps         Caps Lock
  caps                 Caps Lock key behavior
  caps:internal        Caps Lock uses internal capitalization. Shift "pauses" Caps Lock
  caps:internal_nocancel Caps Lock uses internal capitalization. Shift doesn't affect Caps Lock
  caps:shift           Caps Lock acts as Shift with locking. Shift "pauses" Caps Lock
  caps:shift_nocancel  Caps Lock acts as Shift with locking. Shift doesn't affect Caps Lock
  caps:capslock        Caps Lock toggles normal capitalization of alphabetic characters
  caps:numlock         Make Caps Lock an additional Num Lock
  caps:swapescape      Swap ESC and Caps Lock
  caps:escape          Make Caps Lock an additional ESC
  caps:backspace       Make Caps Lock an additional Backspace
  caps:super           Make Caps Lock an additional Super
  caps:hyper           Make Caps Lock an additional Hyper
  caps:shiftlock       Caps Lock toggles Shift so all keys are affected
  caps:none            Caps Lock is disabled
  caps:ctrl_modifier   Make Caps Lock an additional Control but keep the Caps_Lock keysym
  compose:caps         Caps Lock
  compose:caps-altgr   3rd level of Caps Lock
  shift:breaks_caps    Shift cancels Caps Lock
  shift:both_capslock  Both Shift-Keys together toggle Caps Lock
  shift:both_capslock_cancel Both Shift-Keys together activate Caps Lock, one Shift-Key deactivates

...

None of those allow me to use caps lock as a normal shift. I'm trying to figure out how to rebind caps to work as a shift, but I want to have this in a script so that my external keyboard will stick with its default behavior, and I can just type "fixshift" when I unplug it. Basically, just manually switch the two with setxkbmap the way I did with xmodmap. Out of a long while searching, and /only/ finding advice to use one of the default options, and none on making my own, I've decided to come here.

Any help, Arch-friends?

Last edited by Kebertx (2013-10-31 09:10:14)

Offline

#2 2013-10-31 09:28:31

Kebertx
Member
Registered: 2012-01-02
Posts: 69

Re: [SOLVED]Switching Caps Lock with Shift_L

For the record, here's my solution:

This creates a custom key symbol to swap Caps and Shift:

/usr/share/X11/xkb/symbols/custom

partial modifier_keys
xkb_symbols "swapcaps" {
    replace key <CAPS>  { [ Shift_L ] };
    replace key <LFSH>  { [ Caps_Lock ] };
};

This script prints a description of the keymap, adds the symbol to swap the two keys from that other file to the right line, and writes the new description to a temporary file... then compiles it!

/usr/local/bin/fixshift

#!/usr/bin/bash

setxkbmap -print | sed '/xkb_symbols/ { s/"/+custom(swapcaps)"/2 }' > /tmp/fixshift
xkbcomp /tmp/fixshift $DISPLAY > /dev/null 2>&1 &

Then I just set that program to run every time lightdm starts a session:

/etc/lightdm/lightdm.conf

...
display-setup-script=/usr/local/bin/fixshift
greeter-setup-script=/usr/local/bin/fixshift
session-setup-script=/usr/local/bin/fixshift
...

And nothing more to it. Life is grand again.

Offline

#3 2015-05-10 20:53:40

dinebennett
Member
Registered: 2015-05-10
Posts: 1

Re: [SOLVED]Switching Caps Lock with Shift_L

Thank you so much for this, it was such a great help to me!

Offline

#4 2015-05-10 21:00:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED]Switching Caps Lock with Shift_L

Please don't necrobump, especially with empty posts https://wiki.archlinux.org/index.php/Fo … bumping.22



Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB