I been using this great drop-down terminal called Guake for the past couple of years. I conveniently set the open hot key to F1, so I can easily open guake anytime. This worked for a while until I started playing video games on Ubuntu, the F1 key is often used in real-time strategy games, so now I had to pick a new hot key.
I started scanning my keyboard for the most uncommonly-used convenient key. And I found it, the caps lock key. I always heard of people remapping it to escape or a ctrl key, and now is the time to try it.
From the Guake preference you can’t actually map caps lock to the open hot key, so I decided to make the hot key F12 and remap caps lock to F12.
Did some searching online and found this to be the simpliest solution:
This will map caps lock to F12 and make the key no longer act like caps lock. Except this doesn’t persist on re-logins, suspensions and it’s deprecated, so best using something else.
Next up setxkbmap
, it’s apparently the new way of remapping keys. Running the
help command I see this.
Awesome, but how do I remap caps lock to F12?
From what I could gather, you’re supposed to remap keys by editing this file /usr/share/X11/xkb/symbols/pc
. There are symbol files for many different keyboard layouts but pc
is the root-level keyboard and is loaded first. The format is quite simple, give it a key code and then set what it should do.
The next step is to find the keycodes for F12 and caps lock.
Type in xev inside your terminal, when you hit enter, xev will launch. xev takes all of your input and pops info about the key into the command line. I recommend bringing your mouse over the exit key of the xev window, hitting caps lock (or whatever key you want to find out about), and immediately exiting xev.
Press your keys inside this window
You will see your key presses in the terminal
The key name, not surprisingly, is F12
, so now to put it all together. Copy and paste this to /usr/share/X11/xkb/symbols/pc
:
Just incase I ever want to use caps lock again, I remapped number lock to caps lock.
Delete the cached server-* files in /var/lib/xkb/
and restart your computer.
Done.