Jump to content
Sign in to follow this  
ahha

Mousemove not working properly with scaling in some windows

Recommended Posts

ahha

This one has me baffled.  I can't seem to get MouseMove to work properly with scaling in some windows.

Run this program and use the arrow keys to move the mouse Up, Down, Left, Right at native (100%) scaling and it works as expected. 

Now go to 125%, for example, and move Up, Down, Left, Right on the desktop and it works.

Now open the MouseMove help window (cursor on MouseMove then F1).

Move the mouse into the MouseMove help window and try Up, Down, Left, Right and the movements are diagonal!

If you move, for example, right from desktop into the MouseMove window it goes from moving right to down and right (diagonal) as soon as the mouse hits the MouseMove help window.  I'm stumped.

How do I get MouseMove to work properly?  Any hints appreciated.

;
;#AutoIt3Wrapper_run_debug_mode=Y   ; use this to debug in console window <--- LOOK


;Trying to figure out how to scale properly for MouseMove - moving mouse in Up, Down, Left, Right moves diagonally on some windows if scale <> 1 (100%).
;Test on main monitor and use 1920x1080 then scale to 125% as simple example.
;To change display scale in Windows 10, right click on desktop "Display Settings" --> Scale and layout

;arrow keys on arrow keypad
HotKeySet("{UP}", "__UpMouse")
HotKeySet("{DOWN}", "__DownMouse")
HotKeySet("{LEFT}", "__LeftMouse")
HotKeySet("{RIGHT}", "__RightMouse")

;v2g - cutting out superfluous code to show issue, added scaling

Opt("MouseCoordMode",1)         ;1 = absolute screen coordinates (default) - use this because otherwise active window mucks it up

$scale = _GetScale()
MsgBox(0,"DEBUG", "$scale = " & $scale)


While 1
    ;watch the console - the mouse is not moving correctly
    Sleep(10)   ;this works well and does not appear to use the CPU
WEnd


;================= Functions ==================

Func __UpMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]-1)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __UpMouse()" & @CRLF & "Before UP (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After UP (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc

Func __DownMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]+1)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __DownMouse()" & @CRLF & "Before DOWN (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After DOWN (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc

Func __LeftMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]-1, $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __LeftMouse()" & @CRLF & "Before LEFT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After LEFT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc

Func __RightMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+1, $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __RightMouse()" & @CRLF & "Before RIGHT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After RIGHT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc



Func _GetScale()    ;returns a scale factor for PixelGetColor
    ;from: https://www.autoitscript.com/forum/topic/156251-mouse-coordinates/?tab=comments#comment-1130002
   $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
   $pDEVMODE = DllStructGetPtr($tDEVMODE)
   $i = 0

   while 1
      $ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
      if ($ret[0] = 0) then exitloop
      $width = DllStructGetData($tDEVMODE, 4, 2) ; native width
      $i += 1
   wend

   $scale = $width / @DesktopWidth
   Return($scale)
EndFunc

 

Share this post


Link to post
Share on other sites
ahha

Can't as no controls are listed in AutoIt3 Info and tabbing does not work, so I'm stuck with moving the mouse.

Did you observe the strange behavior of MouseMove?

 

Edited by ahha

Share this post


Link to post
Share on other sites
Malkey

While running your script, I experienced the weird MouseMove behavior in both the AutoIt Help window and the AutoIt3 AU3Info window. I am running Win 10 and using a 125% (Recommended) scale.

I managed to fix this weird behavior by setting the "Advanced scaling settings".
The procedure I followed:-
Right mouse button click on a clear part of desktop;
Left mouse button click on "Display settings" on the menu;
Just below the recommended scale percentage input box, there is a link "Advanced scaling settings" which you click on;
Enter a custom scaling size in the box. (I entered 125, which was the recommended scale value on the previous window.); 
Then press the "Apply" button; 
Note the appearance of red writing "The custom scale factor won't be applied until you sign out". So, click the link "Sign out now" that is just below the red writing;
Now you can restart SciTE, AutoIt help, and a smaller version of AutoIt3 AU3Info window.  Run your script, and the mouse moves as expected.  Well, it did for me.

Share this post


Link to post
Share on other sites
ahha

Malkey,

Thanks for confirming that I'm not imagining the weird MouseMove behaviour.  That's a big vote for my sanity :)

Your proposed approach indeed does work and I noticed that the $scale = 1.  Which means that somehow the OS (I'm also running Win 10) is mucking with _GetScale() (the DLL call) to fake out the true resolution of the monitors.  This is just plain strange.

The problem I have with your approach is the users are not going to change to a custom resolution.  It seems to me that regardless of the scaling that MouseMove should not be behaving like this.  BTW it's not just AutoIt windows it acts weird in.  It was actually another program of mine - I just used an AutoIt window to demonstrate the weirdness.

*Edit* This whole issue comes up because on a 4K UHD monitor, which are becoming more common, the native resolution is 3840 x 2160, however Win 10 is set at 150% scaling otherwise most aps are too tiny to read.  AND the MouseMove weird behaviour occurs.  I used the 1920x1080 and 125% example just to illustrate the problem as not everyone has a UHD monitor.  I'm making an assumption that once I figure out how to fix it on the 1920x1080 125% example, I'll be able to fix it on the UHD 150% case.

Is this a bug that should be reported?  I can't believe moving into a widow should cause such weirdness.

Thanks again for the sanity check.

ahha

Edited by ahha
Added UHD info.

Share this post


Link to post
Share on other sites
ahha

Okay, I've added a function _DynamicallyCorrectMouseMove for the UP movement only at this point (I'll work on the others tomorrow) and it works but this whole compensating is a kludge.   The Beeps are to give an indication of what's going on. 

;
;#AutoIt3Wrapper_run_debug_mode=Y   ; use this to debug in console window <--- LOOK


;Trying to figure out how to scale properly for MouseMove - moving mouse in Up, Down, Left, Right moves diagonally on some windows if scale <> 1 (100%).
;Test on main monitor and use 1920x1080 then scale to 125% as simple example.
;To change display scale in Windows 10, right click on desktop "Display Settings" --> Scale and layout

;arrow keys on arrow keypad
HotKeySet("{UP}", "__UpMouse")
HotKeySet("{DOWN}", "__DownMouse")
HotKeySet("{LEFT}", "__LeftMouse")
HotKeySet("{RIGHT}", "__RightMouse")

;v2g - cutting out superfluous code to show issue, added scaling
;v2h - added scaling
;v2i - trying dynamic correction for when MouseMove is erratic


Opt("MouseCoordMode",1)         ;1 = absolute screen coordinates (default) - use this because otherwise active window mucks it up

$scale = _GetScale()
MsgBox(0,"DEBUG", "$scale = " & $scale)


While 1
    ;watch the console - the mouse is not moving correctly
    Sleep(10)   ;this works well and does not appear to use the CPU
WEnd


;================= Functions ==================

Func __UpMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]-(1*$scale))
    ;MouseMove($mousepos[0]-1, $mousepos[1]-(1*$scale)) ;working some of the time
    ;MouseMove($mousepos[0]+0, $mousepos[1]-(1/$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __UpMouse()" & @CRLF & "Before UP (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After UP (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2i
    If $mousepos[0] <> $mouseposafter[0] Then _DynamicallyCorrectMouseMove("UP", $mousepos[0], $mousepos[1])    ;check that no X-axis movement, pass original information
EndFunc

Func __DownMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]+(1*$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __DownMouse()" & @CRLF & "Before DOWN (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After DOWN (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc

Func __LeftMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]-(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __LeftMouse()" & @CRLF & "Before LEFT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After LEFT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc

Func __RightMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __RightMouse()" & @CRLF & "Before RIGHT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After RIGHT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
EndFunc


Func _GetScale()    ;returns a scale factor for PixelGetColor
    ;from: https://www.autoitscript.com/forum/topic/156251-mouse-coordinates/?tab=comments#comment-1130002
   $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
   $pDEVMODE = DllStructGetPtr($tDEVMODE)
   $i = 0

   while 1
      $ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
      if ($ret[0] = 0) then exitloop
      $width = DllStructGetData($tDEVMODE, 4, 2) ; native width
      $i += 1
   wend

   $scale = $width / @DesktopWidth
   Return($scale)
EndFunc



Func _DynamicallyCorrectMouseMove($sDirection, $iXorignal, $iYoriginal)     ;check that no X-axis movement, pass original information

    Select
        Case StringLower($sDirection) = "up"
            ;okay we have the original coordinates and it messed up on the move up and also went left or right
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-2)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then
                Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)

            Else

                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = -1,-2
                            ;so try this first before dropping into this
                            ;-1 makes sense as moving 1 X pixel to the right, -2 makes little sense as it moved correcly in Y direction but it works
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf

        Case StringLower($sDirection) = "down"

        Case StringLower($sDirection) = "left"

        Case StringLower($sDirection) = "right"

        Case Else
            ;really messed up so do nothing
    EndSelect


EndFunc ;_DynamicallyCorrectMouseMove

Can someone point me to a lower level or different approach to moving the mouse?

Share this post


Link to post
Share on other sites
Bert
On 1/21/2019 at 1:55 AM, ahha said:

Can't as no controls are listed in AutoIt3 Info and tabbing does not work, so I'm stuck with moving the mouse.

Did you observe the strange behavior of MouseMove?

 

Did you ever look at this: 

 

Share this post


Link to post
Share on other sites
ahha

Bert - thanks will dive into it.  However, I still need to MouseMove because I need to watch a pixel to know when done (much like progress bar).

Share this post


Link to post
Share on other sites
ahha

All - latest version v2j with UP, DOWN, LEFT, and RIGHT MouseMove dynamically corrected for.  Tested at 125%.

;
;#AutoIt3Wrapper_run_debug_mode=Y   ; use this to debug in console window <--- LOOK


;Trying to figure out how to scale properly for MouseMove - moving mouse in Up, Down, Left, Right moves diagonally on some windows if scale <> 1 (100%).
;Test on main monitor and use 1920x1080 then scale to 125% as simple example.
;To change display scale in Windows 10, right click on desktop "Display Settings" --> Scale and layout

;arrow keys on arrow keypad
HotKeySet("{UP}", "__UpMouse")
HotKeySet("{DOWN}", "__DownMouse")
HotKeySet("{LEFT}", "__LeftMouse")
HotKeySet("{RIGHT}", "__RightMouse")

HotKeySet("^!x", "Terminate") ;Press Ctrl+Alt+x to exit the script

;v2g - cutting out superfluous code to show issue, added scaling
;v2h - added scaling
;v2i - trying dynamic correction for when MouseMove is erratic - added UP only it works
;v2j - added dynamic DOWN, LEFT, RIGHT, and Ctrl+Alt+x to exit the script, $iMouseSpeed, $debug for sound   ;may still need to add screen boundary checks

Opt("MouseCoordMode",1)         ;1 = absolute screen coordinates (default) - use this because otherwise active window mucks it up

$scale = _GetScale()
MsgBox(0,"DEBUG", "$scale = " & $scale)

;scaling just messes up the MouseMove - so force to 1
$scale = 1 ;debug force to a value

While 1
    ;watch the console - the mouse is not moving correctly
    Sleep(10)   ;this works well and does not appear to use the CPU
WEnd


;================= Functions ==================

Func __UpMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]-(1*$scale))
    ;MouseMove($mousepos[0]-1, $mousepos[1]-(1*$scale)) ;working some of the time
    ;MouseMove($mousepos[0]+0, $mousepos[1]-(1/$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __UpMouse()" & @CRLF & "Before UP (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After UP (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2i
    If $mousepos[0] <> $mouseposafter[0] Then _DynamicallyCorrectMouseMove("UP", $mousepos[0], $mousepos[1])    ;check that no X-axis movement, pass original information
EndFunc

Func __DownMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]+(1*$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __DownMouse()" & @CRLF & "Before DOWN (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After DOWN (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2j
    If $mousepos[0] <> $mouseposafter[0] Then _DynamicallyCorrectMouseMove("DOWN", $mousepos[0], $mousepos[1])  ;check that no X-axis movement, pass original information
EndFunc

Func __LeftMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]-(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __LeftMouse()" & @CRLF & "Before LEFT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After LEFT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2j
    If $mousepos[1] <> $mouseposafter[1] Then _DynamicallyCorrectMouseMove("LEFT", $mousepos[0], $mousepos[1])  ;check that no Y-axis movement, pass original information
EndFunc

Func __RightMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __RightMouse()" & @CRLF & "Before RIGHT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After RIGHT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2j
    If $mousepos[1] <> $mouseposafter[1] Then _DynamicallyCorrectMouseMove("RIGHT", $mousepos[0], $mousepos[1])     ;check that no Y-axis movement, pass original information
EndFunc


Func _GetScale()    ;returns a scale factor for PixelGetColor
    ;from: https://www.autoitscript.com/forum/topic/156251-mouse-coordinates/?tab=comments#comment-1130002
   $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
   $pDEVMODE = DllStructGetPtr($tDEVMODE)
   $i = 0

   while 1
      $ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
      if ($ret[0] = 0) then exitloop
      $width = DllStructGetData($tDEVMODE, 4, 2) ; native width
      $i += 1
   wend

   $scale = $width / @DesktopWidth
   Return($scale)
EndFunc



Func _DynamicallyCorrectMouseMove($sDirection, $iXorignal, $iYoriginal)     ;check that no X-axis movement, pass original information
    $iCaseExit = 0  ;effectively an ExitSelect.
                    ;just position Case $iCaseExit = 1  as the *next* Case statement as ContinueCase drops from the code in current Case into the code of the next Case
                    ;it DOES NOT evaluate the next Case statement, it just executes the next code which here is just reset the flag (i.e. $iCaseExit = 0)

    $iMouseSpeed = 0
    $debug = 0  ;0=off, 1=on

    Select
        Case StringUpper($sDirection) = "UP"
            ;okay we have the original coordinates and it messed up on the move up and also went left or right
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-2, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,-2" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = -1,-2
                            ;so try this first before dropping into this
                            ;-1 makes sense as moving 1 X pixel to the right, -2 makes little sense as it moved correcly in Y direction but it works
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf


        Case StringUpper($sDirection) = "DOWN"
            ;okay we have the original coordinates and it messed up on the move down and also went left or right
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-0, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal+1)) Then
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,0" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal+1)) Then
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = -1,0
                            ;so try this first before dropping into this
                            ;-1 makes sense as moving 1 X pixel to the right, 0 makes little sense as it moved correcly in Y direction but it works
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf


        Case StringUpper($sDirection) = "LEFT"
            ;okay we have the original coordinates and it messed up on the move left and also went up or down
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-0, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,0" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                $iCaseExit = 1  ;exit Case
                ContinueCase
            EndIf

            ;try this second
            MouseMove($iXorignal-2, $iYoriginal-1, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -2,-1" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                $iCaseExit = 1  ;exit Case
                ContinueCase
            EndIf

            ;else let's do the hunt
;~          MouseMove($iXorignal-1, $iYoriginal-0, $iMouseSpeed)
;~          $mousepos = MouseGetPos()
;~          If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then
;~              If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
;~              ConsoleWrite("in  _DynamicallyCorrectMouseMove" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
;~          EndIf

            $iCount = 0
            For $x = -5 to +5
                For $y = -5 to +5
                    $iCount = $iCount +1    ;get an idea of how many tries we needed
                    If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                    MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                    $mousepos = MouseGetPos()
                    If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then    ;moved correctly
                        ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                        ;from testing most common is strange as there are 2 most common
                        ;one is $x,$y offset = -1,0 and the second is -2,-1
                        ;perhaps try -1,0 first then -2,-1
                        ;so try this first before dropping into this
                        ;-1 and -2 make no sense as moving 1 X pixel to the left, 0 and -1 make little sense
                        ExitLoop 2  ;we found it
                    EndIf
                Next
            Next
;~      EndIf


        Case $iCaseExit = 1 ;exit Case statement directly above
            If $debug = 1 Then Beep(2000, 100)      ;debug
            $iCaseExit = 0  ;reset it and drop to EndSelect


        Case StringUpper($sDirection) = "RIGHT"

            ;try this first
            MouseMove($iXorignal-0, $iYoriginal-1, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal+1) AND ($mousepos[1] = $iYoriginal)) Then
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using 0,-1" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal+1) AND ($mousepos[1] = $iYoriginal)) Then    ;moved correctly
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = 0,-1
                            ;so try this first before dropping into this
                            ;0 makes no sense as moving 1 X pixel to the right
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf

        Case Else
            ;really messed up so do nothing

    EndSelect


EndFunc ;_DynamicallyCorrectMouseMove


Func Terminate()
    Beep(200, 200)
    Exit 0
EndFunc

 

Share this post


Link to post
Share on other sites
ahha

Version v2n - works for 1920x1080 display at 100%, 125%, 150% - NOT at 175% it appears erratic.

Next I'll try and check on UDH monitor as Win 10 defaults to 150%.

;
;#AutoIt3Wrapper_run_debug_mode=Y   ; use this to debug in console window <--- LOOK


;Trying to figure out how to scale properly for MouseMove - moving mouse in Up, Down, Left, Right moves diagonally on some windows if scale <> 1 (100%).
;Test on main monitor and use 1920x1080 then scale to 125% as simple example.
;To change display scale in Windows 10, right click on desktop "Display Settings" --> Scale and layout

;arrow keys on arrow keypad
HotKeySet("{UP}", "__UpMouse")
HotKeySet("{DOWN}", "__DownMouse")
HotKeySet("{LEFT}", "__LeftMouse")
HotKeySet("{RIGHT}", "__RightMouse")

HotKeySet("^!x", "Terminate") ;Press Ctrl+Alt+x to exit the script

;v2g - cutting out superfluous code to show issue, added scaling
;v2h - added scaling
;v2i - trying dynamic correction for when MouseMove is erratic - added UP only it works
;v2j - added dynamic DOWN, LEFT, RIGHT, and Ctrl+Alt+x to exit the script, $iMouseSpeed, $debug for sound   ;may still need to add screen boundary checks
;v2k - check both X and Y coordinates after MouseMove not just if one coordinate changed that shouldn't.
;       We are using $scale to make a best guess at a first or second coordinate correction before using a brute force hunt
;v2l - skip worthless
;v2m - checking at other scale factors, works at 100%, 125%, 150%,
;       175% is struggling and not really moving the mouse up and left and is *NOT* dropping into the dynamic adjustment - SO MouseGetPos() is AFU!!!
;v2n - AND logic is wrong we want to dynamically correct if either coordinate is off so use OR for checking
;       works for 1920x1080 display at 100%, 125%, 150% - NOT at 175% it appears erratic

Opt("MouseCoordMode",1)         ;1 = absolute screen coordinates (default) - use this because otherwise active window mucks it up

$scale = _GetScale()
MsgBox(0,"DEBUG", "$scale = " & $scale)

;scaling just messes up the MouseMove - so force to 1
$scale = 1 ;debug force to a value

While 1
    ;watch the console - the mouse is not moving correctly
    Sleep(10)   ;this works well and does not appear to use the CPU
WEnd


;================= Functions ==================

Func __UpMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]-(1*$scale))
    ;MouseMove($mousepos[0]-1, $mousepos[1]-(1*$scale)) ;working some of the time
    ;MouseMove($mousepos[0]+0, $mousepos[1]-(1/$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __UpMouse()" & @CRLF & "Before UP (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After UP (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2k
    ;ConsoleWrite("$mouseposafter[0] = " & $mouseposafter[0] & @CRLF & "$mousepos[0]+0 = " & $mousepos[0]+0 & @CRLF & @CRLF)
    ;If ( ($mouseposafter[0] <> $mousepos[0]+0) AND ($mouseposafter[1] <> $mousepos[1]-(1*$scale)) ) Then _DynamicallyCorrectMouseMove("UP", $mousepos[0], $mousepos[1])    ;check both coordinates, pass original information
    ;AND is WRONG it's OR
    If ( ($mouseposafter[0] <> $mousepos[0]+0) OR ($mouseposafter[1] <> $mousepos[1]-(1*$scale)) ) Then _DynamicallyCorrectMouseMove("UP", $mousepos[0], $mousepos[1])  ;check both coordinates, pass original information
EndFunc

Func __DownMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+0, $mousepos[1]+(1*$scale))
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __DownMouse()" & @CRLF & "Before DOWN (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After DOWN (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2k
    If ( ($mouseposafter[0] <> $mousepos[0]+0) OR ($mouseposafter[1] <> $mousepos[1]+(1*$scale)) ) Then _DynamicallyCorrectMouseMove("DOWN", $mousepos[0], $mousepos[1])    ;check both coordinates, pass original information
EndFunc

Func __LeftMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]-(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __LeftMouse()" & @CRLF & "Before LEFT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After LEFT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2k
    If ( ($mouseposafter[0] <> $mousepos[0]-(1*$scale)) OR ($mouseposafter[1] <> $mousepos[1]) ) Then _DynamicallyCorrectMouseMove("LEFT", $mousepos[0], $mousepos[1])  ;check both coordinates, pass original information
EndFunc

Func __RightMouse()
    Local $mousepos, $mouseposafter
    $mousepos = MouseGetPos()
    MouseMove($mousepos[0]+(1*$scale), $mousepos[1]+0)
    $mouseposafter = MouseGetPos()
    ConsoleWrite("in  __RightMouse()" & @CRLF & "Before RIGHT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After RIGHT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF)
    ;v2k
    If ( ($mouseposafter[0] <> $mousepos[0]+(1*$scale)) OR ($mouseposafter[1] <> $mousepos[1]) ) Then _DynamicallyCorrectMouseMove("RIGHT", $mousepos[0], $mousepos[1])     ;check both coordinates, pass original information
EndFunc


Func _GetScale()    ;returns a scale factor for PixelGetColor
    ;from: https://www.autoitscript.com/forum/topic/156251-mouse-coordinates/?tab=comments#comment-1130002
   $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]')
   $pDEVMODE = DllStructGetPtr($tDEVMODE)
   $i = 0

   while 1
      $ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE)
      if ($ret[0] = 0) then exitloop
      $width = DllStructGetData($tDEVMODE, 4, 2) ; native width
      $i += 1
   wend

   $scale = $width / @DesktopWidth
   Return($scale)
EndFunc



Func _DynamicallyCorrectMouseMove($sDirection, $iXorignal, $iYoriginal)     ;check that no X-axis movement, pass original information
    $iCaseExit = 0  ;effectively an ExitSelect.
                    ;just position Case $iCaseExit = 1  as the *next* Case statement as ContinueCase drops from the code in current Case into the code of the next Case
                    ;it DOES NOT evaluate the next Case statement, it just executes the next code which here is just reset the flag (i.e. $iCaseExit = 0)

    $iMouseSpeed = 0
    $debug = 0  ;0=off, 1=on

    Select
        Case StringUpper($sDirection) = "UP"
            ;okay we have the original coordinates and it messed up on the move up and also went left or right or too far up
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first - learned from running brute force and observing
            MouseMove($iXorignal-1, $iYoriginal-2, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then    ;we moved the correct amount
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,-2" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else    ;do the brute search +/-5 X and Y pixels from the original location
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount + 1   ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal-1)) Then    ;we moved the correct amount
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = -1,-2
                            ;so try this first before dropping into this
                            ;-1 makes sense as moving 1 X pixel to the right, -2 makes little sense as it moved correcly in Y direction but it works
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf


        Case StringUpper($sDirection) = "DOWN"
            ;okay we have the original coordinates and it messed up on the move down and also went left or right
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-0, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal+1)) Then    ;we moved the correct amount
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,0" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal) AND ($mousepos[1] = $iYoriginal+1)) Then    ;we moved the correct amount
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = -1,0
                            ;so try this first before dropping into this
                            ;-1 makes sense as moving 1 X pixel to the right, 0 makes little sense as it moved correcly in Y direction but it works
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf


        Case StringUpper($sDirection) = "LEFT"
            ;okay we have the original coordinates and it messed up on the move left and also went up or down
            ;so try dynamically to adjust
            ;try a brute force search pattern - limit it to 10 pixels

            ;try this first
            MouseMove($iXorignal-1, $iYoriginal-0, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then    ;we moved the correct amount
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -1,0" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                $iCaseExit = 1  ;exit Case
                ContinueCase
            EndIf

            ;try this second
            MouseMove($iXorignal-2, $iYoriginal-1, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then    ;we moved the correct amount
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using -2,-1" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                $iCaseExit = 1  ;exit Case
                ContinueCase
            EndIf

            ;else let's do the hunt
            $iCount = 0
            For $x = -5 to +5
                For $y = -5 to +5
                    $iCount = $iCount +1    ;get an idea of how many tries we needed
                    If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                    MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                    $mousepos = MouseGetPos()
                    If (($mousepos[0] = $iXorignal-1) AND ($mousepos[1] = $iYoriginal)) Then    ;we moved the correct amount
                        ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                        ;from testing most common is strange as there are 2 most common
                        ;one is $x,$y offset = -1,0 and the second is -2,-1
                        ;perhaps try -1,0 first then -2,-1
                        ;so try this first before dropping into this
                        ;-1 and -2 make no sense as moving 1 X pixel to the left, 0 and -1 make little sense
                        ExitLoop 2  ;we found it
                    EndIf
                Next
            Next


        Case $iCaseExit = 1 ;exit Case statement directly above
            If $debug = 1 Then Beep(2000, 100)      ;debug
            $iCaseExit = 0  ;reset it and drop to EndSelect


        Case StringUpper($sDirection) = "RIGHT"

            ;try this first
            MouseMove($iXorignal-0, $iYoriginal-1, $iMouseSpeed)
            $mousepos = MouseGetPos()
            If (($mousepos[0] = $iXorignal+1) AND ($mousepos[1] = $iYoriginal)) Then    ;we moved the correct amount
                If $debug = 1 Then Beep(1500, 25) ;debug to show we're still searching
                ConsoleWrite("in  _DynamicallyCorrectMouseMove using 0,-1" & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
            Else
                $iCount = 0
                For $x = -5 to +5
                    For $y = -5 to +5
                        $iCount = $iCount +1    ;get an idea of how many tries we needed
                        If $debug = 1 Then Beep(500, 25) ;debug to show we're still searching
                        MouseMove($iXorignal+$x, $iYoriginal+$y, $iMouseSpeed)
                        $mousepos = MouseGetPos()
                        If (($mousepos[0] = $iXorignal+1) AND ($mousepos[1] = $iYoriginal)) Then    ;we moved the correct amount
                            ConsoleWrite("in  _DynamicallyCorrectMouseMove   $x,$y offset = " & $x  & "," & $y & "  $iCount = " & $iCount & @CRLF & "After correction (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & @CRLF)
                            ;from testing most common is $x,$y offset = 0,-1
                            ;so try this first before dropping into this
                            ;0 makes no sense as moving 1 X pixel to the right
                            ExitLoop 2  ;we found it
                        EndIf
                    Next
                Next
            EndIf

        Case Else
            ;really messed up so do nothing

    EndSelect


EndFunc ;_DynamicallyCorrectMouseMove


Func Terminate()
    Beep(200, 200)
    Exit 0
EndFunc

 

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  

  • Similar Content

    • Lecdev
      By Lecdev
      Can anyone tell me the default parameter to input into, GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "")  to disable a previously set user defined function?
      help file example says empty string ("") which works for other events but doesnt seem to on mouse move.
      Ive attached some of my test code to select icon by clicking and click on screen where needed to create an icon the same or cancel by right clicking and then escape the window with the keyboard escape key. best solution i have come up with after a few hours of trying different things is to create a DoNothing() function
       
      any help would be appreciated.
      dummy2.au3
    • LegitStack
      By LegitStack
      So I'm trying to make a script that will move my mouse when I scroll. I know that's weird, but I have my reasons. What I have so far can detect when I'm moving my mouse, but then when I tell the script to make my mouse move whenever it detects scroll activity it freezes. probably because of some feedback loop.
      Anyway, If anyone on here wants to help, I'm at a loss of how to solve this problem. Like maybe when it is about to take the action of moving the mouse it could stop detection for a bit, idk. but I don't know how to do that.
       
       
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <MsgBoxConstants.au3> #include <Misc.au3> #include <GUIConstants.au3> Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo" Global $currentEvent Global $hDLL = DllOpen("user32.dll") #Region ### START Koda GUI section ### Form= ;Register callback $hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr") $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) #EndRegion ### END Koda GUI section ### While 1 WEnd Func _Mouse_Proc($nCode, $wParam, $lParam) Local $info, $mouseData If $nCode < 0 Then $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) $mouseData = DllStructGetData($info, 3) Select Case $wParam = $WM_MOUSEWHEEL If _WinAPI_HiWord($mouseData) > 0 Then ;Wheel Up $currentEvent = "WheelUp" Else ;Wheel Down $currentEvent = "WheelDown" If _IsPressed("02", $hDLL) Then MsgBox(0,"test","test") EndIf EndIf EndSelect ;;;;;;Mouse Movement CAUSES FREEZING, MAKES ME RESTART COMPUTER: if $currentEvent == "WheelUp" then $pos = MouseGetPos() MouseMove($pos[0]+100,$pos[1]+100,0) EndIf $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndFunc ;==>_Mouse_Proc Func OnAutoItExit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0]) $hM_Hook[0] = 0 DllCallbackFree($hKey_Proc) $hKey_Proc = 0 EndFunc ;==>OnAutoItExit  
    • Miliardsto
      By Miliardsto
      Hello I got this script works below and I want to do not move cursor on screen when action is performed.
      Opt("MouseCoordMode", 1) ; cause it gets whole screen coords Local $x, $y Local $search = _ImageSearch('item.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y,0) MouseClick("right", $x, $y)) MouseMove($xMiddle, $yMiddle,0) MouseClick("left", $xMiddle, $yMiddle) EndIf I changed this above to this below and what happen is. It clicks right button and then left button but not move mouse to $x $y and then to $xMiddle $yMiddle.
      Opt("MouseCoordMode", 1) ; cause it gets whole screen coords Local $x, $y Local $search = _ImageSearch('item.bmp', 0, $x, $y, 0) If $search = 1 Then ControlClick("","",0,"secondary",1,$x,$y) ControlClick("","",0,"primary",1,$xMiddle,$yMiddle) EndIf If needed I got handle in var $hwnd
      Please tell me how parameters in ControlClick would like be
    • Fuzy
      By Fuzy
      #include<img/img.au3>
      #include <AutoItConstants.au3>
      Func Skype()
      $coords = imageSearch(0,0,-1,-1,"Skype.PNG")
      MouseMove($coords[0],$coords[1])
      [when it find the skype icon i want it to move from these coordinates, but of insted of moving to an expecific coordinate i want it to move down from these coordinates, (there is multiple images so i cant move to an specific image)] -- Kinda having trouble telling what i want cuz english isnt my first language, sorry about that. ;X
      MouseClick($MOUSE_CLICK_LEFT)
    • Stormgrade
      By Stormgrade
      Hello,
      I want to use the "_ChangeScreenResEx()" UDF for changing my display settings from 1680*1050 to 1280*800.
      When I use it the display change to 1280*800 but with Intel Drivers, Scaling option change : Maintain display Scaling become Center Image.

      Here my Main program
      #include <.\_ChangeResolutionEx.au3> Global $Config = @ScriptDir & "\ChangeResolution.ini" Global $aSection = IniReadSectionNames($Config) Global $Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh for $i = 1 to $aSection[0] Step 1 $Moniteur = Number($i) $Largeur = Number(IniRead($Config,$i,"Width","1680")) $Hauteur = Number(IniRead($Config,$i,"Height","1050")) $Profondeur = Number(IniRead($Config,$i,"Bits","32")) $Refresh = Number(IniRead($Config,$i,"Refresh","60")) _ChangeScreenResEx($Moniteur,$Largeur,$Hauteur,$Profondeur,$Refresh) Sleep(1000) Next  _ChangeScreenResEx()
      #include-once ;=============================================================================== ; Function Name: _ChangeScreenResEx() ; Description: Changes the current screen geometry, colour and refresh rate. ; Version: 1.0.0.0 ; Parameter(s): $i_DisplayNum - Display to change, starting at 1 ; $i_Width - Width of the desktop screen in pixels. (horizontal resolution) ; $i_Height - Height of the desktop screen in pixels. (vertical resolution) ; $i_BitsPP - Depth of the desktop screen in bits per pixel. ; $i_RefreshRate - Refresh rate of the desktop screen in hertz. ; Requirement(s): AutoIt Beta > 3.1 ; Return Value(s): On Success - Screen is adjusted, @ERROR = 0 ; On Failure - sets @ERROR = 1 ; Forum(s): ; Author(s): Original code - psandu.ro, PartyPooper ; Modifications - bobchernow ;=============================================================================== Func _ChangeScreenResEx($i_DisplayNum = 1, $i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate = @DesktopRefresh) Local Const $DM_PELSWIDTH = 0x00080000 Local Const $DM_PELSHEIGHT = 0x00100000 Local Const $DM_BITSPERPEL = 0x00040000 Local Const $DM_DISPLAYFREQUENCY = 0x00400000 Local Const $CDS_TEST = 0x00000002 Local Const $CDS_UPDATEREGISTRY = 0x00000001 Local Const $DISP_CHANGE_RESTART = 1 Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local Const $HWND_BROADCAST = 0xffff Local Const $WM_DISPLAYCHANGE = 0x007E If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth; default to current setting If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight; default to current setting If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth; default to current setting If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh; default to current setting Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") Local $s_Display $s_Display = "\\.\Display" & $i_DisplayNum Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "int", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then $B = 0 SetError(1) Return $B Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) DllStructSetData($DEVMODE, 4, $i_Width, 2) DllStructSetData($DEVMODE, 4, $i_Height, 3) DllStructSetData($DEVMODE, 4, $i_BitsPP, 1) DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5) $B = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_TEST, "lparam", 0) If @error Then $B = -1 Else $B = $B[0] EndIf Select Case $B = $DISP_CHANGE_RESTART $DEVMODE = "" Return 2 Case $B = $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "int", "ChangeDisplaySettingsEx","str", $s_Display, "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "dword", $CDS_UPDATEREGISTRY, "lparam", 0) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" SetError(1) Return $B EndSelect EndIf EndFunc;==>_ChangeScreenResEx Any idea how to get around this problem ?
      thanks for your answer.
×