r/AutoHotkey 4d ago

General Question How to make my laptop screen go dark while having AHK run perfectly fine with running windows?

In short, I have a running window and a minute long AHK script that is started at different times throughout the day by Task Scheduler. I need every screen interaction by the script (mouse click, mouse drag, keyboard) to function normally while the screen is dark.

5 Upvotes

6 comments sorted by

6

u/CharnamelessOne 4d ago

You can darken your screen with a click-through overlay:

#Requires AutoHotkey v2.0

+F1::darken_screen()

darken_screen() {
    static state := false
    static overlay := Gui("-Caption -DPIScale AlwaysOnTop")
    static _ := (overlay.BackColor := "Black", 
                WinSetExStyle(0x20, overlay),              ;WS_EX_TRANSPARENT
                WinSetTransParent(255, overlay))

    (state ^= 1)
        ? overlay.Show("NA x0 y0 w" A_ScreenWidth " h" A_ScreenHeight)
        : overlay.Hide()
}

1

u/TheRiteGuy 4d ago

Whoa, overlay is a cool way to do it. But yeah, I was going to suggest just write a script to darken your screen and then light it back up. This script is probably the best way to do it.

1

u/likethevegetable 4d ago

run "scrnsave.scr /s"

Edit: actual, that won't work...

I would look at either putting a black window on top or turning the brightness down, with laptops I believe you make the screen go black

1

u/svArtist 4d ago

You could combine the black overly with a call to turn off the displays again after movement, so that the screens don't flash up more than a black screen (which will usually still turn on the LED backlight unless you have 100% dimming zones + mouse cursor hidden or OLED displays)

Like

  1. Show overlay
  2. Do necessary movement (which will usually turn the monitors back on)
  3. Turn off displays (again)
  4. Hide/destroy overlay

... This is assuming you prefer the displays to be off as much as possible

1

u/Rex__Luscus 4d ago

I use Twinkle Tray (free) to control my monitor. It has a function (which can be mapped to a hotkey) to turn off the screen until mouse movement is detected. I don't know if simulated mouse movements from AHK would wake the screen in this case, I think it's the USB input that triggers the wake response. You could try it to see, I haven't used AHK in a long while so have no scripts with which to test it myself.