6

I have a 14" 1920×1080 laptop and a 24" 1920×1200 screen. The pixel density difference is huge.

When I'm using the large screen as a main one and laptop as an additional screen, I'd like to have the smaller one set to 150% scaling so that I can use it comfortably. But when I'm away from my desk and the external screen is disconnected, I'd like the laptop to automatically switch to 100% scaling to maximize desktop area.

How can I make Windows switch DPI scaling automatically when external screens are connected or disconnected?

I'm okay with using 3rd party software if it's necessary, but I'd rather stick to built-in features of Windows.

I'm using Windows 10 Pro Version 1703.

gronostaj
  • 55,965
  • 20
  • 120
  • 179
  • I don't think there is any Windows feature to do what you want. How badly do you want it? You *might* be able to do something with powershell, but it will likely be monstrously over complicated. – ben_re Jul 17 '17 at 18:42
  • 1
    @lifesaspanner Well, I've priced my need for it at 50 reputation points paid with a bounty ;) It could be useful for me, but I don't have a burning need for it. – gronostaj Jul 17 '17 at 19:04
  • @gronostaj I'm currently working on a similar project using batch files to call powershell scripts, but mine concerns monitor brightness. I should have it nailed down by early next week, so if there isn't an answer at that point I will at least share my research and process with you. This should absolutely be able to be done through powershell, but it will be a pain in your behind. – jcam3 Jul 19 '17 at 14:10
  • @jcam3 That may be interesting to look at! If that's of any use to you, [ScreenBright](http://www.softpedia.com/get/Desktop-Enhancements/Other-Desktop-Enhancements/ScreenBright.shtml) can control screen brightness of external displays via DDC/CI and has command-line interface. I'm using it with [SE-TrayMenu](http://se-soft.com/lang/en/) to control brightness from the notification area. – gronostaj Jul 19 '17 at 14:21
  • 1
    @gronostaj I'll have to take a closer look at that application, looks interesting. What I'm trying to do is basically a 3-5 second brightness reduction looped every 20 minutes or so. The idea is to have an automatic non-intrusive reminder to take a screen break now and then for eye strain relief. Has potential for a pomodoro-style application too, but have to get it working first. – jcam3 Jul 19 '17 at 14:39
  • Downvoter, please explain what's wrong with this question. – gronostaj Jul 21 '17 at 07:00
  • @glx .... If you're open to 3rd party, check out https://www.displayfusion.com/Compare/ and download if the free version sounds like it'd do it. Otherwise, this may be possible using a script that runs on events such as monitor connection/disconnection, but it's more complex and requires some knowledge of scripting. I don't have anything at the moment and not sure if the 2017 link to the function script works or not. From what I gather, DisplayFusion should do what you ask after configuration, when you connect or disconnect the external monitor, it'll auto change the DPI scaling on the laptop – Vomit IT - Chunky Mess Style Jan 30 '23 at 04:03
  • My answer below is a bit too late for your bounty but can perhaps still provide some happiness... – jan-glx Jun 28 '23 at 22:32

3 Answers3

1

You can't change DPI scaling automatically because it requires you to logoff and logon.

Here's a good thread on using powershell to set the DPI registry key and toggle back and forth between two DPIs a little quicker. You still have to logoff, and the script automates that.

https://stackoverflow.com/questions/10365394/change-windows-font-size-dpi-in-powershell

If you want to expand on this, here is information about reading monitor information with Powershell: https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/

And, here is information about changing the registry key of a specific user. This will be needed because if you run your script while you are not logged on, or during startup your registry hive will not be loaded. https://www.pdq.com/blog/modifying-the-registry-of-another-user/

Combine it all together with some ingenuity and you could schedule this script to run on logoff and on computer startup. The tricky part is that you will always have to be doing a new logon to get the new settings to take effect and to me, that is the biggest drawback about this.

Now, a better solution might be to change the actual display resolution which can be done without logging off: https://blogs.technet.microsoft.com/heyscriptingguy/2010/07/07/hey-scripting-guy-how-can-i-change-my-desktop-monitor-resolution-via-windows-powershell/

A lot of programs do not function properly with a non-standard DPI, and so if you ask me, changing the display resolution is a better solution.

So there you have it. All the resources to create your new script to automate this. Now you can see if you can get anybody over at http://stackoverflow.com to help you with it. :)

Appleoddity
  • 11,565
  • 2
  • 24
  • 40
  • 3
    “You can't change DPI scaling automatically because it requires you to logoff and logon.” That’s no longer true. It only applies to legacy scaling. Windows 10 can change scaling on the fly. – Daniel B Jul 22 '17 at 17:44
  • Sorry but you are wrong about this. Windows always adjusts the DPI but then indicates you have to sign-out to complete the change. Try it, you'll see. Just confirmed it myself on Windows 10. – Appleoddity Jul 22 '17 at 18:15
  • 5
    More specifically, the message reads: “Some apps won’t respond to scaling until you sign out.” – And that’s how it is. It scales instantly. Most programs respond correctly. Few do not. – Daniel B Jul 22 '17 at 18:46
  • Fair enough. But, I have been unable to locate an API to modify DPI and I am only assuming it is because of the requirement to logoff and logon (even if only for certain apps) and the incompatibility that some programs do exhibit. – Appleoddity Jul 23 '17 at 18:01
  • Logging off is not an option for me, it would interrupt my workflow. I want DPI to change seamlessly when screen setup changes. – gronostaj Jul 25 '17 at 08:50
  • I've just installed a 4k display (as a 2nd monitor to an old laptop that I didn't even think was able to drive it) for the first time. Windows 10 will let me update the DPI setting for this monitor and it updates right away. But for the laptop screen it gives me a warning message. Still puzzled. – Simon Jun 04 '18 at 08:04
0

Here is how to do it.

Create a myswitch.bat text file like this one:

@echo off

:: Check if an external monitor is connected
wmic path Win32_DesktopMonitor get Availability | findstr /C:"2"

if %errorlevel%==0 (
   :: External monitor is connected, set scaling to 150%
   control.exe /name Microsoft.Display /page pageDPI
   control.exe /name Microsoft.Display /page pageAdvancedSettings /cmd ChangeDPI 150
) else (
   :: External monitor is not connected, set scaling to 100%
   control.exe /name Microsoft.Display /page pageDPI
   control.exe /name Microsoft.Display /page pageAdvancedSettings /cmd ChangeDPI 100
)
  • Open the task scheduler.

  • Add a task:

     General tab:
     Name: "DPI Switch"
     User Account: select "Administrator"
    
     Triggers tab:
     New:
     Begin the task: "On an event"
     Log: "System"
     Source: "Display"
     Event ID: "10" (for display connect) or "11" (for display disconnect)
     New:
     Begin the task: "On an event"
     Log: "System"
     Source: "Display"
     Event ID: "11" (for display disconnect) or "10" (for display connect)
    
     Actions tab:
     New:
     Action: "Start a program"
     Program/script: enter the path to the "myswitch.bat" file, e.g. C:\Users\<username>\Documents\myswitch.bat
    

Click OK and voila.

supercobra
  • 166
  • 1
  • 3
  • This seems to just open the correct settings dialogue but not change anything? I am on Windows 11 Pro 21H2 22000.1455. Sry about the bounty, I was quite ill last week, will create another if this turns out working. – jan-glx Feb 04 '23 at 13:17
  • This could be combined with [darwish's answer](https://superuser.com/a/1649336/177522) – jan-glx Jun 28 '23 at 22:17
0

dpiSwitcher

... is a small .exe that you can dowload/install & forget about but that will automagically fix your internal monitors dpi-scaling just the way you like it whenever you are without/back with your external monitor(s).

I wrote dpiSwitcher based on imniko's work and more importantly Sahil Singh's work (See also this answer).

jan-glx
  • 347
  • 5
  • 14