How do I prevent GetSystemMetrics() in Python using a Windows PC from returning different/wrong values?

2k views Asked by At

I'm using this bit of code to get a print out of the monitor resolution from a Surface Pro 1st Gen Win 8.1 PC using Python 2.7:

   import ctypes
   from ctypes import windll
   user32 = ctypes.windll.user32
   screensize = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
   print "Screensize:", screensize

But the problem is that I get different results based on running it through command prompt versus running the script through the Python shell.

Just running the script I get 1280x720, but through the IDLE Shell I get 1920x1080.

Now, since I'm running this on a Surface Pro, I'm almost certain that this has something to do with DPI scaling (someone brought up a similar problem here). If this is the case, then it must be because DPI scaling has been disabled for Python IDLE.

So how do I prevent this from happening so that I get consistent and accurate results when I run this code, regardless of how it's run or what kind of machine is running it or whether DPI scaling has been disabled or not? Maybe CEF Python?

Any help is much appreciated. Thank you.

1

There are 1 answers

1
Roger Lipscombe On

If you want monitor info, call GetMonitorInfo.