Sign in to follow this  
Followers 0
Mechaflash

Physical Monitor Mapping (? iono wut to call it ?)

4 posts in this topic

#1 ·  Posted (edited)

Maybe someone else can find some use of this code.

I'm working on a program for the company I work for, and for this program, it will spawn a few different windows. I wanted a way to manage on which screen these windows showed up on. However, I wanted it to work on workstations that may have more than 2 or 3 monitors... so it can be expandable for numerous monitors in a single row if I wanted it to.

So I created the below script to do just that. It enumerates each physical monitor and sticks it into an array $_xRes. $_xRes[0] holds the x-location of your Default monitor, while $_xRes[1-98] holds the values of all monitors' x-location from your left-most to your right-most, creating a sort of a physical mapping. So if you have a 3 monitor setup, $_xRes[1] will be your left monitor, $_xRes[2] middle monitor, and $_xRes[3] right monitor.

At the bottom of the code is a sample script to open notepad, and use WinMove() to navigate it to your different monitors.

EDIT: This can easily be made into a script that enumerates vertical stacks of monitors as well as horizontal in a 2D array.

EDIT - 05-17-12

SPOILER content is old

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author:      Mechaflash
Script Function:
Get the x positions of all physical monitors (made for 1 row of monitors, with up to 98 monitors).
The $_xRes[] array returns the x values of each monitor from left to right, no matter how they are wired physically,
creating a "physical structure" to use when navigating multiple GUI windows to different monitors.
$_xRes[0] = Default Monitor x value
$_xRes[1-3] = All physical monitor x values starting from the left-most monitor to the right-most monitor.
#ce ----------------------------------------------------------------------------
#include
#include
#Region ; Variable Declarations
Dim $x = 0, $y = 0, $_enum, $_xRes[99], $_xResPre
Dim $_PhysMon[15] = [1,2,8,32,3,9,33,10,34,40,11,35,36,42,51]
Dim $_DefMon[8] = [2,3,10,34,11,35,42,43]
#endregion
Do
$_enum = _WinAPI_EnumDisplayDevices("", $x)
$_physCheck = _ArraySearch($_PhysMon, $_enum[3])
$_defCheck = _ArraySearch($_DefMon, $_enum[3])
$x+=1
msgbox(0,"","Phys Check:  " & $_physCheck & @LF & "Def Check:   " & $_defCheck)
If $_physCheck <> -1 AND $_defCheck <> -1 Then
  msgbox(0,"","Monitor " & $x & " IS THE PHYSICAL DEFAULT MONITOR")
  $y+=1
  $_xResPre = _MonitorAndDesktopInfo()
  $_xRes[$y] = $_xResPre[$x][1]
  $_xRes[0] = $_xResPre[$x][1]
ElseIf $_physCheck <> -1 Then
  msgbox(0,"","Monitor " & $x & " IS A PHYSICAL MONITOR")
  $y+=1
  $_xResPre = _MonitorAndDesktopInfo()
  $_xRes[$y] = $_xResPre[$x][1]
Else
  msgbox(0,"","Monitor " & $x & " IS A VIRTUAL MONITOR")
EndIf
Until NOT $_enum[3]
$y+=1
$_xRes[$y] = "NULL"
ReDim $_xRes[$y + 1]
_ArrayDisplay($_xRes)
_ArraySort($_xRes, 0, 1)
_ArrayDisplay($_xRes)

#Region ; Example of use by starting an app and moving it with the outputs.
Run("notepad")
$x = 1
LOCAL $_winTitle = "Untitled - Notepad"
WinWait($_winTitle, "")
WinActivate($_winTitle, "")
WinWaitActive($_winTitle, "")
WinSetOnTop($_winTitle, "", 1)
Send("This window will be placed on your default monitor, {enter} then move from your left-most monitor to your right-most monitor.")
WinMove($_winTitle, "", $_xRes[0],"")
msgbox(0,"This is your default display","^^^^^^^^^^^^^^")
Do
WinMove($_winTitle, "", $_xRes[$x], 0)
$x+=1
msgbox(0,"Left to Right", "^^^^^^^^^^^^^^^^^^^")
Until $_xRes[$x] == "NULL"
WinKill($_winTitle, "")
#endregion

This is my .au3 I made for myself. It's definitely not structured as an acceptable UDF, but since you're asking questions on it, I'll go ahead and post it:

#include-once
#cs ----------------------------------------------------------------------------
    UDF Name:      Monitor Mapping
    AutoIt Version: 3.3.8.1
    Author:      Mechaflash

    Script Function:
    Get the x positions of all physical monitors (made for 1 row of monitors, with any number of monitors).
    The $_aiMonitorMapping[] array returns the x values of each monitor from left to right, no matter how they are wired physically,
    creating a "physical structure" to use when navigating multiple GUI windows to different monitors.
    $_aiMonitorMapping[0] = Default Monitor x value
    $_aiMonitorMapping[1-98] = All other physical monitor x values starting from the left-most monitor to the right-most monitor.

#ce ----------------------------------------------------------------------------

#include 
#include 

GLOBAL $_aiMonitorMapping[99], $_MonitorMapping, $_MonitorMapping_LEFT, $_MonitorMapping_RIGHT, $_MonitorMapping_DEFAULT, $_MonitorMapping_COUNT
$_MonitorMapping = _MonitorMapping()
$_MonitorMapping_COUNT = UBound($_MonitorMapping) - 2
If $_MonitorMapping_COUNT > 0 AND $_MonitorMapping_COUNT <= 3 THEN
    $_MonitorMapping_DEFAULT = $_MonitorMapping[0]
    $_MonitorMapping_LEFT = $_MonitorMapping[1]
    $_MonitorMapping_RIGHT = $_MonitorMapping[2]
EndIf
Func _MonitorMapping()
    LOCAL $x = 0, $y = 0, $_enum, $xResPre
    LOCAL $PhysMon[15] = [1,2,8,32,3,9,33,10,34,40,11,35,36,42,51]
    LOCAL $DefMon[8] = [2,3,10,34,11,35,42,43]

    Do
        $_enum = _WinAPI_EnumDisplayDevices("", $x)
        $PhysCheck = _ArraySearch($PhysMon, $_enum[3])
        $DefCheck = _ArraySearch($DefMon, $_enum[3])
        $x+=1
        If $PhysCheck <> -1 AND $DefCheck <> -1 Then
            $y+=1
            $xResPre = _MonitorAndDesktopInfo()
            $_aiMonitorMapping[$y] = $xResPre[$x][1]
            $_aiMonitorMapping[0] = $xResPre[$x][1]
        ElseIf $PhysCheck <> -1 Then
            $y+=1
            $xResPre = _MonitorAndDesktopInfo()
            $_aiMonitorMapping[$y] = $xResPre[$x][1]
        EndIf
    Until NOT $_enum[3]
    $y+=1
    $_aiMonitorMapping[$y] = "NULL"
    ReDim $_aiMonitorMapping[$y + 1]
    _ArraySort($_aiMonitorMapping, 0, 1)
    Return $_aiMonitorMapping
EndFunc
Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your script sounded like what I was looking for, but I have a couple of issues.

1 - Lines 11 & 12 don't specify what to include. I am assuming they should be <winapi.au3> and <array.au3>.

2 - Lines 27 & 33 call the function _MonitorAndDesktopInfo(), but that function does not exist.

3 - Can you give an explanation of lines 15 & 16?

Edited by willichan

Share this post


Link to post
Share on other sites

Edited my original post.

1 - Lines 11 & 12 don't specify what to include. I am assuming they should be <winapi.au3> and <array.au3>.

2 - Lines 27 & 33 call the function _MonitorAndDesktopInfo(), but that function does not exist.

3 - Can you give an explanation of lines 15 & 16?

1. Fixed (bad original posting of code... probably pasted it as plain text then wrapped it in
)

2. From Display_Library_Functions.au3

3. Those are the return values from _WinAPI_EnumDisplayDevices() to determine which monitors are physical monitors ($PhysMon = Physical Monitor property return values)and to pinpoint the one set as your default monitor ($DefMon = Default Monitor property return values).


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

I created an additional edit to the function description. Currently its only made to look for up to 3 monitors.


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0