概要
この記事では、Karabiner-Elementsを使用して複数のキーペアを入れ替える設定方法を解説します。具体的には以下のキーを入れ替えます:
-
;(セミコロン)と:(コロン) -
"(ダブルクォート)と'(シングルクォート) -
=(イコール)と+(プラス)
設定ファイル
以下の設定をKarabiner-Elementsのcomplex_modificationsに追加します:
{
"description": "Swap multiple key pairs: ; <-> :, \" <-> ', = <-> +",
"manipulators": [
{
"description": "; to :",
"from": {
"key_code": "semicolon",
"modifiers": { "optional": ["caps_lock", "fn", "option"] }
},
"to": [
{
"key_code": "semicolon",
"modifiers": ["shift"]
}
],
"type": "basic"
},
{
"description": "Shift+; (originally :) to ;",
"from": {
"key_code": "semicolon",
"modifiers": {
"mandatory": ["shift"],
"optional": ["caps_lock", "fn", "option"]
}
},
"to": [{ "key_code": "semicolon" }],
"type": "basic"
},
{
"description": "' to \"",
"from": {
"key_code": "quote",
"modifiers": { "optional": ["caps_lock", "fn", "option"] }
},
"to": [
{
"key_code": "quote",
"modifiers": ["shift"]
}
],
"type": "basic"
},
{
"description": "Shift+' (originally \") to '",
"from": {
"key_code": "quote",
"modifiers": {
"mandatory": ["shift"],
"optional": ["caps_lock", "fn", "option"]
}
},
"to": [{ "key_code": "quote" }],
"type": "basic"
},
{
"description": "= to +",
"from": {
"key_code": "equal_sign",
"modifiers": { "optional": ["caps_lock", "fn", "option"] }
},
"to": [
{
"key_code": "equal_sign",
"modifiers": ["shift"]
}
],
"type": "basic"
},
{
"description": "Shift+= (originally +) to =",
"from": {
"key_code": "equal_sign",
"modifiers": {
"mandatory": ["shift"],
"optional": ["caps_lock", "fn", "option"]
}
},
"to": [{ "key_code": "equal_sign" }],
"type": "basic"
}
]
}
設定の詳細説明
基本構造
各キーペアの入れ替えは2つのmanipulatorで構成されます:
| 設定項目 | 説明 |
|---|---|
description |
設定の説明文 |
from |
入力されるキー |
to |
出力されるキー |
type |
設定タイプ(基本的に"basic") |
キーコード対応表
| 物理キー | key_code | 通常出力 | Shift+出力 |
|---|---|---|---|
; |
semicolon |
; |
: |
' |
quote |
' |
" |
= |
equal_sign |
= |
+ |
modifiers設定
"modifiers": { "optional": ["caps_lock", "fn", "option"] }
この設定により、CapsLock、Fn、Optionキーが同時に押されていても設定が適用されます。
"modifiers": {
"mandatory": ["shift"],
"optional": ["caps_lock", "fn", "option"]
}
Shiftキーが必須で、他のmodifierキーはオプションという意味です。
実際の適用手順
1. Karabiner-Elementsを起動
アプリケーションからKarabiner-Elementsを開きます。
2. Complex Modificationsタブを選択
画面上部の「Complex Modifications」タブをクリックします。
3. Add ruleボタンをクリック
「Add rule」ボタンを押して新しいルールを追加します。
4. Import more rules from the Internetを選択
「Import more rules from the Internet」を選択します。
5. カスタム設定をインポート
上記のJSON設定をファイルとして保存し、インポートするか、手動で追加します。
動作確認
設定が正しく適用されているか確認してください:
| 入力 | 期待される出力 |
|---|---|
;キーを押す |
: が入力される |
Shift + ;を押す |
; が入力される |
'キーを押す |
" が入力される |
Shift + 'を押す |
' が入力される |
=キーを押す |
+ が入力される |
Shift + =を押す |
= が入力される |
カスタマイズ例
他のキーペアも追加したい場合
例えば、[と{を入れ替えたい場合:
{
"description": "[ to {",
"from": {
"key_code": "open_bracket",
"modifiers": { "optional": ["caps_lock", "fn", "option"] }
},
"to": [
{
"key_code": "open_bracket",
"modifiers": ["shift"]
}
],
"type": "basic"
},
{
"description": "Shift+[ (originally {) to [",
"from": {
"key_code": "open_bracket",
"modifiers": {
"mandatory": ["shift"],
"optional": ["caps_lock", "fn", "option"]
}
},
"to": [{ "key_code": "open_bracket" }],
"type": "basic"
}
この設定パターンを参考に、必要に応じて他のキーペアも追加できます。