Scale and Layout - Windows10 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sokrakes
Posts: 36
Joined: 07 Aug 2019, 01:40

Scale and Layout - Windows10

Post by sokrakes » 04 Jun 2023, 03:14

Has anyone solved the fast view switching in Windows, sometimes I need a larger view because some programs on 4K are unreadable, like using OCR.
Simply switch between 150% and 200% .
I only found this https://www.tenforums.com/graphic-cards/171539-hotkey-scaling-windows-10-a.html

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Scale and Layout - Windows10  Topic is solved

Post by teadrinker » 04 Jun 2023, 10:56

For the primary monitor:

Code: Select all

MsgBox 'New scale: ' . SetPrimaryMonitorScaling(150)

SetPrimaryMonitorScaling(value) {
/*
    info: https://is.gd/c10siw
          https://is.gd/zFERYq
    possible values 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500
*/
    static SPI_GETLOGICALDPIOVERRIDE := 0x009E
         , SPI_SETLOGICALDPIOVERRIDE := 0x009F
         , SPIF_UPDATEINIFILE := 0x00000001
         , MONITOR_DEFAULTTOPRIMARY := 0x00000001
         , ScaleValues := [100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500]

    found := false
    for k, v in ScaleValues {
        continue
    } until value = v && found := true
    if !found {
        throw ValueError('Incorrect value: ' . value . '. Allowed values: 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500')
    }
    if !DllCall('SystemParametersInfo', 'UInt', SPI_GETLOGICALDPIOVERRIDE, 'Int', 0, 'IntP', &v := value, 'UInt', 0) {
        throw OSError('SPI_GETLOGICALDPIOVERRIDE unsupported')
    }
    if !recommendedScaling := ScaleValues[1 - v] {
        throw OSError('Something wrong')
    }
    s := r := 0
    for k, v in ScaleValues {
        (v = value && s := k)
        (v = recommendedScaling && r := k)
    } until s && r
    if !DllCall('SystemParametersInfo', 'UInt', SPI_SETLOGICALDPIOVERRIDE, 'Int', s - r, 'Ptr', 0, 'UInt', SPIF_UPDATEINIFILE) {
        throw OSError('Failed to set new scale factor')
    }
    hMon := DllCall('MonitorFromWindow', 'Ptr', 0, 'UInt', MONITOR_DEFAULTTOPRIMARY, 'Ptr')
    DllCall('Shcore\GetScaleFactorForMonitor', 'Ptr', hMon, 'UIntP', &scale := 0)
    return scale
}

sokrakes
Posts: 36
Joined: 07 Aug 2019, 01:40

Re: Scale and Layout - Windows10

Post by sokrakes » 04 Jun 2023, 13:01

Great, thank you very much.

Post Reply

Return to “Ask for Help (v2)”