AutoHotKey script to change DPI and resolution settings

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

MedBooster
User
Posts: 1070
Joined: Mon Nov 15, 2021 8:38 pm

AutoHotKey script to change DPI and resolution settings

Post by MedBooster »

This also works well with PDF-xce
I use it all the time when I want to switch between larger and smaller icons, depending on what I am doing more – reading or editing.

Code: Select all

;AutoHotKey script which changes DPI scaling and resolution. Current scaling set to the b3u by MedBooster. 

;call to function 

#F1::MonitorSettings({Width:2880, Height:1800, Scale:200}) ; scale 200 ; working original resolution 3K B3U 16:10 aspect ratio 
#F2::MonitorSettings({Width:1920, Height:1200, Scale:175}) ; scale 225 ;  low resolution 16:10 aspect ratio 
#F3::MonitorSettings({Width:2560, Height:1440, Scale:200}) ; scale 200 ; 3K but 16:9 not working yet   2880*1620 seems to not be supported
#F4::MonitorSettings({Width:1920, Height:1080, Scale:175}) ; scale 225 ;working Book 3 Ultra 16:9 aspect ratio full HD 
#F5::MonitorSettings({Width:2880, Height:1620, Scale:175}) ; scale 175 ;2880*1620 test 3K 16:9
^#!Up::MonitorSettings({Scale:175}) ; will actually be 50 higher than what you set it to
^#!Down::MonitorSettings({Scale:125}) ; will actually be 50 higher  than what you set it to

;the function
MonitorSettings(Options) {
    if (!IsObject(Options))
        throw Exception("Options must be an object.", -1, Options)
    if (Options.HasKey("Scale")) {
        key := ""
        base := "HKCU\Control Panel\Desktop\PerMonitorSettings"
        if (Options.HasKey("Monitor")) {
            key := base "\" Options.Monitor
        } else {
            RegRead start, HKLM\SYSTEM\CurrentControlSet\Services\monitor\Enum, 0
            start := StrSplit(start, "\")[2]
            loop Reg, % base, K
                if (InStr(A_LoopRegName, start) = 1)
                    key := base "\" A_LoopRegName
        }
        RegRead exists, % key, DpiValue
        if (exists != "") {
            scale := {100:-2, 125:-1, 150:0, 175:1, 200:2, 225:3, 250:4}[Options.Scale]
            RegWrite REG_DWORD, % key, DpiValue, % scale != "" ? scale : -2
        } else {
            MsgBox 0x10, Error, Incorrect monitor name, please check the key in the registry and fix it.
            RegWrite REG_SZ, HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit, LastKey, % base
            EnvSet __COMPAT_LAYER, RunAsInvoker
            Run regedit.exe
            EnvSet __COMPAT_LAYER, % ""
        }
    }
    VarSetCapacity(DEVMODEA, 156, 0)
    DllCall("EnumDisplaySettingsA", "Ptr",0, "Int",-1, "Ptr",&DEVMODEA)
    if (Options.HasKey("ColorDepth"))
        NumPut(Options.ColorDepth, DEVMODEA, 104)
    if (Options.HasKey("Width"))
        NumPut(Options.Width, DEVMODEA, 108)
    if (Options.HasKey("Height"))
        NumPut(Options.Height, DEVMODEA, 112)
    if (Options.HasKey("RefreshRate"))
        NumPut(Options.RefreshRate, DEVMODEA, 120)
    return DllCall("ChangeDisplaySettingsA", "Ptr",&DEVMODEA, "Int",0)
}
I am still waiting for a fixed small icon size option for icons though :)
viewtopic.php?t=38735
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: AutoHotKey script to change DPI and resolution settings

Post by Tracker Supp-Stefan »

Hello MedBooster,

Thanks for sharing that script! I am sure it will be useful to others as well!

Kind regards,
Stefan
MedBooster
User
Posts: 1070
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script to change DPI and resolution settings

Post by MedBooster »

While we're still waiting for a "Optional fixed small icon size in the toolbar"-option (similar to the "show text" option)

Here's a new AHK V1 script with a GUI (graphic user interace) which lets you quickly switch between different scaling values 150-175-200-225 on the Yoga Book 9

If you want to adapt it to your PC you have to find the given monitor(s)' value in the registry editor.
You can just copy this in the search bar to find it:
HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings

image.png
image(1).png
The values for the scalings seem to be the same across different devices, so if you want to keep the 4 150-175-200-225 options, changing the "Monitor1Name" should suffice.

You can add more monitors too if you'd like. Or remove the 2nd.
NB! you probably need to edit the resolution (which I named horizontal and vertical pixels at the top) to match your display too! (I added both the horizontal and vertical resolution so that the scale would change in portrait AND landscape mode.

Code: Select all

Monitor1Name := "LEN83900_00_07E5_39^2D4D23CBBB78410E152B60B08CE46715"
Monitor2Name := "LEN83910_00_07E5_23^2029384D70426D1FF5953C0B5EB562BB"

HorizontalPixels := 2880 ; Default horizontal resolution
VerticalPixels := 1800   ; Default vertical resolution

^+#S::
    Gui, Add, Text, , Choose DPI scale
    Gui, Add, Button, x10 y70 w100 h30, 150
    Gui, Add, Button, x120 y70 w100 h30, 175
    Gui, Add, Button, x10 y110 w100 h30, 200
    Gui, Add, Button, x120 y110 w100 h30, 225
    Gui, Show, w230 h150, Select
    Return

Button150:
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, 4294967294
    sleep, 1000
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, 4294967294
    ChangeResolution(HorizontalPixels, VerticalPixels)
	ChangeResolution(VerticalPixels, HorizontalPixels)
    Gui, Destroy
    Return

Button175:
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, 4294967295
    sleep, 1000
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, 4294967295
    ChangeResolution(HorizontalPixels, VerticalPixels)
	ChangeResolution(VerticalPixels, HorizontalPixels)
    Gui, Destroy
    Return

Button200:
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, 0
    sleep, 1000
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, 0
    ChangeResolution(HorizontalPixels, VerticalPixels)
	ChangeResolution(VerticalPixels, HorizontalPixels)
    Gui, Destroy
    Return

Button225:
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, 1
    sleep, 1000
    RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, 1
    ChangeResolution(HorizontalPixels, VerticalPixels)
	ChangeResolution(VerticalPixels, HorizontalPixels)
    Gui, Destroy
    Return

ChangeResolution(HorizontalPixels, VerticalPixels, Color_Depth := 32)
{
    VarSetCapacity(Device_Mode, 156, 0)
    NumPut(156, Device_Mode, 36)
    DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &Device_Mode)
    NumPut(0x5c0000, Device_Mode, 40)
    NumPut(Color_Depth, Device_Mode, 104)
    NumPut(HorizontalPixels, Device_Mode, 108)
    NumPut(VerticalPixels, Device_Mode, 112)
    Return DllCall("ChangeDisplaySettingsA", UInt, &Device_Mode, UInt, 0)
}
Return
You do not have the required permissions to view the files attached to this post.
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: AutoHotKey script to change DPI and resolution settings

Post by Tracker Supp-Stefan »

Hello MedBooster,

Once again - thanks for sharing the above! I am sure others will also find it useful.

Kind regards,
Stefan
MedBooster
User
Posts: 1070
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script to change DPI and resolution settings

Post by MedBooster »

Here's one where you can toggle one display at a time that I just made.

Code: Select all

Monitor1Name := "LEN83900_00_07E5_39^2D4D23CBBB78410E152B60B08CE46715"
Monitor2Name := "LEN83910_00_07E5_23^2029384D70426D1FF5953C0B5EB562BB"

HorizontalPixels := 2880 ; Default horizontal resolution
VerticalPixels := 1800 ; Default vertical resolution

; Define DPI values as variables
DPI_150 := 4294967294
DPI_175 := 4294967295
DPI_200 := 0
DPI_225 := 1

#^+D::
    Gui, Add, Text, , Choose DPI scale:
    Gui, Add, Button, x10 y30 w100 h30, 150
    Gui, Add, Button, x120 y30 w100 h30, 175
    Gui, Add, Button, x10 y70 w100 h30, 200
    Gui, Add, Button, x120 y70 w100 h30, 225
Gui, Add, Checkbox, checked vMonitor1Checked, Monitor 1
Gui, Add, Checkbox, checked vMonitor2Checked, Monitor 2
Gui, Show, , DPI
Return

	
Button150:
Gui, Submit, NoHide
If (Monitor1Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_150%
    }
If (Monitor2Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_150%
    }
    ChangeResolution(HorizontalPixels, VerticalPixels)
    ChangeResolution(VerticalPixels, HorizontalPixels)
	Sleep, 2000
    Gui Destroy 

    Return

Button175:
Gui, Submit, NoHide
If (Monitor1Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_175%
    }
    if Monitor2Checked {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_175%
    }
    ChangeResolution(HorizontalPixels, VerticalPixels)
    ChangeResolution(VerticalPixels, HorizontalPixels)
	Sleep, 2000
    Gui Destroy 

    Return

Button200:
Gui, Submit, NoHide
If (Monitor1Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_200%
    }
If (Monitor2Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_200%
    }
    ChangeResolution(HorizontalPixels, VerticalPixels)
    ChangeResolution(VerticalPixels, HorizontalPixels)
	Sleep, 2000
    Gui Destroy 

    Return

Button225:
Gui, Submit, NoHide
If (Monitor1Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_225%
    }
If (Monitor2Checked = 1) {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_225%
    }
    ChangeResolution(HorizontalPixels, VerticalPixels)
    ChangeResolution(VerticalPixels, HorizontalPixels)
	Sleep, 2000
    Gui Destroy 

    Return

ChangeResolution(HorizontalPixels, VerticalPixels, Color_Depth := 32) {
    VarSetCapacity(Device_Mode, 156, 0)
    NumPut(156, Device_Mode, 36)
    DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &Device_Mode)
    NumPut(0x5c0000, Device_Mode, 40)
    NumPut(Color_Depth, Device_Mode, 104)
    NumPut(HorizontalPixels, Device_Mode, 108)
    NumPut(VerticalPixels, Device_Mode, 112)
    Return DllCall("ChangeDisplaySettingsA", UInt, &Device_Mode, UInt, 0)
}
Return

Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8624
Joined: Wed Jan 03, 2018 6:52 pm

AutoHotKey script to change DPI and resolution settings

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1070
Joined: Mon Nov 15, 2021 8:38 pm

Re: AutoHotKey script to change DPI and resolution settings

Post by MedBooster »

A new one with a graphic user interface window.
image.png
Modify it to your liking and registry values

Code: Select all

; Unfortunately the script will not work if you use custom scaling (outside the drop-down values in display settings)
;paste this in the top address bar in your registry editor (it's always a good idea to make a backup in case you make any accidental changes
;HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings
;the monitor names will be folders under "PerMonitorSettings"

Monitor1Name := "LEN83900_00_07E5_39^2D4D23CBBB78410E152B60B08CE46715"
Monitor2Name := "LEN83910_00_07E5_23^2029384D70426D1FF5953C0B5EB562BB"
Monitor3Name := "PHLC18F1097_32_07E3_40^4203C09ED432516E76A46CD977B6C28C"
Monitor4Name := "SAM0FEE16780800_01_07E3_F3^64851249ACBD1ABA606D845F0AE08F5E"
Monitor5Name := "SAM0FEF16780800_01_07E3_F3^64CB94CC5380AAB18A1AD60DA6AEB890" ; Sam TV M

DPI_100_M1 := 4294967292
DPI_150_M1 := 4294967294
DPI_175_M1 := 4294967295
DPI_200_M1 := 0
DPI_225_M1 := 1
DPI_250_M1 := 3
;DPI_300_M1 := ; Define your DPI_300_M1 value here
;DPI_125_M1 := ; Define your DPI_125_M1 value here

DPI_100_M2 := 4294967292
DPI_150_M2 := 4294967294
DPI_175_M2 := 4294967295
DPI_200_M2 := 0
DPI_225_M2 := 1
DPI_250_M2 := 2
;DPI_300_M2 := ; Define your DPI_300_M2 value here
;DPI_125_M2 := ; Define your DPI_125_M2 value here

DPI_100_M3 := 4294967294
DPI_150_M3 := 0
DPI_175_M3 := 1
DPI_200_M3 := 2
DPI_225_M3 := 3
DPI_250_M3 := 4
;DPI_300_M3 := ; Define your DPI_300_M3 value here
;DPI_125_M3 := ; Define your DPI_125_M3 value here

DPI_100_M4 := 4294967294
DPI_150_M4 := 0
DPI_175_M4 := 1
DPI_200_M4 := 2
DPI_225_M4 := 3
DPI_250_M4 := 4
;DPI_300_M4 := ; Define your DPI_300_M4 value here
;DPI_125_M4 := ; Define your DPI_125_M4 value here

;DPI_100_M5 := ; Define your DPI_100_M5 value here
DPI_150_M5 := 4294967291
DPI_175_M5 := 4294967292
DPI_200_M5 := 4294967293
DPI_225_M5 := 4294967294
DPI_250_M5 := 4294967295
DPI_300_M5 := 0
;DPI_125_M5 := ; Define your DPI_125_M5 value here

#Persistent ; Make the script run continuously

; This needs to be outside the Gui code
Return

GuiEscape:
Gui, Cancel
return


#^+D:: ; Define a hotkey to trigger the DPI scaling change
Gui, Destroy ; This needs to be on the first line to avoid the error

; Start from y70
Gui, Add, Text, x10 y70, Choose DPI scale:
Gui, Add, Button, x10 y100 w120 h30, 100
Gui, Add, Button, x140 y100 w120 h30, 125
Gui, Add, Button, x10 y130 w120 h30, 150
Gui, Add, Button, x140 y130 w120 h30, 175
Gui, Add, Button, x10 y160 w120 h30, 200
Gui, Add, Button, x140 y160 w120 h30, 225
Gui, Add, Button, x10 y190 w120 h30, 250
Gui, Add, Button, x140 y190 w120 h30, 300

Gui, Add, Text, x10 y230, Select Monitors
Gui, Add, Checkbox, x10 y260 checked vMonitor1Checked, Monitor 1 YB9
Gui, Add, Checkbox, x140 y260 checked vMonitor2Checked, Monitor 2 YB9
Gui, Add, Checkbox, x10 y290 vMonitor3Checked, Monitor 3 Philips
Gui, Add, Checkbox, x140 y290 vMonitor4Checked, Monitor 4 VGA
Gui, Add, Checkbox, x10 y320 vMonitor5Checked, Monitor 5 TV

Gui, Add, Text, x10 y360, Change Primary Monitor
Gui, Add, Button, x10 y390 w120 h30 gMakePrimaryMonitor1, Display 1
Gui, Add, Button, x140 y390 w120 h30 gMakePrimaryMonitor2, Display 2
Gui, Add, Button, x10 y420 w120 h30 gMakePrimaryMonitor3, Display 3
Gui, Add, Button, x140 y420 w120 h30 gMakePrimaryMonitor4, Display 4


RegRead, RegReadM1DpiValue, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue
RegRead, RegReadM2DpiValue, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue
RegRead, RegReadM3DpiValue, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue
RegRead, RegReadM4DpiValue, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue
RegRead, RegReadM5DpiValue, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue

TranslateDPIM1andM2(RegReadM1DpiValue, translatedRegReadM1DpiValue)
TranslateDPIM1andM2(RegReadM2DpiValue, translatedRegReadM2DpiValue)
TranslateDPIM3(RegReadM3DpiValue, translatedRegReadM3DpiValue)
TranslateDPIM5(RegReadM5DpiValue, translatedRegReadM5DpiValue)

Gui, Add, Text, x10 y10 h20 vDPIM1RegRead, M1 DPI: %translatedRegReadM1DpiValue%
Gui, Add, Text, x150 y10 h20 vDPIM2RegRead, M2 DPI: %translatedRegReadM2DpiValue%
Gui, Add, Text, x10 y40 h20 vDPIM3RegRead, M3 DPI: %translatedRegReadM3DpiValue%
Gui, Add, Text, x150 y40 h20 vDPIM5RegRead, M5 DPI: %translatedRegReadM5DpiValue%

Gui, Show, , DPI scale ; This is the name of the GUI Window
Gui, +AlwaysOnTop
Return





MakePrimaryMonitor1:
{
Gui, Submit, NoHide
Run, nircmd setprimarydisplay 1

Return
}

MakePrimaryMonitor2:
{
Gui, Submit, NoHide
Run, nircmd setprimarydisplay 2

Return
}
MakePrimaryMonitor3:
{
Gui, Submit, NoHide
Run, nircmd setprimarydisplay 3

Return
}
MakePrimaryMonitor4:
{
Gui, Submit, NoHide
Run, nircmd setprimarydisplay 4

Return
}
Button100:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_100_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_100_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_100_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_100_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_100_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button150:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_150_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_150_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_150_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_150_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_150_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button175:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_175_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_175_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_175_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_175_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_175_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button200:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_200_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_200_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_200_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_200_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_200_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button225:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_225_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_225_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_225_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_225_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_225_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button250:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_250_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_250_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_250_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_250_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_250_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}
Button125:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_125_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_125_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_125_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_125_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_125_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}

Button300:
{
    Gui, Submit, NoHide
    if (Monitor1Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor1Name%, DpiValue, %DPI_300_M1%
    }
    else if (Monitor2Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor2Name%, DpiValue, %DPI_300_M2%
    }
    else if (Monitor3Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor3Name%, DpiValue, %DPI_300_M3%
    }
    else if (Monitor4Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor4Name%, DpiValue, %DPI_300_M4%
    }
    else if (Monitor5Checked = 1)
    {
        RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\%Monitor5Name%, DpiValue, %DPI_300_M5%
    }
    UpdateScale(32)
    Sleep, 2000
    Gui Destroy
    Return
}



UpdateScale(Color_Depth) {
    VarSetCapacity(Device_Mode, 156, 0)
    NumPut(156, Device_Mode, 36)
    DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &Device_Mode)
    NumPut(0x5c0000, Device_Mode, 40)
    NumPut(Color_Depth, Device_Mode, 104)
    Return DllCall("ChangeDisplaySettingsA", UInt, &Device_Mode, UInt, 0)
}
Return

; Translate function to map raw DPI values to readable values
TranslateDPIM1andM2(rawDPI, ByRef translatedDPI) {
    if (rawDPI = 4294967294)
        translatedDPI := "150"
    else if (rawDPI = 4294967295)
        translatedDPI := "175"
    else if (rawDPI = 0)
        translatedDPI := "200"
    else if (rawDPI = 1)
        translatedDPI := "225"
    else if (rawDPI = 2)
        translatedDPI := "225"
    else if (rawDPI = 3)
        translatedDPI := "250"
	else if (rawDPI = 4294967292)
		translatedDPI := "100"

}

Return


; Translate function to map raw DPI values to readable values
TranslateDPIM3(rawDPI, ByRef translatedDPI) {
    if (rawDPI = 4294967292)
        translatedDPI := "100"
    else if (rawDPI = 0)
        translatedDPI := "150"
    else if (rawDPI = 1)
        translatedDPI := "175"
    else if (rawDPI = 2)
        translatedDPI := "200"
    else if (rawDPI = 3)
        translatedDPI := "225"
    else if (rawDPI = 4)
        translatedDPI := "250"

}

Return

; Translate function to map raw DPI values to readable values
TranslateDPIM5(rawDPI, ByRef translatedDPI) {
    if (rawDPI = 4294967290)
        translatedDPI := "100"
    else if (rawDPI = 4294967291)
        translatedDPI := "150"
    else if (rawDPI = 4294967292)
        translatedDPI := "175"
    else if (rawDPI = 4294967293)
        translatedDPI := "200"
    else if (rawDPI = 4294967294)
        translatedDPI := "225"
    else if (rawDPI = 4294967295)
        translatedDPI := "250"
    else if (rawDPI = 0)
        translatedDPI := "300"

}

Return

You do not have the required permissions to view the files attached to this post.
Wishlist
Bookmarks with page numbers
Optional fixed small icon size in the toolbar
Shift to UNLOCK aspect ratio/i]
Allow more "toolbars" to the title bar
AltGr issues with character input and keyboard shortcuts
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: AutoHotKey script to change DPI and resolution settings

Post by Tracker Supp-Stefan »

Hello MedBooster,

Many thanks once again for sharing this with everyone else! I am sure others will find it as useful as it is for yourself!

Kind regards,
Stefan