Jump to content

MouseCoordMode "Issues"


Go to solution Solved by ioa747,

Recommended Posts

Posted (edited)

Good day,

When you think you know, you discover how little you actually DO know!

As I am now implementing more "automaton" in my scripts, I would prefer to implement  Opt("MouseCoordMode", 0) in such scripts.

However, there are times when MouseCoordMode 0 simply DOES NOT WORK! Thus, I am wondering if the following is acceptable...or NOT?

Spoiler
; -----------------------------------------------
; 4/17/2026 9:58:37 AM
; -----------------------------------------------
#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 0) ; ⚠ Invoke MouseCoordMode "0"
; -----------------------------------------------
Global $iTimeOut = 100
Global $iExtTimeOut = 2000
; ---------------------
Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
Global $hMAIN_BKGRND = "[CLASS:MAIN_BKGRND]"
Global $sSrcMixSessionPath = "C:\RML\SAC\SAC64.exe G:\Session_Master\Session_Master.mxs"
; -----------------------------------------------
LaunchSACWSF()
; -----------------------------------------------
Func LaunchSACWSF()
    Local $sSrcPath = $sSrcMixSessionPath
    ; -----------------------------------------------
    Run($sSrcPath)
    ; ---------------------
    WinWait($hSAC_MAIN)
    WinActivate($hSAC_MAIN)
    ; ---------------------
    ControlClick($hSAC_MAIN, "", "", "", 1, 24, 32)
    ; ---------------------
    Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
    MouseMove(953, 545, 0)
    Opt("MouseCoordMode", 0) ; ⚠ Invoke MouseCoordMode "0"
    ; ---------------------
    Sleep($iExtTimeOut)
EndFunc   ;==>LaunchSACWSF
; -----------------------------------------------

Also, in the following examples, why does the following "work"...

Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
    MouseMove(953, 545, 0)

...and yet, the following DOES NOT?...

Opt("MouseCoordMode", 0) ; ⚠ Invoke MouseCoordMode "1"
    ControlClick($hSAC_MAIN, "", "", "", 1, 953, 545)

 

Edited by mr-es335
Posted (edited)

Hello,

Believe me, I have...many, many times!!!

What is it that I am "missing" as a result of my not being able to properly "read" the reference?

From Eh-Eye...

Quote

Reasons Why ControlClick() May Not Work

Control Compatibility

ControlClick() may fail if the control you are trying to interact with does not accept messages sent by it. This is common with certain types of controls, such as Java applets or custom GUI elements that do not respond to standard Windows messages.

Coordinate Issues

ControlClick() requires precise coordinates relative to the control itself. If the coordinates are not set correctly, the function may not work as intended. Ensure that you are using the correct coordinates for the specific control.

Focus and Activation

ControlClick() does not move the mouse cursor; it sends a message directly to the control. If the control is not active or in focus, the click may not register. Always ensure that the window containing the control is active before calling ControlClick().

Now...as to my original query, is the follo9wing an acceptable workaround?

Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
    MouseMove(953, 545, 0)
    Opt("MouseCoordMode", 0) ; ⚠ Invoke MouseCoordMode "0"

 

Edited by mr-es335
  • Solution
Posted (edited)

There are two main reasons why your code is failing:

Missing Control Information
In your ControlClick command, you’ve left the ControlID parameter empty:
ControlClick($hSAC_MAIN, "", "", "", 1, 953, 545)
While this is syntactically allowed, it tells AutoIt to click the "main" window rather than a specific button or element.
It is always better to provide the ID, ClassNameNN, or Text of the control you want to target.

Relative Coordinates Misunderstanding
The X and Y parameters in ControlClick are relative to the control itself, not the screen or the window.
    By default, if you leave X and Y blank, AutoIt clicks the center of the control.
    By entering 953, 545, you are telling AutoIt to click nearly 1000 pixels to the right and 500 pixels down from the top-left corner of that specific control.
Unless you have a button that is massive (larger than 1906 x 1090 pixels), those coordinates are clicking completely outside the target area.


Edit:
It would be better not to put dimensions at all, just to give a reference to which control it referred to.

Edited by ioa747

I know that I know nothing

Posted (edited)

ioa747,

I kinda figur'd so! Many of the elements within SAC or SAW, have no such ID, ClassNameNN, or Texts to reference to.

Hhhhmmmmm...I do NOW believe that this whole situation maybe "just clicked-in"!?!?

In employing ControlClick($hSAC_MAIN, "", "", "", 1, 24, 32), as there is a physical object located at those coordinates, ControlClick "does what it does"!

However, I WAS hoping that ControlClick would actually re-position the mouse pointer - which is NOT the purpose of ControlClick!?!?
• Duh!!! [Click_Me]

Again, if I need to employ Mode 1, is the following sampling a workable solution for  going from Mode 1 back to Mode 0?

Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
    MouseMove(953, 545, 0)
    Opt("MouseCoordMode", 0) ; ⚠ Invoke MouseCoordMode "0"

Please let me know?!? Thanks!

Edited by mr-es335
Posted
49 minutes ago, mr-es335 said:

Many of the elements within SAC or SAW, have no such ID, ClassNameNN, or Texts to reference to.


with the autoit info tool mark the button you want (what you want to click)
and post the results from the Summary tab
to see if there is anything  👀

I know that I know nothing

Posted
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 0)
; -----------------------------------------------
Global $oldMode = Opt("MouseCoordMode", 0)
; -----------------------------------------------
; Store current mode, then set to Screen mode
Local $newMode = Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
ConsoleWrite(Opt("MouseCoordMode", $newMode) & @CRLF)
MouseMove(953, 545, 0)
Opt("MouseCoordMode", $oldMode) ; ⚠ restore back to oldMode
ConsoleWrite($oldMode & @CRLF)
; -----------------------------------------------

 

Posted
8 minutes ago, ioa747 said:

with the autoit info tool mark the button you want (what you want to click)
and post the results from the Summary tab
to see if there is anything  👀

There are no buttons or controls....I was just wanting to position the mouse pointer in the centre of the screen employing ControlClick rather than MouseClick - but NOW see that this is impossible!

Posted
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client
; -----------------------------------------------
; Store current mode, then set to Screen mode
Local $oldMode = Opt("MouseCoordMode", 1) ; ⚠ Invoke MouseCoordMode "1"
ConsoleWrite("$oldMode=" & $oldMode & @CRLF)
MouseMove(953, 545, 0)
Opt("MouseCoordMode", $oldMode) ; ⚠ restore back to oldMode
; -----------------------------------------------

 

I know that I know nothing

Posted (edited)

This seems to do the "trick"...for SAC - which requires "0":

Spoiler
; -----------------------------------------------
; 4/17/2026 3:06:14 PM
; -----------------------------------------------
#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 1)
; -----------------------------------------------
Global $iTimeOut = 100
Global $iExtTimeOut = 2000
; ---------------------
Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
Global $sSrcAppPathSAC = "C:\RML\SAC\SAC64.exe"
; -----------------------------------------------
ConsoleWrite("Before function call: " & Opt("MouseCoordMode") & @CRLF)
ConfirmMode0()
LaunchSAC()
; -----------------------------------------------
Func ConfirmMode0()
    If Opt("MouseCoordMode") = 1 Then
        Opt("MouseCoordMode", 0)
        ConsoleWrite("In ConfirmMode0, updated MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    Else
        ConsoleWrite("In ConfirmMode0, current MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    EndIf
EndFunc   ;==>ConfirmMode0
; -----------------------------------------------
Func LaunchSAC()
    ConsoleWrite("In LaunchSAC, current MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    Local $sSrcApp = $sSrcAppPathSAC
    ; ---------------------
    Run($sSrcApp)
    ; ---------------------
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)
    ; ---------------------
    MouseMove(953, 543, 0)
    ; ---------------------
    Sleep($iExtTimeOut)
EndFunc   ;==>LaunchSAC
; -----------------------------------------------

...for SAW - which requires "1":

Spoiler
; -----------------------------------------------
; 4/18/2026 7:43:32 AM
; -----------------------------------------------
#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 0)
; -----------------------------------------------
Global $iTimeOut = 100
Global $iExtTimeOut = 2000
; ---------------------
Global $sSrcAppPathSAW = "C:\RML\SAW\SAWStudio64.exe"
; -----------------------------------------------
ConsoleWrite("Before function call: " & Opt("MouseCoordMode") & @CRLF)
ConfirmMode1()
LaunchSAW()
; -----------------------------------------------
Func ConfirmMode1()
    If Opt("MouseCoordMode") = 0 Then
        Opt("MouseCoordMode", 1)
        ConsoleWrite("In ConfirmMode1, updated MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    Else
        ConsoleWrite("In ConfirmMode1, current MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    EndIf
EndFunc   ;==>ConfirmMode1
; -----------------------------------------------
Func LaunchSAW()
    ConsoleWrite("In LaunchSAW, current MouseCoordMode is: " & Opt("MouseCoordMode") & @CRLF)
    Local $sSrcApp = $sSrcAppPathSAW
    ; ---------------------
    Run($sSrcApp)
    ; ---------------------
    MouseMove(953, 543, 0)
    ; ---------------------
    Sleep($iExtTimeOut)
EndFunc   ;==>LaunchSAW
; -----------------------------------------------

 

 

Edited by mr-es335
Posted

Why? Isn't this cleaner?

; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 1)

Global $iTimeOut = 100
Global $iExtTimeOut = 2000

Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
Global $sSrcAppPathSAC = "C:\RML\SAC\SAC64.exe"

LaunchSAC()
; -----------------------------------------------
Func LaunchSAC()
    Local $oldMode = Opt("MouseCoordMode", 0)
    Local $sSrcApp = $sSrcAppPathSAC

    Run($sSrcApp)

    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)

    MouseMove(953, 543, 0)

    Sleep($iExtTimeOut)
    Opt("MouseCoordMode", $oldMode)
EndFunc   ;==>LaunchSAC
; -----------------------------------------------

 

Does it seem cleaner to you?

; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 1)

Global $iTimeOut = 100
Global $iExtTimeOut = 2000

Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
Global $sSrcAppPathSAC = "C:\RML\SAC\SAC64.exe"

LaunchSAC()
; -----------------------------------------------
Func LaunchSAC()
    Local $oldMode = Opt("MouseCoordMode")
    Opt("MouseCoordMode", 0)
    Local $sSrcApp = $sSrcAppPathSAC

    Run($sSrcApp)

    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)

    MouseMove(953, 543, 0)

    Sleep($iExtTimeOut)
    Opt("MouseCoordMode", $oldMode)
EndFunc   ;==>LaunchSAC
; -----------------------------------------------

the result is always the same 

I know that I know nothing

Posted (edited)

There is a logical "gap" in your LaunchSAC() function that might cause it to fail intermittently.

Since you are using Opt("MouseCoordMode", 0),
your mouse actions are now relative to the Active Window.
However, your script doesn't guarantee which window is active when the click happens.


You should use WinWait and WinActivate to ensure the script waits for the window to exist and brings it to the front before clicking.

Func LaunchSAC()
    Local $oldMode = Opt("MouseCoordMode", 0) ; Set to 0 and store old mode in one line
    
    Run($sSrcAppPathSAC)

    ; Wait for the window to exist and make it active
    WinWait($hSAC_MAIN) 
    WinActivate($hSAC_MAIN)
    WinWaitActive($hSAC_MAIN) ; Ensure it is focused before clicking

    ; Now these coordinates are guaranteed to be relative to the SAC window
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)
    MouseMove(953, 543, 0)

    Sleep($iExtTimeOut)
    Opt("MouseCoordMode", $oldMode)
EndFunc   ;==>LaunchSAC


By adding WinWaitActive, you bridge the gap between "starting the app" and "interacting with it."
This ensures that MouseCoordMode 0 always has the correct reference Window.

Edited by ioa747

I know that I know nothing

Posted (edited)

ioa747,

I have, I do believe, thoroughly tested the Lau9chSAC script with and without WinWait()...and I have yet to see...or have...and issue!

I developed the following as a "testing" procedure:

#cs
; 6:50 AM 3/2/2026

Opt("MouseCoordMode", 0)
MouseMove(27, 54, 0)    ; Preferred

Opt("MouseCoordMode", 1)
MouseMove(24, 52, 0)    ; Preferred

Opt("MouseCoordMode", 2)
MouseMove(24, 32, 0)    ; Preferred
#ce
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 1)
; -----------------------------------------------
Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
; -----------------------------------------------
MouseMoveTestLIVE()
; -----------------------------------------------
Func MouseMoveTestLIVE()
    WinActivate($hSAC_MAIN)
    ; -----------------------------------------------
    Local $currentMode = Opt("MouseCoordMode")
    ; -----------------------------------------------
    If $currentMode = 0 Then
        MouseMove(27, 54, 0)
    ElseIf $currentMode = 1 Then
        MouseMove(24, 52, 0)
    ElseIf $currentMode = 2 Then
        MouseMove(24, 32, 0)
    EndIf
    ConsoleWrite("Current MouseCoordMode: " & $currentMode & @CRLF)
EndFunc   ;==>MouseMoveTestLIVE
; -----------------------------------------------
Edited by mr-es335
Posted

Hhhhmmmm...after testing your suggestion, with WinWait() and WinWaitActive() enabled, the mouse never gets to 953, 543!!

I did discover previously, that Sleep($iTimeOut) is required before the MouseClick() however.

Posted (edited)

To make it crystal clear, let's look at what happens when you tell AutoIt to move to (0, 0) in both modes.

Imagine your SAC window is sitting in the middle of your screen.

Opt("MouseCoordMode", 1) = Global/Screen Mode
The Origin (0,0): The very top-left corner of your physical monitor.
 

Opt("MouseCoordMode", 0) = Window Mode
The Origin (0,0): The top-left corner of the Active Window (the SAC title bar).

Why your test is misleading you:
In your test, you used 24, 52.

In Mode 0, that is a button inside SAC.

In Mode 1, that is a spot on your desktop wallpaper.

The only reason they both clicked the same thing in your test is that your SAC window was perfectly aligned at the top-left of your monitor (0,0).
If you move the window just a few inches to the right, your Mode 1 script will click empty space, while your Mode 0 script will still hit the button perfectly.

Conclusion:
For true "automaton," never use Mode 1 for clicking inside apps.
Stick to Mode 0 (Window) or Mode 2 (Client), and your script will work on any screen resolution and any window position!

Edited by ioa747

I know that I know nothing

Posted (edited)
29 minutes ago, mr-es335 said:

Hhhhmmmm...after testing your suggestion, with WinWait() and WinWaitActive() enabled, the mouse never gets to 953, 543!!

it works but it starts counting from the top left corner of your window and maybe goes off screen

 

Edit:
What are the dimensions of your window?

Edited by ioa747

I know that I know nothing

Posted (edited)

Ok!

I maximize me "views" - thus the positioning should always be the same. The main views will never be any different than they currently are.

Regarding your sampling, I do have following:

#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 1)
; -----------------------------------------------
Global $iTimeOut = 100
Global $iExtTimeOut = 2000
; -----------------------------------------------
Global $hSAC_MAIN = "[CLASS:SAC_MAIN]"
Global $sSrcAppPathSAC = "C:\RML\SAC\SAC64.exe"
; -----------------------------------------------
LaunchSAC()
; -----------------------------------------------
Func LaunchSAC()
    Local $oldMode = Opt("MouseCoordMode", 0)
    ConsoleWrite($oldMode & @CRLF) ; <<<<=== Here the value of $oldMode is 1, should this value NOT be 0??
    Local $sSrcApp = $sSrcAppPathSAC
    ConsoleWrite(Opt("MouseCoordMode") & @CRLF) ; <<<<=== Here the value of $oldMode is 0
; -----------------------------------------------
    Run($sSrcApp)
; -----------------------------------------------
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)
; -----------------------------------------------
    MouseMove(953, 543, 0)
; -----------------------------------------------
    Sleep($iExtTimeOut)
    Opt("MouseCoordMode", $oldMode)
    ConsoleWrite($oldMode & @CRLF) ; <<<<=== Here the value of $oldMode is 1
EndFunc   ;==>LaunchSAC
; -----------------------------------------------

I must admit, I am VERY  confused here!!

UPDATE!
Okay! I so see my partial confusion here, just because $oldMode has been "locally" declared, that value has NOT YET been implemented!
• When I then execute the 1st ConsoleWrite(), the updated value of $oldMode is then displayed.

However, whys is the 2nd ConsoleWrite() not displaying the value of $oldMode correctly?

Edited by mr-es335
Posted (edited)

In AutoIt, when you use Opt("Option", NewValue), the function does two things at once
It changes the setting to the NewValue.
It returns the Previous value (the one that was active before the change).

So, in your code
Local $oldMode = Opt("MouseCoordMode", 0)
The script sees that the current mode is 1 (from the top of your script).

It changes the mode to 0.

It "hands" you the number 1 to store in $oldMode, so you can remember what the setting was before you changed it.

This is why your second ConsoleWrite(Opt("MouseCoordMode")) shows 0.
The change happened successfully, but $oldMode is just a "memo" of the past.

 

Edit:
if you want to see the current status, you would put it without a parameter
ConsoleWrite("MouseCoordMode now = " & Opt("MouseCoordMode") & @CRLF)

AutoItSetOption

Changes the operation of various AutoIt functions/parameters.

AutoItSetOption ( "option" [, param] )

Parameters

option The option to change. See Remarks.
param [optional] The value to assign to the option. The type and meaning vary by option. See remarks below. If the param is not provided, then the function just returns the value already assigned to the option. The keyword Default can be used for the parameter to reset the option to its default value.

Return Value

Success: the value of the previous setting for the option.
Failure: sets the @error flag to non-zero. Failure will occur if the parameters are invalid (such as an option that does not exist).
 

 

Edited by ioa747

I know that I know nothing

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
×
×
  • Create New...