Difference between revisions of "ACPI hotkeys"
(corrected hyperlink on Gentoo-Wiki) |
m (→Installing Necessary Tools: Edited necessary tools to reflect the requirement of only acpid) |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | [[ | + | [[ru:ACPI hotkeys]] |
− | [[Category: | + | [[zh-CN:ACPI hotkeys]] |
− | + | [[Category:Input devices]] | |
− | |||
− | |||
− | |||
====Summary==== | ====Summary==== | ||
Line 12: | Line 9: | ||
This guide assumes that you know your keyboard signals through acpi. If you do not know whether or not this is the case, I suggest looking: | This guide assumes that you know your keyboard signals through acpi. If you do not know whether or not this is the case, I suggest looking: | ||
*[http://en.gentoo-wiki.com/wiki/Multimedia_Keys Using Multimedia Keys in Linux] | *[http://en.gentoo-wiki.com/wiki/Multimedia_Keys Using Multimedia Keys in Linux] | ||
− | |||
*[[Extra Keyboard Keys|Extra Keyboard Keys - keyTouch]] | *[[Extra Keyboard Keys|Extra Keyboard Keys - keyTouch]] | ||
====Installing Necessary Tools==== | ====Installing Necessary Tools==== | ||
You should already have these tools installed, but just to make sure you will need | You should already have these tools installed, but just to make sure you will need | ||
− | + | # pacman -S acpid | |
[[ACPI modules|Refer to this guide]] on what modules you should load (i.e. through /etc/rc.conf or modprobe) | [[ACPI modules|Refer to this guide]] on what modules you should load (i.e. through /etc/rc.conf or modprobe) | ||
Line 23: | Line 19: | ||
====Using acpi_listen==== | ====Using acpi_listen==== | ||
Under root, or with sufficient access to the input devices, run: | Under root, or with sufficient access to the input devices, run: | ||
− | acpi_listen | + | # acpi_listen |
If pressing a special key, such as previous or next, receives a response that looks similar to: | If pressing a special key, such as previous or next, receives a response that looks similar to: | ||
hkey VALZ 00000000 00000b31 | hkey VALZ 00000000 00000b31 | ||
then all is well and we can continue. | then all is well and we can continue. | ||
+ | |||
+ | If nothing appears on the screen during execution of the {{Ic|acpi_listen}}, that means that the pressed keys do not generate an ACPI event. In this case you can't use ACPI for monitoring these keys. See the page [[Hotkeys]] for other ways of mapping keys. | ||
===Configuring ACPID=== | ===Configuring ACPID=== | ||
− | The ACPI daemon reacts to ACPI events according to the | + | The ACPI daemon reacts to ACPI events according to the {{ic|handler.sh}} file. This is located in {{ic|/etc/acpi/handler.sh}} |
− | |||
− | You can either directly edit this file, to react to the ACPI events, or you can point it to another shell script (i.e. /etc/acpi/hotkeys.sh) | + | You can either directly edit this file, to react to the ACPI events, or you can point it to another shell script (i.e. {{ic|/etc/acpi/hotkeys.sh}}) |
Under the section | Under the section | ||
Line 103: | Line 100: | ||
fi | fi | ||
− | Note | + | {{Note|This does not need to be run as root if you can receive an acpi_listen response from a user account (again, meaning you have access to the input devices).}} |
Revision as of 23:47, 6 August 2012
Contents
Summary
There are many guides on how to configure multimedia hotkeys using program such as xev or keyTouch. However, this guide explains how to use the simple utility of acpi_listen and generate your own script for hotkeys.
Who Should be Using This Guide
This guide assumes that you know your keyboard signals through acpi. If you do not know whether or not this is the case, I suggest looking:
Installing Necessary Tools
You should already have these tools installed, but just to make sure you will need
# pacman -S acpid
Refer to this guide on what modules you should load (i.e. through /etc/rc.conf or modprobe)
Using acpi_listen
Under root, or with sufficient access to the input devices, run:
# acpi_listen
If pressing a special key, such as previous or next, receives a response that looks similar to:
hkey VALZ 00000000 00000b31
then all is well and we can continue.
If nothing appears on the screen during execution of the acpi_listen
, that means that the pressed keys do not generate an ACPI event. In this case you can't use ACPI for monitoring these keys. See the page Hotkeys for other ways of mapping keys.
Configuring ACPID
The ACPI daemon reacts to ACPI events according to the handler.sh
file. This is located in /etc/acpi/handler.sh
You can either directly edit this file, to react to the ACPI events, or you can point it to another shell script (i.e. /etc/acpi/hotkeys.sh
)
Under the section
case "$1" in
Add the following lines:
hkey) case "$4" in 00000b31) echo "PreviousButton pressed!" exailectl p ;; 00000b32) echo "NextButton pressed!" exailectl n ;; 00000b33) echo "Play/PauseButton pressed!" exailectl pp echo "executed.." ;; 00000b30) echo "StopButton pressed!" exailectl s ;; *) echo "Hotkey Else: $4" ;; esac ;;
The '00000b31' etc. values are the response received from acpi_listen. In 'hkey VALZ 00000000 00000b31', $4 is the final part, which was what distinguished my keys apart.
Also, the exailectl script is a brief shell script I created for controlling Exaile music player. As the ACPID is run from root, you will need to use
sudo -u (username) exaile
for example, otherwise it will not detect your user-level program and recreate another.
Old: Sample Script
As keyTouch and other keyboard programs did not work for me, or did not work effectively, prior to editing my handler.sh file I created my own script that runs in the background and reacts directly from the output of acpi_listen. However it is a poor method to use, caused my laptop to be constantly active and noisy. I have provided the script here anyway, feel free to use it / modify it to suit your needs and post suggestions on how it can be improved. Currently, it is setup for a Toshiba Satellite A50 laptop to control exaile, but can be modified very easily for Amarok, Xine or other non-music related functions (internet, email).
export STOP_MYHOTKEY=0 i=`acpi_listen -c 1` case "$i" in "hkey VALZ 00000000 00000b31") #echo "PREVIOUS" exaile -p ;; "hkey VALZ 00000000 00000b32") #echo "NEXT" exaile -n ;; "hkey VALZ 00000000 00000b33") exaile -t ;; "hkey VALZ 00000000 00000b30") #echo "STOP" exaile -s ;; *) #echo "ELSE: $i" ;; esac e=`echo $STOP_MYHOTKEY` if [ "$e" != "1" ] then ./myHotkey.sh & fi