Monday, September 06, 2021

Mapping Muhenkan key to Alt key in Windows and Linux

I use a keyboard which does not have an Alt key, which can be quite troublesome since many keyboard shortcuts use that key. So I usually have to find a way to map the Muhenkan (無変換) key to Alt key.

In Windows 10, there is a software known as PowerToys which comes with a Keyboard Manager that allows you to do such mapping. I gave it a try, but it ended up disabling my Windows key (after it does map Muhenkan to Alt).

So I went back to the tried method of a registry entry that maps the scan code. But instead of having to manually edit the registry myself, I use the program SharpKeys. You will need administrator rights to run this program, since it makes changes to the registry. But it is really helpful. Just add a new entry, type in the key you want to map (in my case, Muhenkan), then on the other side, select the key to map to. For Alt key, you cannot use the "Type in key" option, so you have to select it from the list of available keys. Alt is under "Special".

There is another method for Linux, which uses Xmodmap.
Basically, create a file called .Xmodmap in your home directory. Then fill it with:
keycode 102 = Alt_L
keycode 101 = Alt_R
add mod1 = Alt_R

Then, run
xmodmap ~/.Xmodmap
to activate.
 
To do this whenever I boot up, I created a file called keymapping.sh with the following:
#!/bin/bash
/usr/bin/xmodmap ~/.Xmodmap

and add keymapping.sh to my startup applications.

No comments: