Jump to content

Recommended Posts

Posted

I'm trying to move the mouse between three monitors (shaped like an L if that matters). But it's not working because the primary monitor (laptop) has 150% scale. I've seen a couple older posts that try to tackle the issue of mousemove and scaling, but the solutions don't quite tackle the basic compensation issue of a simple mouse move...more like tracking, and I can't really decode what they put together. Has anyone come up with a simple compensation for mousemove with a scaled primary screen?

Posted

I guess I'm missing something and don't see how to implement this. I see how this can help with resolution and monitor count, which I don't have an issue with, but I don't see how this can help with window scaling and mousemove coordinates taking it into consideration.

Posted

I assumed that knowing the resolution of each monitor and its position

within the monitors grid  would help move the mouse between them

I know that I know nothing

Posted

No, everything is just off when a monitor has the scale changed. Look at the image. All monitors are 1920 with monitor 1 having a scale of 150%.  If I set MouseMove(2000, 500) the mouse should end up around the green line on monitor 2, but it instead ends up around the blue line. When the scale is at 100% the mouse moves where I expect it to. Some mousemove coordinates wont even move to screen 2 all together even if the coordinates dictate it should be on screen 2.

monitors.png

  • Solution
Posted (edited)

can you show the console output from the script i suggested?

indeed, the mouse lives in its world (with a zoom factor of 200% it makes half the journey), while the ToolTip goes normally to its position

however the problem seems to be fixed by using  DPIAwareness.au3  

which I found after digging in  CV  as suggested by @argumentum

 

DPIAwareness.au3

  Reveal hidden contents

 

Example

; https://www.autoitscript.com/forum/topic/210653-mousemove-and-scaling-issue/#comment-1522551

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include "DPIAwareness.au3"

_WinAPI_SetDPIAwareness()

Global $hGui = GUICreate('Au3Gui', 500, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
WinSetTrans($hGui, '', 100)
Global $Label1 = GUICtrlCreateLabel("", 200, 200, 300, 300)
GUICtrlSetFont(-1, 200, 900, 0, "MS Sans Serif")
GUISetState(@SW_SHOW, $hGui)

Global $aMon = _GetMonitorsArray()

If IsArray($aMon) Then

    #Region ===( test1 )===
    For $i = 1 To $aMon[0][0]
        WinMove($hGui, "", $aMon[$i][1], $aMon[$i][2], $aMon[$i][3], $aMon[$i][4])
        GUISetState(@SW_MAXIMIZE, $hGui)
        GUICtrlSetData($Label1, $i)

        ConsoleWrite("  index: " & $i & @CRLF)
        ConsoleWrite("- [0]=handle=" & $aMon[$i][0] & @CRLF)
        ConsoleWrite("- [1]=left=" & $aMon[$i][1] & @CRLF)
        ConsoleWrite("- [2]=top=" & $aMon[$i][2] & @CRLF)
        ConsoleWrite("- [3]=width=" & $aMon[$i][3] & @CRLF)
        ConsoleWrite("- [4]=height=" & $aMon[$i][4] & @CRLF)
        ConsoleWrite("" & @CRLF)

        _GetMonitorInfo($hGui)

        Sleep(2000)
    Next

    GUIDelete($hGui)
    #EndRegion ===( test1 )===

    #Region ===( test2 )===
    Global $iX, $iY
    For $i = 1 To $aMon[0][0]

        ;the start point
        $iX = $aMon[$i][1]
        $iY = $aMon[$i][2]

        ;plus the midle point
        $iX += $aMon[$i][3] / 2
        $iY += $aMon[$i][4] / 2

        ConsoleWrite($iX & ", " & $iY & @CRLF)

        ToolTip("Mouse x, y:" & @CRLF & $iX & ", " & $iY, $iX, $iY, "midle point:", 1, 3)
        MouseMove($iX, $iY, 70)

        Global $aPos = MouseGetPos()
        ConsoleWrite("MouseGetPos x, y:" & $aPos[0] & ", " & $aPos[1] & @CRLF)

        Sleep(3000)
        ToolTip("")

    Next
    #EndRegion ===( test2 )===

EndIf

;----------------------------------------------------------------------------------------
Func _GetMonitorInfo($hWindow)
    Local $hMonitor = _WinAPI_MonitorFromWindow($hWindow, $MONITOR_DEFAULTTONULL)
    Local $aData = _WinAPI_GetMonitorInfo($hMonitor)
    ConsoleWrite('MonitorInfo **********************' & @CRLF)
    If Not @error Then
        ConsoleWrite('Handle:      ' & $hMonitor & @CRLF)
        ConsoleWrite('Rectangle:   ' & DllStructGetData($aData[0], 1) & ', ' & DllStructGetData($aData[0], 2) & ', ' & DllStructGetData($aData[0], 3) & ', ' & DllStructGetData($aData[0], 4) & @CRLF)
        ConsoleWrite('Work area:   ' & DllStructGetData($aData[1], 1) & ', ' & DllStructGetData($aData[1], 2) & ', ' & DllStructGetData($aData[1], 3) & ', ' & DllStructGetData($aData[1], 4) & @CRLF)
        ConsoleWrite('Primary:     ' & $aData[2] & @CRLF)
        ConsoleWrite('Device name: ' & $aData[3] & @CRLF)
        ConsoleWrite("**********************************" & @CRLF & @CRLF)

    EndIf
EndFunc   ;==>_GetMonitorInfo
;----------------------------------------------------------------------------------------
Func _GetMonitorsArray()
    Local $aPos, $aData = _WinAPI_EnumDisplayMonitors()
    If IsArray($aData) Then
        ReDim $aData[$aData[0][0] + 1][5]
        For $i = 1 To $aData[0][0]
            $aPos = _WinAPI_GetPosFromRect($aData[$i][1])
            For $j = 0 To 3
                $aData[$i][$j + 1] = $aPos[$j]
            Next
        Next
    EndIf
    Return $aData
EndFunc   ;==>_GetMonitorsArray
;----------------------------------------------------------------------------------------

 

;comment /  uncomment  the _WinAPI_SetDPIAwareness() func to see  the different

Edited by ioa747
Correction

I know that I know nothing

Posted

Thank both of you...the best part about your example @ioa747 is you saved me time because that is exactly the function I was going to do in having the mouse center on the screen.

  • 1 month later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...