Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I'm trying to fix my keyboard keys brightness up/down.

Using acpi_listen pressing brightness up/down I have the result:

video DD03 00000087 00000000
video DD03 00000086 00000000

Running showkey:

keycode 225 press
keycode 225 release
keycode 224 press
keycode 224 release

I have set on compizconfi

share|improve this question
I assume your holding down the Function key while pressing another key on your keyboard correct? Is your screen doing anything at all? Flickering, etc...? If not then we need to bind those key presses to run a command that increases or decreases your brightness level. If however your screen Flickers or makes some sort of adjustment then X is recognizing your buttons and we can go about this another way. –  Scott Stookey Feb 25 '12 at 22:00
@ScottStookey hi...you are right about fn key, when I press it appears a black box on top right corner, as it does for sound (sound works perfectly) but for brightness it doesn't...so I think the brightness keys are being identified but not working –  Gerep Feb 25 '12 at 22:03
Ok... Yes they are being recognized so key recognition isn't a problem. Let's do this and see if we can make the screen adjust. Were going to install an app that we can use to adjust the brightness level. Type the following in a terminal window: sudo apt-get install xbacklight After you have it install type the following at the command prompt: xbacklight -dec 50% and see if the brightness decreases. If it does type xbacklight -inc 100% to adjust to full brightness. Report back on your findings. –  Scott Stookey Feb 25 '12 at 22:11
How is overall compiz working? Are you able to use features in Compiz like wobbly windows, and Desktop Cube etc.? –  Scott Stookey Feb 25 '12 at 22:18
let us continue this discussion in chat –  Scott Stookey Feb 25 '12 at 22:25

1 Answer 1

up vote 1 down vote accepted

There are many ways to adjust the screen backlight of a monitor, laptop or integrated panel (such as the iMac) using software, but depending on hardware and model, sometimes only some options are available.


  • brightness is controlled by vendor specified hotkey. And there is no interface for OS to adjust brightness.
  • brightness is controlled by OS:
  • brightness could be controlled by ACPI
  • brightness could be controlled by graphic driver.

There is an excellent article on Wiki summarizing the possible ways of doing this at: https://wiki.archlinux.org/index.php/Backlight

However if ACPI, xbacklight or xcalib fail to adjust your brightness levels we can use the setpci command to manipulate the graphics card directly. This is the method we will be using for this tutorial.

Note: This method should only be used if the above mentioned programs fail to accomplish what your wanting to do and is not the preferred method for doing so. However in numerous cases, its the only one that will.

What were going to do is bind the setpci command to a key combination on your keyboard using xbindkeys, so that when certain keys are pressed your brightness will adjust up or down.

Ok Let's get Started!!

  • First we need to determine the Device Address of your graphics card, in most cases its going to be 00:02.0 but not always so here's how to check.

Open up a terminal window and at the command prompt type the following:

lspci |grep -i vga

This will return a line displaying information such as vendor, model, version etc... The part were interested in is at the very beginning and should look something like the following:


Note: Output may vary

This is the Device Address of your graphics card and we will be using this along with the setpci command to control your brightness levels. So Write It Down!

  • Next we need to download xbindkeys. This will be the program that does the actual binding of the setpci command to the key combination on your keyboard.

Open a terminal window and type the following at the command prompt:

sudo apt-get install xbindkeys

  • Now we are going to create two files in our Home directory that xbindkeys will use when it starts up.

Open a terminal window if you haven't already and change into your Home directory. Type the following commands at the command prompt:

touch .xbindkeysrc

This creates a file that we will be typing our configurations into and it is read by xbindkeys each time it is started

touch .xbindkeys.noauto

This just creates a blank file but it is crucial because when it exists it keeps xbindkeys from starting automatically at boot. Though we want xbindkeys to start automatically we want to control it ourselves because the Xserver starts it to early in the boot process. This causes our configurations that we make to sometimes not function properly. We will add a script called xb_start.sh to our Startup Applications later in this tutorial that will take care of the startup process.

Let's find out what keys do what!!

For time saving purposes I'm going to automatically assume that the Xserver already recognizes the keys you press on your keyboard to change brightness, it just doesn't do anything when you press them. In my case its the Fn + Up Arrow or Down Arrow

But we can't just put the words Fn,Up Arrow or Down Arrow in our config file, we have to find out what the keycodes are.

In most cases they are going to be keycode 232 to adjust the brightness down and keycode 233 to adjust the brightness up but we better make sure.

Open a terminal window and type the following at the command prompt:

xmodmap -pke |grep -i xf86monbrightness

This should return two lines that look similar to the following:

keycode 232 = XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown

keycode 233 = XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp

The info were concerned about are the numbers that come after keycode. In this case it's 232 and 233. Write whatever numbers it is down for we will be using them later.

Let's start putting it all together!!

  • Now we're going to use the information that we've gathered and written down to add some lines to the .xbindkeysrc file you created earlier in your Home directory.

Using your favorite text editor, open the .xbindkeysrc file and either copy and paste or type the following lines to it and save it:

Note: If 232 and 233 aren't the same keycodes you wrote down earlier, change them in this file


What were doing here is telling xbindkeys to run the blevel_down.sh script when we press the key combo on our keyboard that adjusts brightness down. In my case it's Fn + Down Arrow. On the next line we're telling it to run the blevel_up.sh for Fn + Up Arrow

Note: Key combos vary, check the pictures on the keys of your keyboard to determine which ones they are for you.

Lets write the scripts!!

The blevel_up.sh and blevel_down.sh scripts are created to incrementally adjust the brightness up or down by passing arguments to the setpci command. So pretty much when you press whatever keys that do the adjusting, the brightness goes up a little or down a little each time. The xb_start.sh is used to start xbindkeys when the computer boots up but allows for other processes to complete before doing so.

Note: If your Device Address of your Graphics card that we determined earlier differs from the one in blevel_up.sh and blevel_down.sh you will need to modify accordingly. Most likely they should be the same.

  • We will create blevel_up.sh first:

Open up your favorite text editor and either copy and paste or type the following into a file and save it as blevel_up.sh in your Home directory


if [ ! -f /home/$USER/.blevel ]; then 

    touch /home/$USER/.blevel
    echo "FF" > /home/$USER/.blevel


    state=`cat /home/$USER/.blevel`


new_state=$(echo "$[0x$state+0x10]")

if [ "$new_state" -gt 255 ]; then 

    sudo setpci -s 00:02.0 F4.B=FF


    state=$(echo "obase=16; $new_state" | bc)
    sudo setpci -s 00:02.0 F4.B=$state
    echo $state > /home/$USER/.blevel


  • Now we will create the blevel_down.sh script:

Open up your favorite text editor and either copy and paste or type the following into a file and save it as blevel_down.sh in your Home directory


if [ ! -f /home/$USER/.blevel ]; then 

    touch /home/$USER/.blevel
    echo "FF" > /home/$USER/.blevel


    state=`cat /home/$USER/.blevel` 


new_state=$(echo "$[0x$state-0x10]")

if [ "$new_state" -lt 15 ]; then 

    sudo setpci -s 00:02.0 F4.B=0F


    state=$(echo "obase=16; $new_state" | bc)
    sudo setpci -s 00:02.0 F4.B=$state
    echo $state > /home/$USER/.blevel


  • Now we will create the xb_start.sh script:

Open up your favorite text editor and either copy and paste or type the following into a file and save it as xb_start.sh in your Home directory


sleep 10
/usr/bin/xbindkeys &

Lets make the scripts Global!!

  • Now what we wanna do is move the three scripts we just created from our Home directory to /usr/local/bin and set the permissions so that no matter who is logged in on the machine they can execute them.

Open up a terminal window and type the following at the command prompt:

sudo mv blevel_up.sh blevel_down.sh xb_start.sh /usr/local/bin

sudo chmod 755 /usr/local/bin/blevel_up.sh

sudo chmod 755 /usr/local/bin/blevel_down.sh

sudo chmod 755 /usr/local/bin/xb_start.sh

Now to make setpci be able to run without typing a password each time

Being that setpci makes changes to certain system files, a regular user would have to prefix setpci with sudo eachtime in order to run the command. This would require you to enter a password eachtime you want to adjust the brightness of your screen. If we make a particular entry in the /etc/sudoers file we can get around this.

Open a terminal window and type the following at the command prompt:

sudo visudo

This will open up the /etc/sudoers file so that we can make the required changes.

Scroll all the way to the bottom of the file and type the following:

ALL ALL = NOPASSWD:/usr/bin/setpci

Note: File is Case-Sensitive so type exactly how it is here

Save the file and exit

Almost Finished!!

Last thing we need to do is add our xb_start.sh script to our Startup Applications so that xbindkeys starts at boot exactly when we want it to.

Reboot and Enjoy!

share|improve this answer
100%!!! The only problem is that the box on the top right corner is gone but it worked perfectly...thanks Scott –  Gerep Feb 27 '12 at 14:51
That also solved the problem when my computer hibernates or when I close the lid...in those situations I had to restart to get full brightness..now its solved...amazing –  Gerep Feb 27 '12 at 15:20
The box on the top right doesn't show up anymore because xbindkeys is trapping the key combos before the Xserver does, causing it to run our scripts rather than whatever it was before that wasn't working. –  Scott Stookey Feb 27 '12 at 16:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.