SetDPI icon indicating copy to clipboard operation
SetDPI copied to clipboard

Automatically adjust the resolution, depending on the connected displays

Open mi-skam opened this issue 2 years ago • 0 comments

Hi there, many thanks for that little helper, I always looked for a way to automate the scaling of my laptop depending on the connected state of the hdmi output. I scale it to 150% if it's next to my external display, as it's further away.

I just wanted to share my ahk script, maybe it's useful to others.

#Requires AutoHotkey v2.0
; requires setDpi.exe in $PATH https://github.com/imniko/SetDPI/

OnMessage 0x007E, OnDisplayChange ; System Event: Display changes
Persistent

OnDisplayChange(wParam, lParam, *)
{
    scale_connected := 150
    scale_solo := 100
    display_lg := "\\.\DISPLAY4"
    ; display_internal := "\\.\DISPLAY1"

    ; Determine the scale based on the primary monitor
    ; TODO: find a more stable property
    new_scale := MonitorGetName() == display_lg ? scale_connected : scale_solo
    Sleep 1000 ; setDpi needs to be delayed a little bit, otherwise explorer.exe crashes
    Run("setDpi.exe " . new_scale . " 1")
}

mi-skam avatar Jan 09 '24 12:01 mi-skam