Get Ubuntu Get Ubuntu

Download Ubuntu now for free, request a free CD or buy it on DVD or CD

Get Support Get Support

Free documentation and community support, or buy professional support

Get Involved Get Involved

Share technical know-how with other users, or help to promote Ubuntu

Get Developing Get Developing

Share your development expertise and help shape the future of Ubuntu

User login

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
18 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Navigation

Who's new

  • mayonks
  • naiimullah
  • iwe
  • bizkut

Who's online

There are currently 0 users and 2 guests online.

Subscribe to Ubuntu Malaysia by e-mail

Delivered by FeedBurner

Search

Akkana Peck: Making those Fn- laptop keys do something useful

bizkut's picture


A friend was trying to get some of her laptop's function keys working
under Ubuntu, and that reminded me that I'd been meaning to do the
same on my Vaio TX 650P.

My brightness keys worked automagically -- I suspected via the scripts
in /etc/acpi -- and that was helpful in tracking down the rest of the
information I needed. But it still took a bit of fiddling since
(surprise!) how this stuff works isn't documented.

Here's the procedure I found.

First, use acpi_listen to find out what events are generated
by the key you care about. Not all keys generate ACPI events.
I haven't get figured out what controls this -- possibly the kernel.
When you type the key, you're looking for something like this:

sony/hotkey SPIC 00000001 00000012

You may get separate events for key down and key up. It's your choice
as to which one matters.

Once you know the code for your key, it's time to make it do something.
Create a new file in /etc/acpi/events -- I called mine sony-lcd-btn.
It doesn't matter what you call it -- acpid will read all of them.
(Yes, that means every time you start up it's reading all those
toshiba and asus files even if you have a Lenovo or Sony.
Looks like a nice place to shave off a little boot time.)

The file is very simple and should look something like this:

# /etc/acpi/events/sony-lcd-btn

event=sony/hotkey SPIC 00000001 00000012
action=/etc/acpi/sonylcd.sh

Now create a script for the action you specified in the event file.
I created a script /etc/acpi/sonylcd.sh that looks like this:

#! /bin/bash
# temporary, for testing:
echo "LCD button!" >/dev/console

Now restart acpid: service acpid restart if you're
on karmic, or /etc/init.d/acpid restart on earlier releases.
Press the button. If you're running from the console (or using a
tool like xconsole), and you got all
the codes right, you should be able to see the echo from your script.

Now you can do anything you want. For instance, when I press the LCD
button I generally want to run this:

xrandr --output VGA --mode 1024x768

Or to make it toggle, I could write a slightly smarter script using
xrandr --query to find out the current mode and behave accordingly.
I'll probably do that at some point when I have a projector handy.


Original Source: http://shallowsky.com/blog/linux/kernel/acpi-buttons.html