iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article

Using a Japanese ThinkPad Keyboard with US Layout on Mac

に公開

This is an article for the 20th day of the SmartHR Advent Calendar.

https://qiita.com/advent-calendar/2021/smarthr

It has been 50 days since I joined SmartHR. I am called tommy internally (there is a culture of calling each other by Slack names, and since tmtms is hard to say, I went with tommy).

My work PC is a MacBook Pro, making it my first Mac ever. With 32GB RAM / 512GB SSD, it feels like it has very decent specs. Also, it seems the PC is eligible for replacement every two years.
Having been in workplaces where I had to use much worse PCs for five years, this is wonderful.

If you're developing programs that run on Linux, I think it's better to use Linux than macOS, but since business apps often have poor support on Linux, I have no choice.

However, the MacBook is cold in the morning during this season. It warms up after using it for a while, so it's good for heating your hands, but at this rate, I suspect it will get quite hot in the summer.

I had the option to choose between an English and a Japanese keyboard, so I went with the English layout, but that was a mistake. Since I usually use a Japanese keyboard with an English layout, I thought I could manage somehow, but I was naive.

The biggest issue is mispressing Esc. I'm used to having Esc located to the left of 1. If I move Esc to the left of 1, though, there's no place for the backtick (`) key.

So, would a Japanese keyboard have been better? A standard Japanese keyboard has the Half-width/Full-width key to the left of 1, but for some reason, the Mac Japanese keyboard makes the 1 key larger and has no key on its left, so it was out of the question from the start.

Consequently, I decided to use the USB-connected ThinkPad TrackPoint Keyboard I've been using. This also solves the problem of it being too cold to rest my hands in the morning.

The Japanese version of the ThinkPad keyboard has this layout:

When you make it recognized as an English keyboard, it looks like this:

I usually change these red keys in Linux as follows, so I wanted to achieve something similar on Mac.

I found that I could freely modify keymaps with something called Karabiner-Elements. Seriously, this is a godsend app.

You can apply settings specifically to the external keyboard, so even if you disconnect the keyboard and have to use the laptop itself, the keymap won't get messed up.

It seems that keys on a Japanese keyboard that aren't on an English keyboard can be referenced as internationalX, and the mapping was as follows:

  • international1 → ろ (Ro)
  • international2 → カタカナひらがな (Katakana/Hiragana)
  • international3 → ¥ (Yen)
  • international4 → 変換 (Henkan/Convert)
  • international5 → 無変換 (Muhenkan/Non-convert)

I got a bit stuck on the fact that the \ key (originally the ] key) was non_us_pound rather than backslash.
I was able to confirm this with a tool called Karabiner-EventViewer.

It seems settings can be changed for short and long presses. I imported "For Japanese (settings for Japanese environment)" via "Complex modifications" → "Add Rule" → "import more rules from the Internet" and enabled "When the command key is pressed alone, send the Eisu/Kana keys."

Since I didn't know what to use the option key (the Alt key on the keyboard) for, I assigned it to command as well.

I imported "Change mouse motion to scroll" and enabled "Change button3 + mouse motion to scroll wheel," which allowed me to scroll with the middle button + TrackPoint, but I also wanted to enable middle-clicking with the middle button on its own.

I couldn't find anything by Googling, but I figured that since the function can be switched based on whether the command key is pressed briefly or held down, I should be able to do something with the middle button as well. After tinkering with ~/.config/karainer/karabiner.json a bit, I got it to work. I don't know if this is the correct way to do it.

    "profiles": [
        {
            "complex_modifications": {
                "parameters": {
                    "basic.simultaneous_threshold_milliseconds": 50,
                    "basic.to_delayed_action_delay_milliseconds": 500,
                    "basic.to_if_alone_timeout_milliseconds": 1000,
                    "basic.to_if_held_down_threshold_milliseconds": 500,
                    "mouse_motion_to_scroll.speed": 100
                },
                "rules": [
                    {
                        "available_since": "12.3.0",
                        "description": "Change button3 + mouse motion to scroll wheel (rev 1)",
                        "manipulators": [
                            {
                                "from": {
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    },
                                    "pointing_button": "button3"
                                },
                                "parameters": {
                                    "basic.to_if_alone_timeout_milliseconds": 100
                                },
                                "to": [
                                    {
                                        "set_variable": {
                                            "name": "enable_mouse_motion_to_scroll",
                                            "value": 1
                                        }
                                    }
                                ],
                                "to_after_key_up": [
                                    {
                                        "set_variable": {
                                            "name": "enable_mouse_motion_to_scroll",
                                            "value": 0
                                        }
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "pointing_button": "button3"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "name": "enable_mouse_motion_to_scroll",
                                        "type": "variable_if",
                                        "value": 1
                                    }
                                ],
                                "from": {
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "type": "mouse_motion_to_scroll"
                            }
                        ]
                    },

With this, I can now use it normally.


However, macOS is hard to use. I think a big part of it is just that I'm not used to it, but what's with the distance between the window and the menu bar? In this era of large screens like 4K, is it still based on the assumption that a single window is used in full screen?

Another thing is that you can't give keyboard focus to a window just by hovering the mouse over it. It's inconvenient.

One thing I thought was the sole advantage over Windows or Linux is that keyboard shortcuts are assigned to the command key, separate from the control key used for text editing. When editing text in a browser, Ctrl-N isn't hijacked by the browser. I wish Linux and Windows had assigned shortcut keys to Alt too.

But this very advantage is the part I'm struggling with the most because I'm not used to it. I think it's because I use a Linux desktop outside of work, so maybe I should try using shortcuts similar to macOS on Linux as well...

I feel like I could probably manage to some extent if I use xremap or xkeysnail and set them up properly.

Discussion