「コンソールでの特別なキーボードキー」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(ページの作成:「Category:キーボード en:Extra keyboard keys in console {{Related articles start}} {{Related|特別なキーボードキー}} {{Related|Xorg での特別なキ...」)
 
(同期)
(同じ利用者による、間の1版が非表示)
7行目: 7行目:
 
{{Related articles end}}
 
{{Related articles end}}
   
  +
コンソールを使用するときは、ホットキーを使って特殊な文字を打ち込むことができます。さらに、一連の文字列やエスケープシーケンスを入力することも可能です。従って、コマンドと改行のエスケープ文字からなる文字列を連続して打ち込んだ場合、コマンドが実行されます。
When using the console, you can use hotkeys to print a specific character. Moreover we can also print a sequence of characters and some escape sequences. Thus, if we print the sequence of characters constituting a command and afterwards an escape character for a new line, that command will be executed!
 
   
  +
これを行うには[[KEYMAP|キーマップ]]を編集するのが一つの方法ですが、キーマップは要注意のファイルであり、キーマップが入っているパッケージが更新されると書きなおされてしまいます。そのためファイルの編集は推奨されません。個人的なキーマップと既存のキーマップを統合するほうが良いでしょう。{{ic|loadkeys}} ユーティリティを使います。
One method of doing this is editing [[KEYMAP|the keymap]]. However, the keymap is a sensitive file, and since it will be rewritten anytime the package it belongs to is updated, editing this file is discouraged. It is better to integrate the existing keymap with a personal keymap. The {{ic|loadkeys}} utility can do this.
 
   
 
== カスタムキーマップの作成 ==
 
== カスタムキーマップの作成 ==
   
  +
まず、キーマップファイルを作成してください。キーマップファイルはどこに置いてもかまいませんが、{{ic|/usr/local}} のディレクトリ階層を真似るという方法があります:
First, create a keymap file. This keymap file can be anywhere, but one method is to mimic the directory hierarchy in {{ic|/usr/local}}:
 
   
 
# mkdir -p /usr/local/share/kbd/keymaps
 
# mkdir -p /usr/local/share/kbd/keymaps
 
# vim /usr/local/share/kbd/keymaps/personal.map
 
# vim /usr/local/share/kbd/keymaps/personal.map
   
  +
自分用のキーマップを使って、デフォルトのキーマップで既に定義済みのキーの挙動を再定義することも可能です。{{ic|loadkeys}} でキーマップをロードしたときに、新しいディレクティブでキーマップが衝突する場合、既存のキーマップのディレクティブが置き換わります。自分用のキーマップに定義する必要があるのは変更したいキーだけで十分です。
As a side note, it is worth noting that such a personal keymap is useful also to redefine the behaviour of keys already treated by the default keymap: when loaded with {{ic|loadkeys}}, the directives in the default keymap will be replaced when they conflict with the new directives and conserved otherwise. This way, only changes to the keymap must be specified in the personal keymap.
 
   
{{Tip|You can also edit an existing keymap located in the {{ic|/usr/share/kbd/keymaps/}} directory tree. Keymaps have an ''.map.gz'' extension, for example {{ic|us.map.gz}} is an American keymap. Just copy the keymap to {{ic|/usr/local/share/kbd/keymaps/personal.map.gz}} and ''gunzip'' it.}}
+
{{Tip|{{ic|/usr/share/kbd/keymaps/}} ディレクトリツリーに存在する既存のキーマップを編集することもできます。キーマップの拡張子は ''.map.gz'' となっており、例えばアメリカ英語のキーマップは {{ic|us.map.gz}} です。キーマップを {{ic|/usr/local/share/kbd/keymaps/personal.map.gz}} にコピーして ''gunzip'' を実行してください。}}
   
 
== ディレクティブの追加 ==
 
== ディレクティブの追加 ==
   
  +
自分用キーマップには2種類のディレクティブが必要です。まず、既存のキーマップにあるフォーマットにマッチするキーコードディレクティブです。キーコードディレクティブはキーコードをキーシムと関連付けます。キーシムはキーボードのアクションを表します。文字コードや文字シーケンスの出力、コンソールやキーマップの切り替え、マシンの起動などのアクションが定義できます。完全なリストは以下のコマンドで確認できます:
Two kinds of directives are required in this personal keymap. First of all, the keycode directives, which matches the format seen in the default keymaps. These directives associate a keycode with a keysym. Keysyms represent keyboard actions. The actions available include outputting character codes or character sequences, switching consoles or keymaps, booting the machine, and many other actions. A complete list can be obtained with
 
   
 
# dumpkeys -l
 
# dumpkeys -l
   
  +
ほとんどのキーシムはすぐにわかります。例えば、キー 112 で 'e' が出るように設定する場合、ディレクティブは以下のようになります:
Most keysyms are them are intuitive. For example, to set key 112 to output an 'e', the directive will be:
 
   
 
keycode 112 = e
 
keycode 112 = e
   
  +
キー 112 でユーロ記号が出力されるようにするには、以下のディレクティブを使用:
To set key 112 to output a euro symbol, the directive will be:
 
   
 
keycode 112 = euro
 
keycode 112 = euro
   
  +
一部のキーシムはキーボードのアクションとすぐにはつながりません。特に、大文字の F と1〜3桁の数字からなるキーシム (F1-F246) で数字が30以上のものは自由に使うことができ、一連の文字列やアクションを出力するホットキーとして有用です:
Some keysym are not immediately connected to a keyboard actions. In particular, the keysyms prefixed by a capital F and one to three digits (F1-F246) constituting a number greater than 30 are always free. This is useful directing a hotkey to output a sequence of characters and other actions:
 
   
 
keycode 112 = F70
 
keycode 112 = F70
   
  +
上記のように定義してから F70 で特定の文字列を出力するように設定できます:
Then, F70 can be bound to output a specific string:
 
   
 
string F70 = "Hello"
 
string F70 = "Hello"
   
  +
キー 112 が押されると、F70 の中身が出力されます。ターミナルで出力したコマンドを実行するには、コマンド文字列の末尾に改行のエスケープ文字を追加してください。例えば、ハイバネートを実行したい場合、以下のキーシムを追加します:
When key 112 is pressed, it will output the contents of F70. In order to execute a printed command in a terminal, a newline escape character must be appended to the end of the command string. For example, to enter a system into hibernation, the following keymap is added:
 
   
 
string F70 = "sudo /usr/sbin/hibernate\n"
 
string F70 = "sudo /usr/sbin/hibernate\n"
50行目: 50行目:
 
=== その他の例 ===
 
=== その他の例 ===
   
* To make the Right Alt key same as Left Alt key (for Emacs), use the following line in your keymap. It will include the file {{ic|/usr/share/kbd/keymaps/i386/include/linux-with-two-alt-keys.inc}}, check it for details.
+
* ([[Emacs]] 用に) Alt キーを左 Alt キーと同じにしたい場合、キーマップに以下の行を書いてください。{{ic|/usr/share/kbd/keymaps/i386/include/linux-with-two-alt-keys.inc}} ファイルが読み込まれます:
   
 
include "linux-with-two-alt-keys"
 
include "linux-with-two-alt-keys"
   
  +
* ([[Vim]] 用に) CapsLock と Escape を交換するには、以下のキーコードをリマップしてください:
* To swap CapsLock with Escape (for Vim), remap the respective keycodes:
 
   
 
keycode 1 = Caps_Lock
 
keycode 1 = Caps_Lock
 
keycode 58 = Escape
 
keycode 58 = Escape
   
  +
* CapsLock を Control キーとして使うには、以下のキーコードをリマップします:
* To make CapsLock another Control key, remap the respective keycode:
 
   
 
keycode 58 = Control
 
keycode 58 = Control
   
  +
* CapsLock を左 Control キーと交換するには、それぞれのキーマップを再マッピングしてください:
* To swap CapsLock with Left Control key, remap the respective keycodes:
 
   
 
keycode 29 = Caps_Lock
 
keycode 29 = Caps_Lock
70行目: 70行目:
 
== 変更の保存 ==
 
== 変更の保存 ==
   
  +
作成したキーマップを使うには ''loadkeys'' でロードする必要があります:
In order to make use of the personal keymap, it must be loaded with ''loadkeys'':
 
   
 
$ loadkeys /usr/local/share/kbd/keymaps/personal.map
 
$ loadkeys /usr/local/share/kbd/keymaps/personal.map
   
  +
ただし上記のコマンドでロードされたキーマップは現在のセッションにおいてのみしか有効になりません。起動時にキーマップをロードするには、[[コンソールでのキーボード設定#永続的な設定|/etc/vconsole.conf]] の {{ic|KEYMAP}} 変数にファイルのフルパスを指定してください。{{Pkg|kbd}} に含まれている公式キーマップと同じようにファイルを gzip で圧縮する必要はありません。
However this keymap only active for the current session. In order to load the keymap at boot, specify the full path to the file in {{ic|KEYMAP}} variable in {{ic|/etc/vconsole.conf}}. The file does not have to be gzipped as the official keymaps provided by {{Pkg|kbd}}.
 

2017年2月25日 (土) 23:45時点における版

関連記事

コンソールを使用するときは、ホットキーを使って特殊な文字を打ち込むことができます。さらに、一連の文字列やエスケープシーケンスを入力することも可能です。従って、コマンドと改行のエスケープ文字からなる文字列を連続して打ち込んだ場合、コマンドが実行されます。

これを行うにはキーマップを編集するのが一つの方法ですが、キーマップは要注意のファイルであり、キーマップが入っているパッケージが更新されると書きなおされてしまいます。そのためファイルの編集は推奨されません。個人的なキーマップと既存のキーマップを統合するほうが良いでしょう。loadkeys ユーティリティを使います。

カスタムキーマップの作成

まず、キーマップファイルを作成してください。キーマップファイルはどこに置いてもかまいませんが、/usr/local のディレクトリ階層を真似るという方法があります:

# mkdir -p /usr/local/share/kbd/keymaps
# vim /usr/local/share/kbd/keymaps/personal.map

自分用のキーマップを使って、デフォルトのキーマップで既に定義済みのキーの挙動を再定義することも可能です。loadkeys でキーマップをロードしたときに、新しいディレクティブでキーマップが衝突する場合、既存のキーマップのディレクティブが置き換わります。自分用のキーマップに定義する必要があるのは変更したいキーだけで十分です。

ヒント: /usr/share/kbd/keymaps/ ディレクトリツリーに存在する既存のキーマップを編集することもできます。キーマップの拡張子は .map.gz となっており、例えばアメリカ英語のキーマップは us.map.gz です。キーマップを /usr/local/share/kbd/keymaps/personal.map.gz にコピーして gunzip を実行してください。

ディレクティブの追加

自分用キーマップには2種類のディレクティブが必要です。まず、既存のキーマップにあるフォーマットにマッチするキーコードディレクティブです。キーコードディレクティブはキーコードをキーシムと関連付けます。キーシムはキーボードのアクションを表します。文字コードや文字シーケンスの出力、コンソールやキーマップの切り替え、マシンの起動などのアクションが定義できます。完全なリストは以下のコマンドで確認できます:

# dumpkeys -l

ほとんどのキーシムはすぐにわかります。例えば、キー 112 で 'e' が出るように設定する場合、ディレクティブは以下のようになります:

keycode 112  = e

キー 112 でユーロ記号が出力されるようにするには、以下のディレクティブを使用:

keycode 112 = euro

一部のキーシムはキーボードのアクションとすぐにはつながりません。特に、大文字の F と1〜3桁の数字からなるキーシム (F1-F246) で数字が30以上のものは自由に使うことができ、一連の文字列やアクションを出力するホットキーとして有用です:

keycode 112 = F70

上記のように定義してから F70 で特定の文字列を出力するように設定できます:

string F70 = "Hello"

キー 112 が押されると、F70 の中身が出力されます。ターミナルで出力したコマンドを実行するには、コマンド文字列の末尾に改行のエスケープ文字を追加してください。例えば、ハイバネートを実行したい場合、以下のキーシムを追加します:

string F70 = "sudo /usr/sbin/hibernate\n"

その他の例

  • (Emacs 用に) 右 Alt キーを左 Alt キーと同じにしたい場合、キーマップに以下の行を書いてください。/usr/share/kbd/keymaps/i386/include/linux-with-two-alt-keys.inc ファイルが読み込まれます:
include "linux-with-two-alt-keys"
  • (Vim 用に) CapsLock と Escape を交換するには、以下のキーコードをリマップしてください:
keycode 1 = Caps_Lock
keycode 58 = Escape
  • CapsLock を Control キーとして使うには、以下のキーコードをリマップします:
keycode 58 = Control
  • CapsLock を左 Control キーと交換するには、それぞれのキーマップを再マッピングしてください:
keycode 29 = Caps_Lock
keycode 58 = Control

変更の保存

作成したキーマップを使うには loadkeys でロードする必要があります:

$ loadkeys /usr/local/share/kbd/keymaps/personal.map

ただし上記のコマンドでロードされたキーマップは現在のセッションにおいてのみしか有効になりません。起動時にキーマップをロードするには、/etc/vconsole.confKEYMAP 変数にファイルのフルパスを指定してください。kbd に含まれている公式キーマップと同じようにファイルを gzip で圧縮する必要はありません。