https://wiki.archlinux.org/api.php?action=feedcontributions&user=Aleksclark&feedformat=atomArchWiki - User contributions [en]2024-03-28T19:16:54ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Keyboard_input&diff=261943Keyboard input2013-06-09T03:47:55Z<p>Aleksclark: /* Laptops */</p>
<hr />
<div>[[Category:Keyboards]]<br />
[[zh-CN:Extra Keyboard Keys]]<br />
{{Article summary start}}<br />
{{Article summary text|A general overview of how to assign actions to extra keyboard keys.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|Xmodmap}}<br />
{{Article summary wiki|Extra Keyboard Keys in Xorg}}<br />
{{Article summary wiki|Extra Keyboard Keys in Console}}<br />
{{Article summary end}}<br />
Many keyboards include some "special keys" (also called hotkeys, such as HP Quickplay), which are supposed to execute an application or print special characters (not included in the standard national keymaps). The lack of specification for these extra keys makes it impossible for the kernel to know what to do with them and that is why we need to map the keys to actions. There are 3 ways of doing that:<br />
* The most portable way using low level tools, such as [[acpid]]. Not all keys are supported, but configuration in uniform way is possible for keyboard keys, power adapter connection and even headphone jack (un)plugging events.<br />
* The universal way using [[Xorg]] utilities (and eventually your desktop environment tools)<br />
* The quicker way using a third-party program to do everything in GUI, such as the Gnome Control Center or [[Keytouch]]<br />
<br />
Before starting you need to learn some vocabulary.<br />
<br />
A '''scancode''' is the lowest identification number for a key. If a key does not have a scancode then we cannot do anything because it means that the kernel does not see it.<br />
<br />
A '''keycode''' is the second level of identification for a key, a keycode corresponds to a function.<br />
<br />
A '''symbol''' is the third level of identification for a key, it is the way Xorg refers to keys.<br />
<br />
== Step 1: Check for keycodes ==<br />
<br />
Most of your keys should already have a keycode, or at least a scancode. Keys without a scancode are not recognized by the kernel.<br />
<br />
=== Using xev ===<br />
<br />
Use the graphical X program "xev" (without having to switch to a console environment).<br />
[[pacman|Install]] {{Pkg|xorg-xev}}.<br />
<br />
With the following line you can start xev and directly grep the important parts:<br />
<br />
$ xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'<br />
<br />
In the example below I pressed the "a", "r", "c" and "h" keys and two of the media keys on my Dell keyboard. This gives me the following output:<br />
38 a<br />
27 r<br />
54 c<br />
43 h<br />
153 NoSymbol<br />
144 NoSymbol<br />
This means that the "a", "r", "c" and "h" keys have the keycodes 38, 27, 54 and 43 and are properly bound while the media keys with the keycodes 153 and 144 have no function yet, which is indicated by "NoSymbol". If you press a key and nothing appears in the terminal, this means that the kernel does not see that key or that it is not mapped.<br />
<br />
=== Using showkey ===<br />
<br />
The universal way to know if a key has a keycode is to use the kernel {{ic|showkey}} program. showkey waits for a key to be pressed and if none is during 10 seconds it quits, note that this is the only way to exit the program. To execute showkey you need to be in a real console, it means not in a graphical environment so switch using {{Keypress|Ctrl+Alt+F2}} ({{Keypress|Ctrl+Alt+F1}} returns to the graphical environment).<br />
# showkey<br />
and try to push your hotkeys. If a keycode appears the key is mapped, if not it can mean either that the kernel does not see the key or that the key is not mapped.<br />
<br />
=== 2.6 kernels ===<br />
<br />
According to the keymap man page:<br />
<br />
{{Note|In 2.6 kernels raw mode, or scancode mode, is not very raw at all. Scan codes are first translated to key codes, and when scancodes are desired the key codes are translated back...there is no guarantee at all that the final result corresponds to what the keyboard hardware did send. To change behavior back to the old raw mode, add the parameter {{ic|1=atkbd.softraw=0}} to your kernel while booting. This can be removed for later boots when the old raw functionality is not required.}}<br />
<br />
This is relevant if the keymaps obtained from showkey and the ones set by [[setkeycodes]] differ from the ones obtained by xev in X. Keep this in mind when translating the keymaps into keysyms using xmodmap (See [[Extra Keyboard Keys in Xorg]]).<br />
<br />
If all your keys have a keycode you can go directly to the second step. If not keep reading below:<br />
<br />
=== Check for scancodes ===<br />
<br />
If a key does not have a keycode you can know if it has a scancode by looking at the kernel log using the dmesg command:<br />
$ dmesg|tail -5<br />
If when you press the key something like that appears:<br />
atkbd.c: Unknown key pressed (translated set 2, code 0xf1 on isa0060/serio0).<br />
atkbd.c: Use 'setkeycodes e071 <keycode>' to make it known.<br />
then your key has a scancode which can be mapped to a keycode. See [[Map scancodes to keycodes]].<br />
<br />
If nothing new appears in dmesg then your key does not have a scancode, which means that it is not recognized by the kernel and cannot be used.<br />
<br />
== Step 2: map keycodes ==<br />
<br />
=== In console ===<br />
<br />
''See the dedicated article: [[Extra Keyboard Keys in Console]].''<br />
<br />
When in console, hotkeys can be used to print sequences of characters, including escape sequences. Thus, printing the sequence of characters constituting a command followed by the escape sequence for a new will execute the command.<br />
<br />
=== In Xorg ===<br />
<br />
''See the dedicated article: [[Extra Keyboard Keys in Xorg]].''<br />
<br />
== Laptops ==<br />
<br />
=== Asus M series ===<br />
<br />
In order to have control over the light sensor and the multimedia keys on your Asus machine, you should use the following command:<br />
<br />
# echo 0 > /sys/devices/platform/asus-laptop<br />
<br />
To have it run on boot create a [[Systemd#Temporary_files|Systemd tmpfile]]:<br />
{{hc|/etc/tmpfiles.d/local.conf|<br />
w /sys/devices/platform/asus-laptop/ls_switch - - - - 0<br />
}}<br />
<br />
Note that this may work for other Asus notebook models.<br />
''See the detailed article: [[lineak]].''<br />
<br />
=== Asus N56VJ (or possibly others) ===<br />
<br />
if most of your special keys don't work, try loading the asus-nb-wmi kernel module with<br />
# modprobe asus-nb-wmi<br />
<br />
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]]</div>Aleksclarkhttps://wiki.archlinux.org/index.php?title=Keyboard_input&diff=259433Keyboard input2013-05-29T01:36:18Z<p>Aleksclark: console switch keys have changed, ctrl+alt+f1 now brings up xorg, ctrl+alt+f2 will give you a console</p>
<hr />
<div>[[Category:Keyboards]]<br />
[[zh-CN:Extra Keyboard Keys]]<br />
{{Article summary start}}<br />
{{Article summary text|A general overview of how to assign actions to extra keyboard keys.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|Xmodmap}}<br />
{{Article summary wiki|Extra Keyboard Keys in Xorg}}<br />
{{Article summary wiki|Extra Keyboard Keys in Console}}<br />
{{Article summary end}}<br />
<br />
Many keyboards include some "special keys" (also called hotkeys, such as HP Quickplay), which are supposed to execute an application or print special characters (not included in the standard national keymaps). The lack of specification for these extra keys makes it impossible for the kernel to know what to do with them and that is why we need to map the keys to actions. There are 3 ways of doing that:<br />
*The most portable way using low level tools, such as [[acpid]]. Not all keys are supported, but configuration in uniform way is possible for keyboard keys, power adapter connection and even headphone jack (un)plugging events.<br />
*The universal way using [[Xorg]] utilities (and eventually your desktop environment tools)<br />
*The quicker way using a third-party program to do everything in GUI, such as the Gnome Control Center or [[Keytouch]]<br />
<br />
Before starting you need to learn some vocabulary:<br />
<br />
A '''scancode''' is the lowest identification number for a key. If a key does not have a scancode then we cannot do anything because it means that the kernel does not see it.<br />
<br />
A '''keycode''' is the second level of identification for a key, a keycode corresponds to a function.<br />
<br />
A '''symbol''' is the third level of identification for a key, it is the way Xorg refers to keys.<br />
<br />
==Step 1: Check for keycodes==<br />
Most of your keys should already have a keycode, or at least a scancode. Keys without a scancode are not recognized by the kernel.<br />
<br />
===Using xev===<br />
Use the graphical X program "xev" (without having to switch to a console environment).<br />
Install the xev program:<br />
<br />
{{bc|# pacman -S xorg-xev}}<br />
<br />
With the following line you can start xev and directly grep the important parts:<br />
<br />
{{bc|<nowiki>$ xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'</nowiki>}}<br />
<br />
In the example below I pressed the "a", "r", "c" and "h" keys and two of the media keys on my Dell keyboard. This gives me the following output:<br />
38 a<br />
27 r<br />
54 c<br />
43 h<br />
153 NoSymbol<br />
144 NoSymbol<br />
This means that the "a", "r", "c" and "h" keys have the keycodes 38, 27, 54 and 43 and are properly bound while the media keys with the keycodes 153 and 144 have no function yet, which is indicated by "NoSymbol". If you press a key and nothing appears in the terminal, this means that the kernel does not see that key or that it is not mapped.<br />
<br />
=== Using showkey ===<br />
The universal way to know if a key has a keycode is to use the kernel {{ic|showkey}} program. showkey waits for a key to be pressed and if none is during 10 seconds it quits, note that this is the only way to exit the program. To execute showkey you need to be in a real console, it means not in a graphical environment so '''switch using Ctrl+Alt+F2''' (Ctrl+Alt+F1 returns to the graphical environment).<br />
{{bc|# showkey}}<br />
and try to push your hotkeys. If a keycode appears the key is mapped, if not it can mean either that the kernel does not see the key or that the key is not mapped.<br />
<br />
=== 2.6 kernels ===<br />
According to the keymap man page:<br />
<br />
{{Note|In 2.6 kernels raw mode, or scancode mode, is not very raw at all. Scan codes are first translated to key codes, and when scancodes are desired the key codes are translated back...there is no guarantee at all that the final result corresponds to what the keyboard hardware did send. To change behavior back to the old raw mode, add the parameter {{ic|1=atkbd.softraw=0}} to your kernel while booting. This can be removed for later boots when the old raw functionality is not required.}}<br />
<br />
This is relevant if the keymaps obtained from showkey and the ones set by [[setkeycodes]] differ from the ones obtained by xev in X. Keep this in mind when translating the keymaps into keysyms using xmodmap (See [[Extra Keyboard Keys in Xorg]]).<br />
<br />
If all your keys have a keycode you can go directly to the second step. If not keep reading below:<br />
<br />
=== Check for scancodes ===<br />
If a key does not have a keycode you can know if it has a scancode by looking at the kernel log using the dmesg command:<br />
$ dmesg|tail -5<br />
If when you press the key something like that appears:<br />
atkbd.c: Unknown key pressed (translated set 2, code 0xf1 on isa0060/serio0).<br />
atkbd.c: Use 'setkeycodes e071 <keycode>' to make it known.<br />
then your key has a scancode which can be mapped to a keycode. See [[Map scancodes to keycodes]].<br />
<br />
If nothing new appears in dmesg then your key does not have a scancode, which means that it is not recognized by the kernel and cannot be used.<br />
<br />
==Step 2: Map keycodes==<br />
===In Console===<br />
''See the dedicated article: [[Extra Keyboard Keys in Console]].''<br />
<br />
When in console, hotkeys can be used to print sequences of characters, including escape sequences. Thus, printing the sequence of characters constituting a command followed by the escape sequence for a new will execute the command.<br />
<br />
===In Xorg===<br />
''See the dedicated article: [[Extra Keyboard Keys in Xorg]].''<br />
<br />
==Laptops==<br />
===Asus M series===<br />
In order to have control over the light sensor and the multimedia keys on your Asus machine, you should use the following command:<br />
<br />
{{bc|# echo 0 > /sys/devices/platform/asus-laptop}}<br />
<br />
To have it run on boot:<br />
{{hc|/etc/rc.local|echo 0 > /sys/devices/platform/asus-laptop/ls_switch}}<br />
<br />
Note that this may work for other Asus notebook models.<br />
''See the detailed article: [[lineak]].''</div>Aleksclark