* updates
** 9/15/19
revised my tutorial to make it a bit more organized and to fix a typo i discovered after following my own tutorial after reinstalling mint.
* introduction
hello everyone. i don't post much on the forums here, but i wanted to share a neat trick with with emacs. if you have a keyboard with dual super keys [also referred to as the 'windows key'] it's possible to re-purpose one into a new mod key for use inside emacs. it's also handy for key combos outside of emacs as well, so even if you don't use that text editor this tutorial may still be of interest to you. this tutorial is written with the intention of re-purposing your left super key into a left hyper key.
* background
what is a hyper key?
it's a mod key, similar to CTRL*SHIFT*ALT. it dates back to the era of dedicated lisp machines, the type of computer where emacs was first developed. from my own research, it would appear the hyper key was typically reserved for user key combos. it made it's debut on the space-cadet keyboard which you can read more about on this linked article:
https://en.wikipedia.org/wiki/Space-cadet_keyboard
here's a direct link to an image of the space-cadet keyboard:
emacs doesn't bind anything to the hyper key by default. this makes it an excellent choice in binding the hyper key to an extra physical key on your keyboard. furthermore, it gives you an extra mod key for combos inside of linux mint itself. i have only personally done this in mint, but i assume it should work in any linux version. feel free to correct me if i'm wrong.
* walk-through
quick note: if at anytime you've somehow messed up the keyboard layout and bindings, you enter the following in terminal:
Code: Select all
setxkbmap -layout us
** check existing bindings
before you do anything, open a terminal window and type the command below:
Code: Select all
xmodmap
specifically what i want you to look for is a group called mod3. it should be blank. this is important as this is the mod group where the titular hyper key will be assigned after you follow the instructions for this tutorial.
in mod4 you should see keybindings for super-l, super-r, and hyper-l keys.
i'd assume hyper-l is already bound to some key-code in the off chance that a user ever connects a keyboard with an actual hyper key, it will already be assigned and detected by the operating system automatically. it more or less exists like a phantom limb for most modern keyboards, if that makes sense to you.
** find existing key-code for super-l
in order to reassign your super-l key, you must find out its corresponding key-code.
inside a terminal window, you need to type the command below:
Code: Select all
xev
what you're looking for is any text referring to Key Press event or KeyRelease event
once you locate that bit of text, locate a line which should start out something like state 0x10, keycode
read the numbers immediately after the word keycode in that line. in my case, this keycode number was 133, depending on your keyboard/layout it may or may not be different.
** config file
inside the terminal do the following:
Code: Select all
touch ~/.Xmodmap
Code: Select all
nano ~/.Xmodmap
touch: if you aren't already aware, touch is a shell command to create a file, followed by the location of where to place it along with the name you've chosen for it.
~/: this refers to your home folder
nano: this opens a cli text editor called nano. usually in guides, people use gedit, or in the case of linux mint and cinnamon, xed. i like nano for terminal work and scripting in general. it's installed on mint by default. when you enter this command with the name/location of the file you just created, it will then be opened inside nano within the terminal window.
*** file contents
once inside the .Xmodmap file, you need to place the following text:
Code: Select all
clear mod3
clear mod4
keycode # = Hyper_L
add mod3 = Hyper_L
keycode # = Super_R
add mod4 = Super_R
where the # symbol appears above, you need to replace with the appropriate key-code.
in my case, my .Xmodmap file looks like so:
Code: Select all
clear mod3
clear mod4
keycode 133 = Hyper_L
add mod3 = Hyper_L
keycode 134 = Super_R
add mod4 = Super_R
*** source the config file
enter the following command inside the terminal:
Code: Select all
xmodmap ~/.Xmodmap
for now, test the results. rerun the xev command inside a terminal window. again, ignore the pop-up window as we are not concerned with mouse-related events. press the super-l key. all previous references to super-l should be gone, and now you should see hyper-l popping up and being associated with super-l's key-code.
additionally, if you are an emacs user, you could also test the key bind inside there. simply open emacs and press hyper-l [set to the physical super-l key] and another key such as i.
emacs should say H-i is undefined.
references to the hyper key inside emacs are stylized as a capitol 'H' same as ctrl is represented as 'C' and the alt/meta key as 'M'.
if you saw H-i is undefined that's good! emacs is already capable of accepting the hyper key for key combos and this is just to show you it is trying to interpret a command from it. you'll have to actually bind something inside of emacs itself if you want H-i to mean something there however.
** reboot and suspend
if you've followed my instructions so far, you'll note that it becomes necessary to run:
Code: Select all
xmodmap ~/.Xmodmap
you need to make a startup entry to run the command from above automatically every-time that you log into mint.
*** startup entry
press the super-r key to open the start menu and type start
you should immediately see an entry for startup applications. you need to hit the enter key to open the sub-menu for it.
on the startup entry sub-menu, look at the bottom of the window for a + symbol. click on that, then click on custom command.
you will see a window popup that says add startup program along with fields for name, command, comment, and startup delay.
for name, keep it simple such as:
hyper-l
for command put the following:
Code: Select all
xmodmap ~/.Xmodmap
binds hyper-l to super-l key
for startup delay:
do nothing for this line, just leave it blank.
with everything filled out, click the add button, and the entry will be added to the list of startup applications and commands.
*** suspend state
you will need to create a service file which in turn runs a script to reload the .Xmodmap file after coming back from a suspend state. this is necessary, otherwise, going to and returning from suspend will restore the default keyboard layout.
**** create the service file
inside the terminal do this:
Code: Select all
sudo touch /etc/systemd/hyper-l.service
Code: Select all
sudo nano /etc/systemd/hyper-l.service
Code: Select all
[Unit]
Description=reset super-l to hyper-l
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/path/to/your/script/hyper-l-fix.sh
[Install]
WantedBy=sleep.target
**** script for service file
you need to create the script that will be run after waking from suspend. if you don't create the script, the keybinding won't be applied after returning from suspend, and the default keyboard layout will be restored.
***** location for script
personally i put all my personal scripts inside the subdir 'scripts' inside the 'documents' dir which itself exists inside my home directory.
if you want to do this like me, then first create the subdir as specified below, along with making a blank script file inside there. do this [inside the terminal]:
Code: Select all
mkdir ~/Documents/scripts
Code: Select all
nano ~/.bashrc
Code: Select all
# custom user settings
export PATH="$HOME/documents/scripts:$PATH"
again if you're doing this inside nano, press CTRL+S to save and CTRL+X to close the file and the text editor.
you will need to load/source the .bashrc file to make the added path for your scripts effective immediately.
to source the .bashrc file, type the following inside the terminal and press enter:
Code: Select all
source ~/.bashrc
do this:
Code: Select all
touch ~/Documents/scripts/hyper-l-fix.sh
Code: Select all
nano ~/Documents/scripts/hyper-l-fix.sh
Code: Select all
#!/bin/bash
xmodmap ~/.Xmodmap
you need to make the script executable:
via terminal:
Code: Select all
chmod +x hyper-l-fix.sh
Code: Select all
chmod +x ~/Documents/scripts/hyper-l-fix.sh
and that's it, your done. you can test what you did in this tutorial by rebooting and logging into cinnamon. try pressing the super-l key. if it's doing nothing, that means the startup service correctly ran the .Xmodmap file at startup. also, if it does nothing, that's because you haven't set the hyper-l key to any command inside of cinnamon.
now try suspending your computer, then bring it back. try the key again. if it's still doing nothing, then that's good because the script ran successfully and the super-l key is still bound to hyper-l after suspending. you can always double-check by opening terminal and typing xmodmap to see what's bound.
now you have a new mod key to use inside of emacs, or anywhere in linux.