Page 1 of 1

Change display resolution and scaling

Posted: 02 Jul 2019, 07:38
by Feleq
Hi everyone. I'm using the script below to quickly switch my Surface Book 2 display's resolution from 3240x2160 to 1620x1080 and back, with Win+Alt+PgDn and Win+Alt+PgUp. Can you please help me to also switch from 200% scaling to 100% with this?

I have almost zero experience with scripts and coding in general: I just found this script online and replaced the hotkeys.

I've added the custom 1620x1080 resolution with CRU (Custom Resolution Utility) tool.

The main reason I'm using this is gaming: I'm using full resolution when working, but I switch to half resolution when gaming to increase performance. This script saves me a lot of clicks through Display settings.

What I want the script to do:

- Press Win+Alt+PgDn to set main display resolution to 1620x1080 and scaling to 100%.
- Press Win+Alt+PgUp to set main display resolution to 3240x2160 and scaling to 200%.

System info: MS Surface Book 2 15, Windows 10. I'm not using any external monitors.

Thank you!

Code: Select all

!#PgDn::
ChangeResolution(1620, 1080)
Return

!#PgUp::
ChangeResolution(3240, 2160)
Return

ChangeResolution(Screen_Width := 3240, Screen_Height := 2160, 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(Screen_Width,Device_Mode,108)
	NumPut(Screen_Height,Device_Mode,112)
	Return DllCall( "ChangeDisplaySettingsA", UInt,&Device_Mode, UInt,0 )
}
Return

Re: Change display resolution and scaling

Posted: 02 Jul 2019, 12:04
by Feleq
OK, I guess I figured this out. At least this is working for me...

Did some heavy googling, found the registry key for screen DPI setting, switched from 200% to 100% ad back to get the registry values, and came up with this wonder. Let me know how this can be improved.

Code: Select all

!#PgDn::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\LGD0554218103969_00_07E0_61^6BEFCEEC5FDCA6002942DAAC6BD795F2, DpiValue, 4294967292
ChangeResolution(1620, 1080)
Return

!#PgUp::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\LGD0554218103969_00_07E0_61^6BEFCEEC5FDCA6002942DAAC6BD795F2, DpiValue, 0
ChangeResolution(3240, 2160)
Return

ChangeResolution(Screen_Width := 3240, Screen_Height := 2160, 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(Screen_Width,Device_Mode,108)
	NumPut(Screen_Height,Device_Mode,112)
	Return DllCall( "ChangeDisplaySettingsA", UInt,&Device_Mode, UInt,0 )
}
Return

Re: Change display resolution and scaling

Posted: 27 May 2020, 11:03
by wyatterp
I know this is an older post - but I'm wondering if you refined this at all over the last year.

I want to create a script to switch between my one monitor's native resolution, and then when I connect via Splashtop from my ipad pro 12.9 to set the resolution to the ipad's native rez, and then change scaling to 200%.

Right now, my research is that scaling values are not absolute, even when you call the registry setting here - they seem to be incremental. With the script below, I can toggle to IPP native rez, and 60hz. First time I toggle it, it will jump to 150% scaling, then I can hit the hotkey again to bump up to 200%. It won't go higher than 200%.

When I quit splashtop remote session, I can sit down at my computer and hit the hotkey combo twice to restore it to 1440P and 100% scaling. Again, it takes two calls of the script to get to the scaling I desire. I'm trying to figure out how to automate this as putting in different values for the DPIVALUE do not really seem to result in any absolute jumps to a specific scaling factor. For example, if I use 4 when jumping to the ipad pro rez - it will actually jump to 250%. Right now -2 and 2 on DPIVALUE work ok, just takes two toggles of the hotkey. I'm going to keep working on it- probably just repeat the regedit call twice on hotkey toggle? However, it would be much nicer if there was just a way to set an absolute scaling value. <br/>

Code: Select all

</i>#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

^[::
ChangeResolution(32,2560, 1440,95)
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, -3
; RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\GraphicsDrivers\ScaleFactors\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, -1
Return

^]::
ChangeResolution(32,2732,2048,60)
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 2
; RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\GraphicsDrivers\ScaleFactors\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 3
Return

ChangeResolution( cD, sW, sH, rR ) 
{ 
	VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36) 
	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), 
	NumPut(0x5c0000,dM,40) NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120) 
	Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 ) 
	}

Re: Change display resolution and scaling

Posted: 27 May 2020, 11:11
by wyatterp
Well, that was simple, I just put the regedit command before calling the changeresolution routine and now it seems to work much better. I set before 1440P rez to set DPIVALUE to zero, and then 2 for ipad pro native rez. Works like a champ.

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

^[::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 0
ChangeResolution(32,2560,1440,95)
Return

^]::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 2
ChangeResolution(32,2732,2048,60)
Return

ChangeResolution( cD, sW, sH, rR ) 
{ 
	VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36) 
	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), 
	NumPut(0x5c0000,dM,40) NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120) 
	Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 ) 
	}

Re: Change display resolution and scaling

Posted: 18 Feb 2021, 15:42
by porkpie2021
Thanks for posting updates to your script. I am trying to do something similar and this was very helpful.

Re: Change display resolution and scaling

Posted: 19 Nov 2022, 07:37
by TonyGwhak
wyatterp wrote:
27 May 2020, 11:11
Well, that was simple, I just put the regedit command before calling the changeresolution routine and now it seems to work much better. I set before 1440P rez to set DPIVALUE to zero, and then 2 for ipad pro native rez. Works like a champ.

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

^[::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 0
ChangeResolution(32,2560,1440,95)
Return

^]::
RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\WAM27000_01_07E3_75^5C7D7FCD16ED5791FB8067EEC72B6B69, DpiValue, 2
ChangeResolution(32,2732,2048,60)
Return

ChangeResolution( cD, sW, sH, rR ) 
{ 
	VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36) 
	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ), 
	NumPut(0x5c0000,dM,40) NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120) 
	Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 ) 
	}
hey what is the key combo to switch the displays? i replaced the regkey with my own and changed the resolution but cant figure out how to get it working with waht keys to press to switch displays? thanks!