0

Is there a way to change the screen orientation using python? On Ubuntu I can evoke xrandr through the os library, but what about Windows? I want to rotate the screen as a whole (as if the user pressed "ctrl+alt+down/right/left") and not just the app window. Although I'm asking for python, I can accept answers on other languages too (C++, JS, C#) as long as there is a way to do it on both, Linux and Windows (even if it is through a terminal call).

Samuel
  • 378
  • 1
  • 9

1 Answers1

1

Rotating the screen using C# - Rotating the display programmatically?

If you wanted to use Python, you could use the ctypes library to execute C functions - https://www.journaldev.com/31907/calling-c-functions-from-python. Just follow the logic from the C# example and re-create it in Python.

The key here is that there are c functions that you need to invoke to actually rotate the screen, primarily ChangeDisplaySettingsExa - https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changedisplaysettingsexa

Ryan Comer
  • 11
  • 2
  • 1
    Could you give me an example on how to use ChangeDisplaySettingsExA ? I didn't understand how I could use it to rotate the screen like the C# example. – Samuel Jul 23 '20 at 16:58
  • FYSA link-only answers are frowned upon on S/O, next time give some code examples to supplement your links :) – Aaron Meese Nov 01 '22 at 12:58