Skip to content

Automatically adjust the resolution, depending on the connected displays #18

@mi-skam

Description

@mi-skam

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")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions