Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

66%
+2 −0
Q&A Bind brightness/volume and other special Fn keys in a tty

The special Fn keys typically trigger ACPI events, for which the ACPI daemon can trigger actions. Install ACPI daemon (apt install acpid) and make sure it is started and enabled. If it isn't, sy...

posted 2y ago by Quasímodo‭

Answer
#1: Initial revision by user avatar Quasímodo‭ · 2022-05-28T13:04:24Z (almost 2 years ago)
The special Fn keys typically trigger ACPI events, for which the ACPI daemon
can trigger actions.

Install ACPI daemon (`apt install acpid`) and make sure it is started and enabled. If it isn't,

    systemctl start  acpid
    systemctl enable acpid

You can read its manual page and inspect files under `/etc/acpi` to
easily figure it all out. But here is a summary.

Run `acpi_listen` and press the special Fn keys. For brightness keys, volume keys
and reconnecting the AC adapter, I get

    $ acpi_listen
     676AA15E-6A47- 000000bc 00000000
    video/brightnessdown BRTDN 00000087 00000000
     676AA15E-6A47- 000000bc 00000000
    video/brightnessup BRTUP 00000086 00000000
     676AA15E-6A47- 000000bc 00000000
     676AA15E-6A47- 000000bc 00000000
    button/volumedown VOLDN 00000080 00000000 K
    button/volumeup VOLUP 00000080 00000000 K
    ac_adapter ACPI0003:00 00000080 00000000
    battery PNP0C0A:00 00000080 00000001
    ac_adapter ACPI0003:00 00000080 00000001
    battery PNP0C0A:00 00000080 00000001

Ignore garbage lines, just take note of the relevant identifiers, and look inside
`/etc/acpi/acpi_handler.sh`.

The `set $*` statement turns each space delimited field into a positional
argument. I.e.,

    button/volumeup VOLUP 00000080 00000000 K
    ^^^^^^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^ ^
          $1         $2      $3       $4    $5

A working example:

```
if [ $# != 1 ]; then
        exit 1
fi
set $*

case "$1" in
    button/volumeup)      amixer -q set Master 5%+ ;;
    button/volumedown)    amixer -q set Master 5%- ;;
    video/brightnessup)   xbacklight -inc 6 ;;
    video/brightnessdown) xbacklight -dec 6 ;;
    ac_adapter)
        case "$4" in
            *1) adapter_connected ;;
            *0) adapter_disconnected ;;
        esac 
    ;;
esac
```

Then restart the daemon:

    systemctl restart acpid

And the bindings will work.

See also: [Arch Wiki: acpid](https://wiki.archlinux.org/title/Acpid).