Skip to content

Control your computer's brightness based on the foreground window

Notifications You must be signed in to change notification settings

calvindalenta/windows-brightness

Repository files navigation

WARNING: These scripts are OS (Windows) specific

Windows Brightness

These scripts will provide you the functionalities for getting the current window on the foreground and getting and setting your computer's brightness

Click here if you just want to use the binary

Dependencies

Before using this script, there are several dependencies that need to be installed. Use the package manager pip to install them.

pip install WMI
pip install win32gui

Script Usage

Brightness

from brightness import Brightness
b = Brightness()
b.get_brightness() # Get the current brightness
b.set_brightness(30) # Percentage [0-100]

Checking foreground window by interval

from brightness import Brightness
from gui import ForegroundGUI
import time

brightness = Brightness()
gui = ForegroundGUI()
interval = 1

while True:
  current_brightness = brightness.get_brightness()
  current_window = gui.get_foreground_window()

  #Your app logic here based on the current brightness and current window

  time.sleep(interval)

Checking foreground window by the callback event

from brightness import Brightness
from event import ForegroundEvent

brightness = Brightness()
event = ForegroundEvent(callback)

def callback(current_window):
  #Your app logic based on current window provided

Binary Usage

The binary can be downloaded on the release page

Specify one window to watch

program.exe start one "Untitled - Notepad" 40

Specify multiple windows to watch

program.exe start file yourfile.csv

The csv file specified should have two columns (without header). The first column is the window name and the second one is the brightness value if true.

See example.csv for reference

Specify default brightness if all the windows specified don't exist

program.exe start -d 40 one "Untitled - Notepad" 40
program.exe start -d 40 file yourfile.csv

If you just want to see what's your current window

program.exe test

About

Control your computer's brightness based on the foreground window

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages