Results 1 to 5 of 5

Thread: How do I change the screen brightness with a keyboard shortcut?

  1. #1
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,772
    Distro
    Lubuntu 18.04 Bionic Beaver

    Question How do I change the screen brightness with a keyboard shortcut?

    I have been searching how to change my screen's brightness with a keyboard shortcut, because my keyboard doesn't have a physical key.

    A tool such as xrandr isn't suitable, because it messes with my Night Light setting.

    From the terminal or from Alt+F2, these two commands correctly raise or lower the screen's brightness respectively:
    Code:
    xdotool key XF86MonBrightnessUp
    xdotool key XF86MonBrightnessDown
    However, if I add these to my custom keyboard shortcuts, they don't work.

    I created a basic script to do the same thing, and I discovered something odd. This script works when run from the terminal or Alt+F2, but not from a keyboard shortcut:
    Code:
    #!/usr/bin/env bash
    xdotool key XF86MonBrightnessUp
    However, this does work from a keyboard shortcut:
    Code:
    #!/usr/bin/env bash
    zenity --info --text='Brightness up'
    xdotool key XF86MonBrightnessUp
    Of course, there's the inconvenience of pressing Enter to close Zenity's display before it works.

    Putting Zenity into the background prevents it from working:
    Code:
    #!/usr/bin/env bash
    zenity --info --text='Brightness up' &
    xdotool key XF86MonBrightnessUp
    Obviously, running Zenity to put something on the screen somehow "activates" the screen from Bash's point of view.

    How can I achieve what I'm after without having to display something on the screen?

  2. #2
    Join Date
    Oct 2004
    Location
    33.4N -112.1W
    Beans
    2,435
    Distro
    Ubuntu Budgie

    Re: How do I change the screen brightness with a keyboard shortcut?

    Can you use xbacklight with your GFX to control the brightness?

    Brightness Down (example):
    $ xbacklight -1

    Brightness Up (example):
    $ xbacklight +5

    If it works test it by adding it:
    Settings → Keyboard → Application Shortcuts

    Reboot may be required.
    /path/to/Truth

  3. #3
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,772
    Distro
    Lubuntu 18.04 Bionic Beaver

    Re: How do I change the screen brightness with a keyboard shortcut?

    Thank you for the reply, Xian.

    Unfortunately, xbacklight does nothing whatsoever to my screen display, even after rebooting. There's no error message; it just does nothing. I've also tried using -display :0.

  4. #4
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,772
    Distro
    Lubuntu 18.04 Bionic Beaver

    Re: How do I change the screen brightness with a keyboard shortcut?

    I've discovered the solution, with a bit of intuition and some trial-and-error.

    The keys XF86MonBrightnessDown and XF86MonBrightnessUp are assigned in dconf respectively to
    /org/gnome/settings-daemon/plugins/media-keys/screen-brightness-down-static
    /org/gnome/settings-daemon/plugins/media-keys/screen-brightness-up-static


    Changing the key assignments to something that I could use (I chose <Super>F11 and <Super>F12) didn't work.

    However, I found that using those assignments on a different key worked:
    /org/gnome/settings-daemon/plugins/media-keys/screen-brightness-down
    /org/gnome/settings-daemon/plugins/media-keys/screen-brightness-up


    Problem solved!

  5. #5
    Join Date
    Aug 2011
    Location
    51.8° N 5.8° E
    Beans
    5,937
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: How do I change the screen brightness with a keyboard shortcut?

    Alternatively, the brightness is available in the /sys pseudofilesystem. You can read the current brightness, the max brightness and set a new brightness.
    Code:
    $ cd /sys/class/backlight/acpi_video0
    $ ls
    actual_brightness  bl_power  brightness  device  max_brightness  power  scale  subsystem  type  uevent
    $ cat actual_brightness
    16
    $ cat max_brightness
    20
    $ echo 4 | sudo tee brightness
    ## This make my screen very dim
    $ cat actual_brightness
    4
    This tends to be somewhat hardware dependent. Just have a look around there.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •