Page 1 of 2

Is there really no way to set screen orientation in modern Windows 10?

Posted: 28 Feb 2021, 08:46
by zeech
Hi, trying to write a script that will toggle my display between portrait and landscape, but it seems like all the old methods don't work anymore on my Win 10 Home? Using AHK_L v1.1.33.02.
The old fashioned Ctrl+Alt+Arrow hotkeys don't work anymore.

This code didn't work for me. It's apparently NVIDIA only, but it didn't work on my Nvidia device either. (The device I'm targeting has Intel IRIS Plus graphics, though.)
https://autohotkey.com/board/topic/20851-changedisplayorientation/


The other methods rely on a windows API call to "User32.dll\ChangeDisplaySettings".
https://www.autohotkey.com/boards/viewtopic.php?t=51447


However, looking at MS's docs, display orientation is not an available field?
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changedisplaysettingsa


Any help would be much appreciated, thanks!

Re: Is there really no way to set screen orientation in modern Windows 10?  Topic is solved

Posted: 28 Feb 2021, 12:33
by malcev
All works like it should.

Code: Select all

VarSetCapacity(DEVMODE, 220, 0)
NumPut(220, DEVMODE, 68, "short")   ; dmSize
DllCall("EnumDisplaySettingsW", "ptr", 0, "int", -1, "ptr", &DEVMODE)
width := NumGet(DEVMODE, 172, "uint")
height := NumGet(DEVMODE, 176, "uint")
NumPut(width, DEVMODE, 176, "int")
NumPut(height, DEVMODE, 172, "int")
NumPut(DMDO_90 := 1, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
sleep 2000
NumPut(width, DEVMODE, 172, "int")
NumPut(height, DEVMODE, 176, "int")
NumPut(DMDO_DEFAULT := 0, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 28 Feb 2021, 17:29
by BoBo
@malcev - Any idea why I can't make it rotating 180°/270°, while with 90° it isn't rotating clockwise but counter-clockwise?? :think:

Code: Select all

;  'scr(een)Rotate'-function based on code kindly provided by malcev:
;	https://www.autohotkey.com/boards/viewtopic.php?p=384743#p384743
;	Params ...
;		clock mode:	3/6/9/12
;		angle degree:	0/90/180/270/360
;		direction:		t/r/b/l

F1::scrRotate(3)			; rotating to 3 o'clock
F2::scrRotate(180)			; rotating 180°
F3::scrRotate(9)			; rotating to 9 o'clock
F4::scrRotate(360)			; rotating 360° (default)
F5::scrRotate("b")			; rotating towards the bottom of the screen
F6::scrRotate("default")	; rotating to default position (12 o'clock AKA 360°/0° AKA 'top')
F7::scrRotate("d")			; rotating to d(efault) position (12 o'clock AKA 360°/0° AKA 'top')
F8::scrRotate()				; throwing 'parameter advise'-message.

scrRotate(param:="") {
	if param not in 0,3,6,9,12,90,180,270,360,default,d,t,r,b,l
		MsgBox % "Valid parameters are: 0,3/6/9/12/90/180/270/360/default/d/t/r/b/l"
	else {
		mode:=	(param=0) || (param=12)  || (param=360) || (param=t)?	DMDO_DEFAULT:=0
			:	(param=9) || (param=90)	 || (param=r)				?	DMDO_90		:=1 
			:	(param=6) || (param=180) || (param=b)				?	DMDO_180	:=2
			:	(param=3) || (param=270) || (param=l)				?	DMDO_270	:=3
			:	(param=default)										?	DMDO_DEFAULT:=0
			:	(param=d)											?	DMDO_DEFAULT:=0
		VarSetCapacity(DEVMODE, 220, 0)
		NumPut(220, DEVMODE, 68, "short")										; dmSize
		DllCall("EnumDisplaySettingsW", "ptr", 0, "int", -1, "ptr", &DEVMODE)

		width	:= NumGet(DEVMODE, 172, "uint")
		height	:= NumGet(DEVMODE, 176, "uint")

		NumPut(width, DEVMODE, 176, "int")
		NumPut(height, DEVMODE, 172, "int")
		NumPut(mode, DEVMODE, 84, "int")										; dmDisplayOrientation
		DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
		}
	}
Code edited after @malcev's advise below. Tested. :thumbup:

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 28 Feb 2021, 18:15
by malcev
I dont understand Your code, but it should be like this:

Code: Select all

VarSetCapacity(DEVMODE, 220, 0)
NumPut(220, DEVMODE, 68, "short")   ; dmSize
DllCall("EnumDisplaySettingsW", "ptr", 0, "int", -1, "ptr", &DEVMODE)
width := NumGet(DEVMODE, 172, "uint")
height := NumGet(DEVMODE, 176, "uint")

NumPut(width, DEVMODE, 176, "int")
NumPut(height, DEVMODE, 172, "int")
NumPut(DMDO_90 := 1, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
sleep 2000

NumPut(width, DEVMODE, 172, "int")
NumPut(height, DEVMODE, 176, "int")
NumPut(DMDO_180 := 2, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
sleep 2000

NumPut(width, DEVMODE, 176, "int")
NumPut(height, DEVMODE, 172, "int")
NumPut(DMDO_270 := 3, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)
sleep 2000

NumPut(width, DEVMODE, 172, "int")
NumPut(height, DEVMODE, 176, "int")
NumPut(DMDO_DEFAULT := 0, DEVMODE, 84, "int")   ; dmDisplayOrientation
DllCall("ChangeDisplaySettingsW", "ptr", &DEVMODE, "uint", 0)

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 28 Feb 2021, 23:55
by BoBo
Thx mate :) Much appreciated :wave:

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 15 Mar 2021, 07:55
by zeech
malcev wrote:
28 Feb 2021, 12:33
All works like it should.
Thanks! It works! \o/

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 02 Feb 2022, 17:56
by Kitsoon
I'm asking for alot, but is there a way to set parameters for rotating 2nd display with this?

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 05 May 2022, 15:25
by katrielf
I too would be very grateful for guidance on how to modify this script so it changed the secondary monitor's display settings (and not the first).

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 21 May 2022, 15:19
by blauwblokje
For some reason when I use these they set my screen brightness really low. Does anyone know how to fix that?

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 24 Nov 2022, 12:47
by MedBooster
Any ideas on how to maybe make this script work on multiple displays? Perhaps working in the display the cursor is in (instead of the current way it only affects the main (primary) display)

Here's some ideas

Code: Select all

MWAGetMonitorMouseIsIn() { ; By "Maestr0" ~ https://www.autohotkey.com/boards/viewtopic.php?t=54557
  Coordmode, Mouse, Screen
  MouseGetPos, Mx, My
  SysGet, MonitorCount, 80
  Loop, %MonitorCount% {
    SysGet, mon%A_Index%, Monitor, %A_Index%
    if (Mx >= mon%A_Index%left) && (Mx < mon%A_Index%right)
    && (My >= mon%A_Index%top) && (My < mon%A_Index%bottom) {
      ActiveMon := A_Index
      break
    }
  }
  Return ActiveMon
}
to perhaps get the monitor the cursor is in

maybe this as a function

Code: Select all

ScreenResolution_Set(WxHaF, Disp:=0, orientation:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13 and CloakerSmoker
    Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
    Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",NumPut(F[3],NumPut(F[2],NumPut(F[1],NumPut(32,NumPut(0x5C0080,NumPut(220,NumPut(orientation,DM,84,"UInt")-20,"UShort")+2,"UInt")+92,"UInt"),"UInt"),"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)  
}

but I have no idea how to run the script, or use the one that is already here – I just can't see where the display is specified in the script

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 24 Nov 2022, 20:37
by [+]
@Kitsoon
@katrielf
@MedBooster
Use this script and tweak the Disp variable for alternate displays.
viewtopic.php?t=85527
https://github.com/Masonjar13/RotateScreen/blob/main/screen%20rotate.ahk
Identify display number for Disp w/ ScreenResolution_List:
viewtopic.php?t=77664

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 25 Nov 2022, 00:11
by [+]
[+] wrote:
24 Nov 2022, 20:37
Identify display number for Disp w/ ScreenResolution_List:
viewtopic.php?t=77664
Sorry. Identify MonitorName for Disp via SysGet as specified in the same linked thread:
https://www.autohotkey.com/docs/commands/SysGet.htm#MonitorName

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 25 Nov 2022, 10:54
by MedBooster
@[+]

change the disp as in the ``Disp:=0``''s or

the script you shared also works well, BUT I switched out "\.\DISPLAY1" with ".\DISPLAY" MWAGetMonitorMouseIsIn() and it did nothing.

At this point I'm just using both scripts, since for some reason the script you shared always changes the rotation of my laptop screen (even if it is not the primary display)
and the original one of this post changes the primary screen orientation montitor

So I'm just using both with slightly different keyboard shortcuts.

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 25 Nov 2022, 13:25
by MedBooster
vieira on the autohotkey discord came up with this, so maybe it helps if anyone sees how to add it if it actually is as simple as replacing the ".\DISPLAY1" .

This is what I got so far, but it is not working . Might have something to do with function outputs before adding a string prefix

Code: Select all

#singleInstance force
#noEnv


;Usage instructions below 

;GetActiveMonitorName("Point") -> Uses the mouse location
;GetActiveMonitorName("Point", [1921, 1]) -> Uses the provided coordinates
;GetActiveMonitorName("Window") -> Uses the active window
;GetActiveMonitorName("Rect", [1921, 1, 1951, 10]) -> Uses the provided rectangle coordinates


;By Vieira se usage instructions above

GetActiveMonitorName(method := "Window", coords := "", default_to := "Nearest") {
    static default := {"Null": MONITOR_DEFAULTTONULL := 0x0, "Primary": MONITOR_DEFAULTTOPRIMARY := 0x1, "Nearest": MONITOR_DEFAULTTONEAREST := 0x2}
    If (method = "Window")
        hMonitor := DllCall("MonitorFromWindow", "UInt", WinExist("A"), "UInt", default[default_to], "Ptr")
    Else if (method = "Point") {
        if coords
            x := coords[1], y := coords[2]
        Else
            MouseGetPos, x, y
        hMonitor := DllCall("MonitorFromPoint", "Int64", x | y << 32, "UInt", default[default_to], "Ptr")
    }
    Else if (method = "Rect") {
        if !coords
            Throw % "Rect method requires coordinates"
        VarSetCapacity(RECT, 16, 0)
        NumPut(coords[4], NumPut(coords[3], NumPut(coords[2], NumPut(coords[1], &RECT, "UInt"), "UInt"), "UInt"), "UInt")
        hMonitor := DllCall("MonitorFromRect", "Ptr", &RECT, "UInt", default[default_to], "Ptr")
    }
    Else
        Throw % "Invalid method"
    NumPut(VarSetCapacity(MONITORINFOEX, 40 + (32 << !!A_IsUnicode)), MONITORINFOEX, 0, "UInt")
    DllCall("GetMonitorInfoW", "Ptr", hMonitor, "Ptr", &MONITORINFOEX)
    return StrGet(&MONITORINFOEX + 40, 32)
}

display := "\.\"GetActiveMonitorName("Window")
lookup:={"^!down":[0,0],"^!right":[1,1],"^!up":[2,0],"^!left":[3,1]}
return



^!down::
^!right::
^!up::
^!left::

if (lookup[a_thisHotkey][2]){ ; rotating to portrait
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] < sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
} else { ; rotating to landscape
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] > sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
 }
screenRes_Set(cRes,display,lookup[a_thisHotkey][1])
return

screenRes_Set(WxHaF, Disp:=0, orient:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13
	Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
	Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",NumPut(F[3],NumPut(F[2],NumPut(F[1]
	,NumPut(32,NumPut(0x5C0080,NumPut(220,NumPut(orient,DM,84,"UInt")-20,"UShort")+2,"UInt")+92,"UInt"),"UInt")
	,"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)  
}
screenRes_Get(Disp:=0) {              ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
	Local DM, N:=VarSetCapacity(DM,220,0) 
	Return DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",-1, "Ptr",&DM)=0 ? ""
		: Format("{:}x{:}@{:}", NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt")) 
}

Here I compare it to the actually working code *see attachment 1
image.png
image.png (1.42 MiB) Viewed 2905 times

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 25 Nov 2022, 15:44
by [+]
MedBooster wrote:
25 Nov 2022, 10:54
@[+]
for some reason the script you shared always changes the rotation of my laptop screen (even if it is not the primary display)
and the original one of this post changes the primary screen orientation montitor
Yep, that's the difference between WinAPI function each script calls. @malcev's script uses ChangeDisplaySettingsW while @Masonjar13's script uses ChangeDisplaySettingsExW. The W variant only changes the settings of the default display device while the ExW variant allows a specific display device to be chosen via lpszDeviceName.

If you unfurl the condensed code in ExW version's functions, you'll get something like the following:

Code: Select all

screenRes_Set(WxHaF, Disp:=0, orient:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13
	Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
	NumPut(orient,DM,84,"UInt")
	NumPut(220,DM,68,"UShort")
	NumPut(0x5C0080,DM,72,"UInt")
	NumPut(32,DM,168,"UInt")
	NumPut(F[1],DM,172,"UInt")
	NumPut(F[2],DM,176,"UInt")
	NumPut(F[3],DM,184,"UInt")
	Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",&DM, "Ptr",0, "Int",0, "Int",0)  
}
which defines a new DEVMODE structure (variable DM here) each time as opposed to W's version pulling the default display's DEVMODE and modifying some values to it. You can choose to pass a DEVMODE into ExW in either way, though, and your GetActiveMonitorName looks promising enough so you can just pass that as Disp into screenRes_Set. If there's an error, it should only be because your function returns an unintended monitor name; make sure its return value is in the format that ChangeDisplaySettingsExW wants, e.g. \\.\DISPLAY1.

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 26 Nov 2022, 16:20
by MedBooster
I have no idea how to "pass that as Disp into screenRes_Set" :(

:crazy:

I get that we should be using Masonjar13's ChangeDisplaySettingsExW script, but not how we could input the display := "\.\"GetActiveMonitorName("Window")
(if that is even valid formatting)

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 26 Nov 2022, 16:55
by MedBooster
as an alternative, we could maybe also tweak one of the scripts to have two different keyboard shortcuts for let's say Display1 vs. Display 2, if they are just named according to the number they have in the windows display settings.
(To those of you interested in this kind of script)

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 26 Jan 2023, 09:31
by MedBooster
FINALLY FINALLY FINALLY, this has been bugging me for months.
Here you go guys, the script rotates the display your cursor is currently in.

Code: Select all

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

;help received by [+] https://www.autohotkey.com/boards/viewtopic.php?f=76&t=87453&p=492976&sid=643f7444d745cc540978272aece7091f#p492976


#singleInstance force
#noEnv


;put together by MedBooster thank you to everyone that helped!

;the rotation code by masonjar13 ChangeDisplaySettingsExW down below edited in get active monitor down below 




lookup:={"^!down":[0,0],"^!right":[1,1],"^!up":[2,0],"^!left":[3,1]}
return

^!down::
^!right::
^!up::
^!left::

display := GetMonitorName("Point")


if (lookup[a_thisHotkey][2]){ ; rotating to portrait
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] < sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
} else { ; rotating to landscape
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] > sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
 }
screenRes_Set(cRes,display,lookup[a_thisHotkey][1])
return

screenRes_Set(WxHaF, Disp:=0, orient:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13
	Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
	Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",NumPut(F[3],NumPut(F[2],NumPut(F[1]
	,NumPut(32,NumPut(0x5C0080,NumPut(220,NumPut(orient,DM,84,"UInt")-20,"UShort")+2,"UInt")+92,"UInt"),"UInt")
	,"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)  
}
screenRes_Get(Disp:=0) {              ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
	Local DM, N:=VarSetCapacity(DM,220,0) 
	Return DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",-1, "Ptr",&DM)=0 ? ""
		: Format("{:}x{:}@{:}", NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt")) 
}



;Usage instructions below start of Vieira GetMonitorName

;GetMonitorName("Point") -> Uses the mouse location
;GetMonitorName("Point", [1921, 1]) -> Uses the provided coordinates
;GetMonitorName("Window") -> Uses the active window
;GetMonitorName("Rect", [1921, 1, 1951, 10]) -> Uses the provided rectangle coordinates


;Get monitor cursor by Vieira

GetMonitorName(method := "Window", coords := "", default_to := "Nearest") {
    static default := {"Null": MONITOR_DEFAULTTONULL := 0x0, "Primary": MONITOR_DEFAULTTOPRIMARY := 0x1, "Nearest": MONITOR_DEFAULTTONEAREST := 0x2}
    If (method = "Window")
        hMonitor := DllCall("MonitorFromWindow", "UInt", WinExist("A"), "UInt", default[default_to], "Ptr")
    Else if (method = "Point") {
        if coords
            x := coords[1], y := coords[2]
        Else
            MouseGetPos, x, y
        hMonitor := DllCall("MonitorFromPoint", "Int64", (x&0xFFFFFFFF) | (y<<32), "Int", default[default_to], "Ptr")
    }
    Else if (method = "Rect") {
        if !coords
            Throw % "Rect method requires coordinates"
        VarSetCapacity(RECT, 16, 0)
        NumPut(coords[4], NumPut(coords[3], NumPut(coords[2], NumPut(coords[1], &RECT, "UInt"), "UInt"), "UInt"), "UInt")
        hMonitor := DllCall("MonitorFromRect", "Ptr", &RECT, "UInt", default[default_to], "Ptr")
    }
    Else
        Throw % "Invalid method"
    NumPut(VarSetCapacity(MONITORINFOEX, 40 + (32 << !!A_IsUnicode)), MONITORINFOEX, 0, "UInt")
    DllCall("GetMonitorInfoW", "Ptr", hMonitor, "Ptr", &MONITORINFOEX)
    return StrGet(&MONITORINFOEX + 40, 32)
}

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 09 Feb 2023, 11:21
by MedBooster
I changed the script to use the display in which the selected window is

The issue with using the cursor "Point" position is that the mouse position gets repositioned to the main display once you rotate a display,
so I recommend using the script that rotates the display the active/selected window is in. It is also more stable
(the "Point" one does not always work on other displays than the primary display)


Code: Select all

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

;help received by [+] https://www.autohotkey.com/boards/viewtopic.php?f=76&t=87453&p=492976&sid=643f7444d745cc540978272aece7091f#p492976


#singleInstance force
#noEnv


;put together by MedBooster thank you to everyone that helped!

;the rotation code by masonjar13 ChangeDisplaySettingsExW down below edited in get active monitor down below 




lookup:={"^!down":[0,0],"^!right":[1,1],"^!up":[2,0],"^!left":[3,1]}
return

^!down::
^!right::
^!up::
^!left::

display := GetMonitorName("Window")


if (lookup[a_thisHotkey][2]){ ; rotating to portrait
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] < sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
} else { ; rotating to landscape
	sRes:=strSplit((cRes:=screenRes_Get(display)),["x","@"])
	if (sRes[2] > sRes[1]) {
		cRes:=sRes[2] "x" sRes[1] "@" sRes[3]
	}
 }
screenRes_Set(cRes,display,lookup[a_thisHotkey][1])
return

screenRes_Set(WxHaF, Disp:=0, orient:=0) {       ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution ; edited orientation in by Masonjar13
	Local DM, N:=VarSetCapacity(DM,220,0), F:=StrSplit(WxHaF,["x","@"],A_Space)
	Return DllCall("ChangeDisplaySettingsExW",(Disp=0 ? "Ptr" : "WStr"),Disp,"Ptr",NumPut(F[3],NumPut(F[2],NumPut(F[1]
	,NumPut(32,NumPut(0x5C0080,NumPut(220,NumPut(orient,DM,84,"UInt")-20,"UShort")+2,"UInt")+92,"UInt"),"UInt")
	,"UInt")+4,"UInt")-188, "Ptr",0, "Int",0, "Int",0)  
}
screenRes_Get(Disp:=0) {              ; v0.90 By SKAN on D36I/D36M @ tiny.cc/screenresolution
	Local DM, N:=VarSetCapacity(DM,220,0) 
	Return DllCall("EnumDisplaySettingsW", (Disp=0 ? "Ptr" : "WStr"),Disp, "Int",-1, "Ptr",&DM)=0 ? ""
		: Format("{:}x{:}@{:}", NumGet(DM,172,"UInt"),NumGet(DM,176,"UInt"),NumGet(DM,184,"UInt")) 
}



;Usage instructions below start of Vieira GetMonitorName

;GetMonitorName("Point") -> Uses the mouse location

;GetMonitorName("Window") -> Uses the active window
;GetMonitorName("Rect", [1921, 1, 1951, 10]) -> Uses the provided rectangle coordinates


;Get monitor cursor by Vieira

GetMonitorName(method := "Window", coords := "", default_to := "Nearest") {
    static default := {"Null": MONITOR_DEFAULTTONULL := 0x0, "Primary": MONITOR_DEFAULTTOPRIMARY := 0x1, "Nearest": MONITOR_DEFAULTTONEAREST := 0x2}
    If (method = "Window")
        hMonitor := DllCall("MonitorFromWindow", "UInt", WinExist("A"), "UInt", default[default_to], "Ptr")
    Else if (method = "Point") {
        if coords
            x := coords[1], y := coords[2]
        Else
            MouseGetPos, x, y
        hMonitor := DllCall("MonitorFromPoint", "Int64", (x&0xFFFFFFFF) | (y<<32), "Int", default[default_to], "Ptr")
    }
    Else if (method = "Rect") {
        if !coords
            Throw % "Rect method requires coordinates"
        VarSetCapacity(RECT, 16, 0)
        NumPut(coords[4], NumPut(coords[3], NumPut(coords[2], NumPut(coords[1], &RECT, "UInt"), "UInt"), "UInt"), "UInt")
        hMonitor := DllCall("MonitorFromRect", "Ptr", &RECT, "UInt", default[default_to], "Ptr")
    }
    Else
        Throw % "Invalid method"
    NumPut(VarSetCapacity(MONITORINFOEX, 40 + (32 << !!A_IsUnicode)), MONITORINFOEX, 0, "UInt")
    DllCall("GetMonitorInfoW", "Ptr", hMonitor, "Ptr", &MONITORINFOEX)
    return StrGet(&MONITORINFOEX + 40, 32)
}


[Mod edit: Replaced quote tags with [code][/code] tags.]

Re: Is there really no way to set screen orientation in modern Windows 10?

Posted: 17 Apr 2023, 14:59
by sraasch
Sorry to dredge up an old post...

I'm wondering if anyone has translated this to the new syntax?