Keyboard

Control all functions of your external monitor with a click on your (wireless) keyboard! Lower brightness, switch input, raise contrast or switch power modes with Python and Monitorcontrol.

1
2
3
4
from monitorcontrol import get_monitors
for monitor in get_monitors():
    with monitor:
        monitor.set_luminance(30)

Motivation

Eye strain is probably one of the most bothering things for people working on computers all day long. While blue light reduction is a key to less fatigue, I personally tend to adjust either my laptop’s or my monitor’s brightness a lot.

Controlling monitor settings with tiny, malfactured plastic buttons however, is quite annoying. Luckily, mid-priced keyboards offer good customization and usually allow - in some way - executing self-written scripts.

Monitorcontrol GUI

If you’re on Windows and don’t have monitor program yet, definitely check out the Monitorian GUI. Easy to use and it simply works out of the box. Similar programs are available for macOS and Linux.

Shortcuts

While the GUI already offers a nice widget with a brightness slider, it’s not effective enough. I prefer keyboard shortcuts and hence used my keyboard’s software to trigger a Python script either lowering or raising brightness by 5%. One could use native shortcut combinations, e.g. shift+l for lower but in my case I use the additional custom keys and proprietary software of my bluetooth keyboard.

Script

Thanks to VESA Monitor Control Command Set (MCCS) and the Display Data Channel Command Interface Standard (DDC-CI) (Monitorcontrol Wiki) it’s only a few lines to set brightness (or “luminance”) percentage.

Install Monitorcontrol

1
pip install monitorcontrol

Set brightness

1
2
3
4
from monitorcontrol import get_monitors
for monitor in get_monitors():
    with monitor:
        monitor.set_luminance(30)

Current brightness -5%

1
2
3
4
5
6
7
from monitorcontrol import get_monitors

for monitor in get_monitors():
    with monitor:
        current_val = monitor.get_luminance()
        set_val = current_val-5 if current_val > 4 else 0
        monitor.set_luminance(set_val)

Current brightness +5%

1
2
3
4
5
6
7
from monitorcontrol import get_monitors

for monitor in get_monitors():
    with monitor:
        current_val = monitor.get_luminance()
        set_val = current_val+5 if current_val <96 else 100
        monitor.set_luminance(set_val)

Logitech Options

Logitech Options is the accompanying software for the recent (as of 2021/22) keyboard and mouse series. Unfortunately they don’t offer Linux support and no direct command execution. However, if you installed Python and Monitorcontrol globally, Windows will recognize the .py extension and simply execute it with Python as it’s supposed to.

If it doesn’t work, you could compile the tiny scripts with pyinstaller to an .exe file and execute it just like any other Windows program.

So simply save the last two sripts as lower-luminance-5.py and raise-luminance-5.py in your directory of choice and choose them in the settings.

Logitech Options

Not enough?

Dimmer is a fantastic tool for additional screen dimming. It’s only a black filter and does not physically dim but helps if you need to go beyond the screen’s limits.