Skip to content

[Linux] Solution to the invalid shortcut key for changing the brightness of laptop screen

On my laptop keyboard, F11 and F12 are shortcut keys to change the screen brightness, just like the picture:

Although the icons is very good to know, my laptop can not use them to change the screen brightness (But in Windows operating system, they can work normally). To be on the safe side, I also used the xev command to test and they was naturally caught keycode.

So, today I want to record how I reconstructed these two buttons as shortcuts for changing the screen brightness.


Change the Brightness

In my Linux system, my screen brightness setting file is located the /sys/class/backlight/intel_backlight/. Your path may be different from mine, but roughly it will be in /sys/class/backlight/.

max_brightness is the maximum brightness that can be set on my system, which is 120000; brightness is the value currently set by my system. As long as the value in this file is changed, the brightness of my computer screen will also change.

So the first time to do is to set permission for the brightness file so that I can edit to it in normal mode.

sudo chmod 777 brightness


If I want to reduce the brightness, I can use the following command:

br=$(cat /sys/class/backlight/intel_backlight/brightness) &&
br=$(expr $br - 12000) &&
echo $br > /sys/class/backlight/intel_backlight/brightness



If I want to increase the brightness, just replace - with +.

br=$(cat /sys/class/backlight/intel_backlight/brightness) &&
br=$(expr $br + 12000) &&
echo $br > /sys/class/backlight/intel_backlight/brightness



Confirm that there is no problem with these two commands, you can set them as shortcut keys.


Set shortcut keys

In fact, setting the shortcut keys is quite simple. I will just give a demonstration here, but most of the desktop environments have similar ways to set the shortcut keys.

Basically, if you search for "Shortcut", you should be able to directly find the place to set the shortcut key.

There are three parameters to be filled in to set the shortcut key: Name, Command, Shortcut.

  • Name: It doesn’t matter, just fill in the name you like
  • Command: Fill in the command above to adjust the screen brightness
  • Shortcut: Press the shortcut key you want, in my case it is F11, F12

After completing the settings, I can successfully pretend that my keys are working properly.

Tags:

Leave a Reply