「特別なキーボードキー」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
8行目: 8行目:
 
{{Related|Xorg でのキーボード設定}}
 
{{Related|Xorg でのキーボード設定}}
 
{{Related|コンソールでのキーボード設定}}
 
{{Related|コンソールでのキーボード設定}}
{{Related3|Map scancodes to keycodes|スキャンコードをキーコードにマップ}}
+
{{Related|スキャンコードをキーコードにマップ}}
 
{{Related|Xmodmap}}
 
{{Related|Xmodmap}}
 
{{Related articles end}}
 
{{Related articles end}}
36行目: 36行目:
   
 
コマンドを実行した後にキーボードのキーを押してみて下さい。''スキャンコード''が出力されます。
 
コマンドを実行した後にキーボードのキーを押してみて下さい。''スキャンコード''が出力されます。
  +
  +
==== evtest を使う ====
  +
  +
USB キーボードの場合、''showkey'' ではなく {{Pkg|evtest}} パッケージに入っている ''evtest'' を使う必要があります [https://ask.fedoraproject.org/en/question/46201/how-to-map-scancodes-to-keycodes/]:
  +
  +
# evtest /dev/input/event12
  +
...
  +
Event: time 1434666536.001123, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70053
  +
Event: time 1434666536.001123, type 1 (EV_KEY), code 69 (KEY_NUMLOCK), value 0
  +
Event: time 1434666536.001123, -------------- EV_SYN ------------
  +
  +
{{ic|MSC_SCAN}} の "value" フィールドを使って下さい。上記の例の場合、NumLock のスキャンコードは 70053 でキーコードは 69 です。
   
 
==== dmesg を使う ====
 
==== dmesg を使う ====
41行目: 53行目:
 
{{Note|This method does not provide ''scancodes'' for all keys, it only identifies the unknown keys.}}
 
{{Note|This method does not provide ''scancodes'' for all keys, it only identifies the unknown keys.}}
   
  +
調べたいキーを押して {{ic|dmesg}} コマンドの出力を確認することでキーの''スキャンコード''を取得できます。例えば、以下のように表示された場合:
You can get the ''scancode'' of a key by pressing the desired key and looking the output of {{ic|dmesg}} command. For example, if you get:
 
   
 
Unknown key pressed (translated set 2, code 0xa0 on isa0060/serio0
 
Unknown key pressed (translated set 2, code 0xa0 on isa0060/serio0
   
then the ''scancode'' you need is {{ic|0xa0}}.
+
必要な''スキャンコード'' {{ic|0xa0}} です。
   
 
=== キーコード ===
 
=== キーコード ===
104行目: 116行目:
 
# echo 1 > /sys/devices/platform/asus_laptop/ls_switch
 
# echo 1 > /sys/devices/platform/asus_laptop/ls_switch
   
To have it run on boot create a [[Systemd#Temporary_files|Systemd tmpfile]]:
+
To have it run on boot create a [[Systemd#一時ファイル|Systemd tmpfile]]:
 
{{hc|/etc/tmpfiles.d/local.conf|
 
{{hc|/etc/tmpfiles.d/local.conf|
 
w /sys/devices/platform/asus_laptop/ls_switch - - - - 1
 
w /sys/devices/platform/asus_laptop/ls_switch - - - - 1
113行目: 125行目:
 
=== Asus N56VJ ===
 
=== Asus N56VJ ===
   
  +
特殊キーが動作しない場合、次のコマンドで {{ic|asus-nb-wmi}} カーネルモジュールをロードしてみてください:
if most of your special keys don't work, try loading the asus-nb-wmi kernel module with
 
 
# modprobe asus-nb-wmi
 
# modprobe asus-nb-wmi
   
  +
それから xev をもう一度確認してください。{{ic|1=acpi_osi="!Windows 2012"}} ブートオプションを使っている場合、xev で変な結果が表示されることがあるので、使わないようにしてください。モジュールをロードすることで問題が解決する場合、[[カーネルモジュール]]の記事に書かれているようにして、起動時にモジュールをロードするようにしてください。
then check xev again. if you combine this with the acpi_osi="!Windows 2012" boot option, you may get weird results in xev, so try not using it. If this did fix things, make sure to make the module load at boot with methods described [[Kernel modules|here]]
 
   
 
== 参照 ==
 
== 参照 ==
   
* [http://keytouch.sourceforge.net/howto_keyboard/node4.html How to retrieve scancodes] by Marvin Raaijmakers
 
 
* [http://wiki.linuxquestions.org/wiki/Configuring_keyboards#Enabling_Keyboard_Multimedia_Keys Enabling Keyboard Multimedia Keys] - guide on LinuxQuestions wiki
 
* [http://wiki.linuxquestions.org/wiki/Configuring_keyboards#Enabling_Keyboard_Multimedia_Keys Enabling Keyboard Multimedia Keys] - guide on LinuxQuestions wiki
 
* [http://www.gentoo-wiki.info/HOWTO_Use_Multimedia_Keys Multimedia Keys] on [http://www.gentoo-wiki.info/ Gentoo Wiki Archives]
 
* [http://www.gentoo-wiki.info/HOWTO_Use_Multimedia_Keys Multimedia Keys] on [http://www.gentoo-wiki.info/ Gentoo Wiki Archives]

2015年8月7日 (金) 23:27時点における版

関連記事

多くのキーボードには何らかの特別なキーが付いており (ホットキーマルチメディアキーとも呼ばれる)、アプリケーションを起動したり特殊な文字を打ち込むのに使われます (標準的なキーマップには含まれていない機能)。udev は様々なキーボードに関する巨大なデータベースを持っているため、基本的なキーボードは何も設定せずとも問題なく動作します。最近発売されたばかり、または非常にレアなハードウェアを使っている場合に、マッピングを手動で調整する必要がでてきます。

キーマッピングを変更する前に、そのキーがシステムでどう認識されているのか知らなくてはなりません。いくつかの段階に分かれています:

  • スキャンコードは最下層のキー識別番号で、キーボードがコンピュータに送信する値になります。
  • キーコードは2番目のキー識別子で、キーコードは機能に対応しています。
  • キーシムは3番目のキー識別子で、シンボルに対応しています。キーシムは Shift キーなどの修飾キーが押されているかどうかによって変わります。

スキャンコードキーコードにマップされており、キーコードは使用しているキーボードレイアウトにあわせてキーシムにマップされています。ほとんどのキーにはキーコードが割り当てられているはずです。そして、キーコードがなくともスキャンコードは存在するでしょう。スキャンコードが存在しないキーはカーネルによって認識されていません。ゲーミングキーボードに追加されているキーなどでスキャンコードがないことがあります。

Xorg では、特定のキーシム (例: XF86AudioPlay, XF86AudioRaiseVolume など) をアクションにマップすることができます (例: アプリケーションの起動)。詳しくは Xorg での特別なキーボードキー#キーシムをアクションにマップ を見て下さい。

Linux コンソールでは、特定のキーシム (例: F1 から F246) を特定のアクションにマップすることができます (例: 他のコンソールへの切り替えや特定の文字列の打ち込みなど)。詳しくはコンソールでの特別なキーボードキーを見て下さい。

キーコードの確認

スキャンコード

showkey を使う

スキャンコードを取得するときは showkey ユーティリティを使うのが一般的です。showkey はキーが押されるまで待機し、10秒たってもキーが押されなかった場合、終了します。showkey を使用するには仮想端末上で実行させる必要があり、グラフィカル環境やネットワーク接続を介してログインした場合は使用できません。次のコマンドを実行してください:

# showkey --scancodes

コマンドを実行した後にキーボードのキーを押してみて下さい。スキャンコードが出力されます。

evtest を使う

USB キーボードの場合、showkey ではなく evtest パッケージに入っている evtest を使う必要があります [1]:

# evtest /dev/input/event12
...
Event: time 1434666536.001123, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70053
Event: time 1434666536.001123, type 1 (EV_KEY), code 69 (KEY_NUMLOCK), value 0
Event: time 1434666536.001123, -------------- EV_SYN ------------

MSC_SCAN の "value" フィールドを使って下さい。上記の例の場合、NumLock のスキャンコードは 70053 でキーコードは 69 です。

dmesg を使う

ノート: This method does not provide scancodes for all keys, it only identifies the unknown keys.

調べたいキーを押して dmesg コマンドの出力を確認することでキーのスキャンコードを取得できます。例えば、以下のように表示された場合:

Unknown key pressed (translated set 2, code 0xa0 on isa0060/serio0

必要なスキャンコード0xa0 です。

キーコード

警告: Note that the keycodes are different for Linux console and Xorg. Use the appropriate tool to determine the desired value.

コンソール

The keycodes for virtual console are reported by the showkey utility. showkey waits for a key to be pressed and if none is during 10 seconds it quits, which is the only way to exit the program. To execute showkey you need to be in a virtual console, not in a graphical environment. Run the following command

# showkey --keycodes

and try to push keyboard keys, you should see keycodes being printed to the output.

Xorg

Xorg によって使用されるキーコードxev という名前のユーティリティで判別できます (xorg-xev パッケージに入っています)。もちろん xev を使用するには、コンソールではなくグラフィカル環境から実行する必要があります。

次のコマンドで xev を起動して肝心の部分だけを表示できます:

$ xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'

出力例:

38 a
27 r
54 c
43 h
153 NoSymbol
144 NoSymbol

In the example the keys a, r, c, h and two other multimedia keys were pressed. The former four keys with keycodes 38, 27, 54 and 43 are properly mapped, while the multimedia keys with keycodes 153 and 144 are not. The NoSymbol indicates that no keysyms are assigned to those keys.

If you press a key and nothing appears in the terminal, it means that either the key does not have a scancode, the scancode is not mapped to a keycode, or some other process is capturing the keypress. If you suspect that a process listening to X server is capturing the keypress, you can try running xev from a clean X session:

$ xinit /usr/bin/xterm -- :1

スキャンコードをキーコードにマッピング

次の記事を参照してください: スキャンコードをキーコードにマップ

キーコードをキーシムにマッピング

コンソール

次の記事を参照してください: コンソールでの特別なキーボードキー

Xorg

次の記事を参照してください: xmodmap

ノートパソコン

Asus M シリーズ

In order to have control over the light sensor and the multimedia keys on your Asus machine, you should use the following command:

# echo 1 > /sys/devices/platform/asus_laptop/ls_switch

To have it run on boot create a Systemd tmpfile:

/etc/tmpfiles.d/local.conf
w /sys/devices/platform/asus_laptop/ls_switch - - - - 1
ノート: This may work also for other Asus notebook models.

Asus N56VJ

特殊キーが動作しない場合、次のコマンドで asus-nb-wmi カーネルモジュールをロードしてみてください:

# modprobe asus-nb-wmi

それから xev をもう一度確認してください。acpi_osi="!Windows 2012" ブートオプションを使っている場合、xev で変な結果が表示されることがあるので、使わないようにしてください。モジュールをロードすることで問題が解決する場合、カーネルモジュールの記事に書かれているようにして、起動時にモジュールをロードするようにしてください。

参照