Skip to main content
Clarifying what portion of the code is important
Source Link

(Someone edited the code above, I assume to preserve it in case the gist disappears, but anyways. The important part is only the "rw_code = ..." those are the instructions you need to execute in RWEverything, you can ignore the rest if you're writing your own code.)

You can use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of Intel graphics, and then you get some address that you read from system memory and the current and max values, and you modify the current brightness value.

You can use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of Intel graphics, and then you get some address that you read from system memory and the current and max values, and you modify the current brightness value.

(Someone edited the code above, I assume to preserve it in case the gist disappears, but anyways. The important part is only the "rw_code = ..." those are the instructions you need to execute in RWEverything, you can ignore the rest if you're writing your own code.)

You can use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of Intel graphics, and then you get some address that you read from system memory and the current and max values, and you modify the current brightness value.

added 1498 characters in body
Source Link
Peregrino69
  • 4.7k
  • 3
  • 23
  • 30

So, first, you'll need RWEverythingRWEverything (or any similar program/code that can read PCIe and system memory). The idea is simple, there is an address that is used by the intelIntel graphics driver where Windows writes the value to use when you use the default brightness keys.

I found the code herein https://gist.github.com/Orochimarufan/04da79841395710c0dbc9d28a22e29f2GitHub

The relevant part is this:

#!/usr/bin/env python3
# Intel Backlight Hack
# CC0 2018 Taeyeon Mori aka /u/Haruha

# Must be absolute!
rw_path = "D:\\Development\\Win32-Intel-Backlight\\Rw-Everything\\Rw.exe"

# Actuall Rw batch code follows
rw_code = """\
Read Intel GFX BAR1
> Local0 = rPCIe32(0, 2, 0, 0x10)
Null out flags to get address
> Local1 = and(Local0, 0xFFFFFFFFFFFFFFF0)
LVX offset = 0xC8254
See https://github.com/RehabMan/OS-X-Intel-Backlight/blob/master/IntelBacklight/IntelBacklightHandler.cpp#L39
> Local2 = or(Local1, 0xC8254)
Get LVX
> Local3 = r32(Local2)
Get max brightness
> Local4 = shr(Local3, 16)
Get relative brightness
> Local5 = mul(Local4, {level})
> Local5 = div(Local5, 100)
Construct new LVX
> Local6 = shl(Local4, 16)
> Local6 = or(Local6, Local5)
Write to hardware
> w32 Local2 Local6
"""

rw_exit_code = "> RwExit"


import sys
import ctypes

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False


if not is_admin():
    # Re-run the program with admin rights
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join([__file__] + sys.argv[1:]), None, 1)
    
    sys.exit()


import os
import argparse
import subprocess
import tempfile

parser = argparse.ArgumentParser()
parser.add_argument("level", help="New Backlight level", choices=list(range(0,101)), type=int, metavar="0-100", nargs="?")
parser.add_argument("--noexit", action="store_true", help="Don't exit Rw after running the script")
parser.add_argument("--pause", action="store_true", help="Pause after execution")
args = parser.parse_args()

if args.level is None:
    print("Enter new brightness level in %, or \"x\" to abort")
    while True:
        print("Brightness: ", end="")
        v = input()

        if v.lower() == "x":
            print("Aborted")
            sys.exit(12)
        
        try:
            args.level = int(v)
        except ValueError:
            continue
        else:
            if args.level <= 100 and args.level >= 0:
                break

with tempfile.NamedTemporaryFile("w", delete=False) as f:
    f.write(rw_code.format(level=args.level))
    
    if not args.noexit:
        f.write(rw_exit_code)
    
    path = os.path.dirname(f.name)
    name = os.path.basename(f.name)

subprocess.run([rw_path, "/Command=%s" % name], cwd=path)

os.unlink(os.path.join(path, name))

if args.pause:
    print("Press enter to continue")
    input()

So basically, eitherYou can use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of intelIntel graphics, and then you get some address that you read from system memory and then you get the current and max values, and you modify the current brightness value. 

All of this is using the command line apiAPI of RWEverything so then you can call it from some keyboard shortcut and make sure it runs as admin whenever Windows is started and voila, brightness control that goes to zero.

(Side note: in In my code, I made two shortcuts, one for controlling windows brightness and then one for the direct brightness value, because when. When you write a value using memory, windows Windows still thinks it's the old value, so I only use writing to write below the minimum of windowsWindows and use windows for above the windowsWindows minimum, it's.

It's not a big deal just cozbecause rarely, like after waking up, windowsWindows might set the brightness again to the old value, so I keep them close by using windows steps for the big jumps and my code for fine tuning or going really low.)

Now finally I can say my eyes are happy :)

P.S. this shows how easy it is, so literally there is no excuse why intel and windows could let the user adjust the brightness steps, Windows literally just writes a value to a memory location and it could have easily offered user defined brightness levels... Oh well, what can we do...

So, first, you'll need RWEverything (or any similar program/code that can read PCIe and system memory). The idea is simple, there is an address that is used by the intel graphics driver where Windows writes the value to use when you use the default brightness keys.

I found the code here https://gist.github.com/Orochimarufan/04da79841395710c0dbc9d28a22e29f2

The relevant part is this:

rw_code = """\
Read Intel GFX BAR1
> Local0 = rPCIe32(0, 2, 0, 0x10)
Null out flags to get address
> Local1 = and(Local0, 0xFFFFFFFFFFFFFFF0)
LVX offset = 0xC8254
See https://github.com/RehabMan/OS-X-Intel-Backlight/blob/master/IntelBacklight/IntelBacklightHandler.cpp#L39
> Local2 = or(Local1, 0xC8254)
Get LVX
> Local3 = r32(Local2)
Get max brightness
> Local4 = shr(Local3, 16)
Get relative brightness
> Local5 = mul(Local4, {level})
> Local5 = div(Local5, 100)
Construct new LVX
> Local6 = shl(Local4, 16)
> Local6 = or(Local6, Local5)
Write to hardware
> w32 Local2 Local6
"""

So basically, either use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of intel graphics, and then you get some address that you read from system memory and then you get the current and max values and you modify the current brightness value. All of this is using the command line api of RWEverything so then you can call it from some keyboard shortcut and make sure it runs as admin whenever Windows is started and voila, brightness control that goes to zero.

(Side note: in my code, I made two shortcuts, one for controlling windows brightness and then one for the direct brightness value, because when you write a value using memory, windows still thinks it's the old value, so I only use writing to write below the minimum of windows and use windows for above the windows minimum, it's not a big deal just coz rarely, like after waking up, windows might set the brightness again to the old value, so I keep them close by using windows steps for the big jumps and my code for fine tuning or going really low.)

Now finally I can say my eyes are happy :)

P.S. this shows how easy it is, so literally there is no excuse why intel and windows could let the user adjust the brightness steps, Windows literally just writes a value to a memory location and it could have easily offered user defined brightness levels... Oh well, what can we do...

So, first, you'll need RWEverything (or any similar program/code that can read PCIe and system memory). The idea is simple, there is an address that is used by the Intel graphics driver where Windows writes the value to use when you use the default brightness keys.

I found the code in GitHub:

#!/usr/bin/env python3
# Intel Backlight Hack
# CC0 2018 Taeyeon Mori aka /u/Haruha

# Must be absolute!
rw_path = "D:\\Development\\Win32-Intel-Backlight\\Rw-Everything\\Rw.exe"

# Actuall Rw batch code follows
rw_code = """\
Read Intel GFX BAR1
> Local0 = rPCIe32(0, 2, 0, 0x10)
Null out flags to get address
> Local1 = and(Local0, 0xFFFFFFFFFFFFFFF0)
LVX offset = 0xC8254
See https://github.com/RehabMan/OS-X-Intel-Backlight/blob/master/IntelBacklight/IntelBacklightHandler.cpp#L39
> Local2 = or(Local1, 0xC8254)
Get LVX
> Local3 = r32(Local2)
Get max brightness
> Local4 = shr(Local3, 16)
Get relative brightness
> Local5 = mul(Local4, {level})
> Local5 = div(Local5, 100)
Construct new LVX
> Local6 = shl(Local4, 16)
> Local6 = or(Local6, Local5)
Write to hardware
> w32 Local2 Local6
"""

rw_exit_code = "> RwExit"


import sys
import ctypes

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False


if not is_admin():
    # Re-run the program with admin rights
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join([__file__] + sys.argv[1:]), None, 1)
    
    sys.exit()


import os
import argparse
import subprocess
import tempfile

parser = argparse.ArgumentParser()
parser.add_argument("level", help="New Backlight level", choices=list(range(0,101)), type=int, metavar="0-100", nargs="?")
parser.add_argument("--noexit", action="store_true", help="Don't exit Rw after running the script")
parser.add_argument("--pause", action="store_true", help="Pause after execution")
args = parser.parse_args()

if args.level is None:
    print("Enter new brightness level in %, or \"x\" to abort")
    while True:
        print("Brightness: ", end="")
        v = input()

        if v.lower() == "x":
            print("Aborted")
            sys.exit(12)
        
        try:
            args.level = int(v)
        except ValueError:
            continue
        else:
            if args.level <= 100 and args.level >= 0:
                break

with tempfile.NamedTemporaryFile("w", delete=False) as f:
    f.write(rw_code.format(level=args.level))
    
    if not args.noexit:
        f.write(rw_exit_code)
    
    path = os.path.dirname(f.name)
    name = os.path.basename(f.name)

subprocess.run([rw_path, "/Command=%s" % name], cwd=path)

os.unlink(os.path.join(path, name))

if args.pause:
    print("Press enter to continue")
    input()

You can use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of Intel graphics, and then you get some address that you read from system memory and the current and max values, and you modify the current brightness value. 

All of this is using the command line API of RWEverything so you can call it from some keyboard shortcut and make sure it runs as admin whenever Windows is started and voila, brightness control that goes to zero.

In my code I made two shortcuts, one for controlling windows brightness and then one for the direct brightness value. When you write a value using memory Windows still thinks it's the old value, so I only use writing to write below the minimum of Windows and use windows for above the Windows minimum.

It's not a big deal because rarely, like after waking up, Windows might set the brightness again to the old value, so I keep them close by using windows steps for the big jumps and my code for fine tuning or going really low.

Source Link

After years of not finding a solution, I finally did! And now I can control the backlight directly even setting it to zero and with fine granularity. So I'll share the solution for anyone interested :)

So, first, you'll need RWEverything (or any similar program/code that can read PCIe and system memory). The idea is simple, there is an address that is used by the intel graphics driver where Windows writes the value to use when you use the default brightness keys.

I found the code here https://gist.github.com/Orochimarufan/04da79841395710c0dbc9d28a22e29f2

The relevant part is this:

rw_code = """\
Read Intel GFX BAR1
> Local0 = rPCIe32(0, 2, 0, 0x10)
Null out flags to get address
> Local1 = and(Local0, 0xFFFFFFFFFFFFFFF0)
LVX offset = 0xC8254
See https://github.com/RehabMan/OS-X-Intel-Backlight/blob/master/IntelBacklight/IntelBacklightHandler.cpp#L39
> Local2 = or(Local1, 0xC8254)
Get LVX
> Local3 = r32(Local2)
Get max brightness
> Local4 = shr(Local3, 16)
Get relative brightness
> Local5 = mul(Local4, {level})
> Local5 = div(Local5, 100)
Construct new LVX
> Local6 = shl(Local4, 16)
> Local6 = or(Local6, Local5)
Write to hardware
> w32 Local2 Local6
"""

So basically, either use the python script in the link above or write something in your favorite language (I used AHK). But basically, you read a value from the PCIe of intel graphics, and then you get some address that you read from system memory and then you get the current and max values and you modify the current brightness value. All of this is using the command line api of RWEverything so then you can call it from some keyboard shortcut and make sure it runs as admin whenever Windows is started and voila, brightness control that goes to zero.

(Side note: in my code, I made two shortcuts, one for controlling windows brightness and then one for the direct brightness value, because when you write a value using memory, windows still thinks it's the old value, so I only use writing to write below the minimum of windows and use windows for above the windows minimum, it's not a big deal just coz rarely, like after waking up, windows might set the brightness again to the old value, so I keep them close by using windows steps for the big jumps and my code for fine tuning or going really low.)

Now finally I can say my eyes are happy :)

P.S. this shows how easy it is, so literally there is no excuse why intel and windows could let the user adjust the brightness steps, Windows literally just writes a value to a memory location and it could have easily offered user defined brightness levels... Oh well, what can we do...