This guide provides detailed steps to configure your Apple Magic Keyboard (Japanese layout) to work properly on Linux, including remapping keys like Kana (Henkan) and Alphanumeric (Muhenkan) to switch between Kana and Alphanumeric input modes using Mozc input method. It also includes instructions on how to switch between Magic Keyboard and basic layouts using shell scripts.
- Linux (tested on Ubuntu).
- Apple Magic Keyboard (Japanese Layout) connected via Bluetooth.
- Mozc or another Japanese input method installed via IBus.
To ensure that the Japanese input method works properly, you need to install IBus and Mozc.
-
Install IBus and Mozc:
sudo apt update sudo apt install ibus ibus-anthy ibus-mozc
-
Restart the IBus daemon:
ibus-daemon -drx
-
Configure IBus Input Method:
- Run the following command to open IBus settings:
ibus-setup
- Under the Input Method tab, make sure Mozc (Japanese) is added and set as the default input method.
- Run the following command to open IBus settings:
-
Switch to Japanese Input:
- Use the IBus system tray icon to switch to the Japanese input method (Mozc).
- Alternatively, you can use the default keyboard shortcut (
Ctrl + Space
) to toggle between input methods.
You need to map the Kana (Henkan) and Alphanumeric (Muhenkan) keys using xmodmap to properly switch between input modes.
-
Create or Edit the
.Xmodmap
File:- Open or create the
.Xmodmap
file in your home directory:nano ~/.Xmodmap
- Add the following lines to map keycodes 130 and 131 (Kana and Alphanumeric keys):
keycode 130 = Henkan_Mode NoSymbol Henkan_Mode keycode 131 = Muhenkan NoSymbol Muhenkan
- Save and exit the editor (
Ctrl + X
, thenY
, thenEnter
).
- Open or create the
-
Apply the Key Mappings:
- To apply the mappings immediately, run:
xmodmap ~/.Xmodmap
- To apply the mappings immediately, run:
-
Verify the Key Mappings:
- Run the following command to ensure the key mappings are applied correctly:
xev
- Press the Kana and Alphanumeric keys and check if the correct keysyms (Henkan_Mode and Muhenkan) are triggered in the output.
- Run the following command to ensure the key mappings are applied correctly:
To ensure the Kana and Alphanumeric keys are interpreted correctly, set your keyboard layout to Japanese.
- Set Layout to Japanese:
setxkbmap -layout jp
-
Test Switching Between Input Modes:
- With Mozc as the active input method, press the Kana (かな) key to switch to Kana mode.
- Press the Alphanumeric (英数) key to switch back to Alphanumeric mode.
-
Test the Behavior in
xev
:- Run
xev
and verify that pressing the Kana and Alphanumeric keys triggers the correct keysyms (Henkan_Mode and Muhenkan).
- Run
To automatically apply the .Xmodmap
settings each time you log in:
-
Open your
.bashrc
or.profile
file:nano ~/.bashrc
-
Add the following line to apply the
.Xmodmap
file on startup:xmodmap ~/.Xmodmap
-
Save and exit (
Ctrl + X
, thenY
, thenEnter
). -
Reload
.bashrc
:source ~/.bashrc
To easily switch between the Magic Keyboard layout and a basic keyboard layout, you can use the provided shell scripts: switch_to_basic.sh
and switch_to_magic.sh
.
-
Create the Shell Scripts:
-
Create two shell scripts:
switch_to_basic.sh
andswitch_to_magic.sh
in your home directory. -
switch_to_basic.sh:
#!/bin/bash # Switch to basic keyboard layout (e.g., US layout) setxkbmap -layout us
-
switch_to_magic.sh:
#!/bin/bash # Switch to Magic Keyboard layout (Japanese layout) setxkbmap -layout jp
-
-
Make the Scripts Executable:
chmod +x ~/switch_to_basic.sh chmod +x ~/switch_to_magic.sh
-
Run the Scripts:
- To switch to the basic layout, run:
~/switch_to_basic.sh
- To switch to the Magic Keyboard layout, run:
~/switch_to_magic.sh
- To switch to the basic layout, run:
- If the keys still don't work as expected, try restarting the IBus daemon:
ibus-daemon -drx
- If key mappings are not applying, recheck your
.Xmodmap
file or manually runxmodmap ~/.Xmodmap
. - Verify the keycodes using
xev
to make sure they match the expected Kana and Alphanumeric keys.
- IBus Documentation: IBus Official Site
- Mozc Documentation: Mozc GitHub