2

I tried these:

  1. First I tried with xmodmap

    clear Lock

    keycode 66 = F12

but the issue is that it would reset my custom mapping after every reboot or log out. Therefore I had to run the command xmodamp ~/.Xmodmap every single time after reboot or log out. Trying to automate doesn't help either because xmodamp ~/.Xmodmap would take like 10 seconds in order to run and during that time the whole computer is block, i.e. I could not switch to or use any other program.

Also I heard using xmodmap isn't really recommended.

  1. The next thing I tried was setting F12 in the file /usr/share/X11/xkb/symbols/pc. I tried something like this: key <CAPS> {»-[ F12»»-]»}; (<-- the » symbol represents tabs on my computer). But that doesn't seem to have any effect.

Is there a way to permanently remap the Caps Lock to the function key F12?

jesse_b
  • 37,005
  • Possible duplicate - https://unix.stackexchange.com/questions/107566/how-to-swap-ctrl-and-capslock-using-xmodmap/107568#107568. – slm Jul 07 '18 at 17:14
  • @slm From my understanding, your links provides information of how to remap the Caps_Lock with keys like Alt, Ctrl_R, Ctrl_L, etc. But they don't tell me how to remap to F12. Using xev doesn't help me either. I tried to set F12 with keycode 96 and Oxffc9 in xmodmap. But it didn't help. – thadeuszlay Jul 07 '18 at 21:51
  • Take a look at this one then - https://unix.stackexchange.com/questions/49650/how-to-get-keycodes-for-xmodmap. Search the site for 'remap key' we have a lot of these Q&A's already solved, you're not doing anything new here from the collection of other Q's IMO, except for the key choices 8-). – slm Jul 07 '18 at 22:05
  • @slm I looked already. The problem is that remapping Caps_Lock is not your ordinary use case. Also I mentioned the issues with using xmodmap, i.e. it resets after reboot and log out; takes too long to load - thus not feasible for automation; not really recommended. – thadeuszlay Jul 07 '18 at 22:28

2 Answers2

2

I know this is an old question, but I've been struggling with exactly the same issue.

To me the problem seems to be either something overwrites the xmodmap setting (for instance, setxkbmap will do that, so make sure, if it's a part of your .Xmodmap to use it before the xmodmap command), or it is not run.

My .xinitrc clearly looks like it should run my .Xmodmap...

What does your setup look like?

I'm using i3 and I have what I'd call a workaround now, by running xmodmap ~/.Xmodmap in my i3-config file, which works. I don't like this solution because if I use my Plasma setup, CapsLock will be back to normal.

My .Xmodmap looks like this:

remove Lock = Caps_Lock
keysym Caps_Lock = F12

I don't think I have your issue of xmodmap ~/.Xmodmap taking a long time.

I hope we can find a solution, let me know if you do.

Thanks.

Morten
  • 100
0

Following this answer worked for me: https://unix.stackexchange.com/a/170357/105061

I'm paraphrasing it here for completeness:

  1. Run sudo evtest to find
  • The keyboard bus, vendor, and product. Look for a line similar to this:
Input device ID: bus 0x3 vendor 0x46d product 0xc31c version 0x110
  • The scancode of the key you want to change. Press the key and note the value after (MSC_SCAN).
Event: time 1678720211.060421, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70039
  1. Create a file with the remapping, in /etc/udev/hwdb.d/98-custom-keyboard.hwdb. Be careful to convert the identifiers to uppercase so that they can be discerned from the delimeters b, v, and p. The key name should be lowercase. My file ended up looking like this:
evdev:input:b0003v046DpC31C*
 KEYBOARD_KEY_70039=f12       # capslock to f12
  1. Rebuild the database with sudo udevadm hwdb --update.
  2. Apply the settings with sudo udevadm trigger --sysname-match="event*".
  3. Optionally, run sudo evtest again to verify that it works.
morotspaj
  • 101