How can I make any key into a modifier key?
Solution 1:
If I understand you right, what you want is to uncheck the option "Key presses repeat when key is held down" at Menu > System > Preferences > Keyboard.
Solution 2:
The first thing you need to do is identify the 'keycode' or 'keysym' of the key you would like to replace and the key you would like to replace it with.
Let's do an example of replacing the 'F12' key with 'Left Super'.
- Open the terminal and run this command:
xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'
This will run xev which captures keypresses, strips out irrelevant information and gives you, via the terminal output, both the 'keycode' and 'keysym' of the key which you press. Press each of the keys you want to replace and the one you want to replace it with.
When I press F12 on my keyboard, I get this output:
96 F12
And when I press Left Super on my keyboard, I get this output:
133 Super_L
You will need to write these down somewhere or remember them to use later.
- Open up a text editor and enter this text (my example of replacing F12 with Left Super):
keycode 96 = Super_L
or
keysym F12 = Super_L
In my testing, either option should work.
-
Save this file in your home directory as
.Xmodmap
(note the capitalised "X") -
To test it out, in terminal again enter this command from your home directory:
xmodmap .Xmodmap
If everything went to plan, your F12 key should now work as your Left Super.
Each time you make a change to your .Xmodmap
file you can run the above command again to apply changes.
You shouldn't need to run this command each time you login, as it should be read and applied each time you login. If however this doesn't work, then of course you could place this command into a startup script.
There are a few caveats to mention:
a) Some keyboards will have a key labelled "Fn" or similar to access secondary functions on keys, like multimedia controls. From what I've read, you cannot remap this particular "Fn" key itself, though you should be able to remap the individual multimedia keys that pressing "Fn+key" provides.
b) If you unplug and re-plug back in your keyboard, you will need to reload the .Xmodmap
configuration with the same command give in step 4 above.
c) If for some reason you want to comment out (ignore) a line in the .Xmodmap
file, you need to put a "!" at the front of the line (instead of a "#" as in some other configuration files).