0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Karabinerを使って無変換キーを\にした話(Mac)

Last updated at Posted at 2023-03-03

はじめに

私は日本語と英語の切り替えをcaps lockキーで切り替えているので、
無変換キー、変換キーをプログラミングで使えそうな文字に割り当てようと考えた。

バージョン

macOS: Ventura 13.1
Karabiner: 14.11.0

インストール

ダウンロードは以下のサイトでできる。

インストールはこの記事では省略する。

早速、設定して解決!と思いきや...

ああああ.png
Virtual KeyboardをJIS(Japanese)に設定し、
Simple Modificationsで使いたいキーボードを選び、
Add itemする。
左の項目でJapanese -> PCキーボードの無変換キー
右の項目でControls and symbols -> backslash (\)
と設定してできた!と思いきや、無変換キーを押すと「]」が入力されてしまった。

原因

JISキーボードではなく、USキーボードのkeycodeになっていたことが原因だった。

このサイトの「JISキーボードを使っていて、記号の割り当てがおかしいとき」(見出し)に答えがあった。

なので、toのkeycodeをinternational1にしてみた。

再び失敗

今度は、「_」が表示されてしまった。
確かにキーボードの表記の左手前(物理)に「\」表記があるのだが、
入力画面に「\」は、まだ出力できていないようだ。

別の方法として、option+¥を配置できないだろうか?

option+¥の割り当て

karabiner.jsonのtoを次のように割り当てた。

"simple_modifications": [
    {
        "from": {
            "key_code": "japanese_pc_nfer"
        },
        "to": [
            {
                "key_code": "international3",
                "modifiers": ["option"]
            }
        ]
    }
]

この「to」の場所は、Karabiner-ElementsのSimple Modificationsで
Add itemしたときに追加された場所を編集した。
同時押しして入力するのではなく、入力した結果が同時押しの場合は、modifiersをこのように指定すると上手くいった。
右上の¥はinternational3だったので、international1から変更した。

参考にしたサイトは以下である。

キーコードの調査では、Karabiner-EventViewerを使用した。
キーボードを押すだけで調査できる。

補足

出力側で同時押しを使いたい場合は上の書き方でいいのだが、
入力側で同時押しを使いたい場合は別の書き方をする必要がある。
以下がサンプルである。

{
    "from": {
        "key_code": "i",
        "modifiers": {
            "mandatory": "command"
        }
    },
    "to": [
        {
            "key_code": "i"
        },
        {
            "key_code": "m"
        },
        {
            "key_code": "p"
        },
        {
            "key_code": "o"
        },
        {
            "key_code": "r"
        },
        {
            "key_code": "t"
        },
        {
            "key_code": "spacebar"
        }
    ]
}

"from"以下を見てほしい。

"modifiers": {
    "mandatory": "command"
}

となっている。これはcommandを押しながら何かのキー(ここではi)を押すという操作を意味する。
この指定では、command + iを押すと"import "と入力される。
複数の文字を一つの操作で入力したい場合は、"to"の"keycode"の一つ一つを{}でくくる必要があるようだ。

まとめ

特殊なキー配列にする人をする人を見たことないのでやっている人がどのくらいいるのかは分からないが、
混乱しないようならこれからも色々な入力操作を試していきたい。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?