Is there a way to change monitor orientation using Python on Windows?

131 views Asked by At

Every time I turn my monitor I have to go in the settings, any way to automate the changing of the screen orientation in Python? I'm on Windows 10.

I have tried using the shortcut (ctrl alt right) but that doesn't work.

This is something ChatGPT came up with:

from screeninfo import get_monitors
import subprocess

def rotate_screen():
    # Get information about all monitors
    monitors = list(get_monitors())

    # Assuming the second monitor is the one you want to rotate
    if len(monitors) > 1:
        subprocess.run(["DisplaySwitch.exe", "/rotate:90"])

if __name__ == "__main__":
    rotate_screen()

displayswitch is for selecting how to mirror your screen to a second screen

1

There are 1 answers

0
J_dev_J On

you can use Display64.exe then the following code can be used.

import subprocess
subprocess.run(['C:\\Users\\User\\Display64.exe','/device:2','/rotate:90','/toggle'])

more info can be found here and here