Jump to content

Clone mouse movements


krpandrei
 Share

Recommended Posts

Hello @all

I'm wondering that this event can be done in AutoIt:

To clone the mouse movements from an app./tool window let's say instance_1 with content_1 to the same app. but this time window instance_2 with content_2.

Just for the porpoise to compare two verions of one map (in my case) in the same time side by side using same app./tool

THX!

Link to comment
Share on other sites

Who cares if it's for a game bot or not. I certainly don't, so let's focus on solving your problem.

; Script function: DOUBLE CLICKS
; Version: 0.0 alpha
; Features:
; Esc to terminate script, Pause/Break to "pause"


Opt("MouseCoordMode", 0)        ;1=absolute, 0=relative, 2=client

; Change into the WinTitleMatchMode that supports classnames and handles
AutoItSetOption("WinTitleMatchMode", 4)

; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

; Prompt the user to run the script - use a Yes/No prompt
$answer = MsgBox(4, "AutoIt Script", "Run?")

; Check the user's answer to the prompt
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    Terminate()
EndIf

;HANDLE WINDOWS

$DesktopWidth=1280
$DesktopHeight=1024-25

;Minimizes all windows
WinMinimizeAll()

; Get the handle of a notepad window 1 and resize & move to left
Run("notepad.exe")
WinWaitActive("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
$handle1 = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
    WinMove($handle1, "", 0, 0, $DesktopWidth/2, $DesktopHeight)
EndIf

; Get the handle of a notepad window 2 and resize & move to right
Run("notepad.exe")
WinWaitActive("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
$handle2 = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:2]", "")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
    WinMove($handle2, "", $DesktopWidth/2, 0, $DesktopWidth/2, $DesktopHeight)
EndIf

Mouse()

Func Mouse()
$x = MouseGetPos(0)
$y = MouseGetPos(1)

;~  ;decide in what window the click was made
;~  If wuindow 1
;~  ;select window 2
;~  ;execute function clicksendL2R
;~  Else
;~  If wuindow 2
;~  ;select window 1
;~  ;execute function clicksendR2L

While 1 ;infinite loop
If WinActive($handle1) Or MouseDown("primary")=1 Then
    ;If $x < $DesktopWidth/2 Then
        WinActivate($handle2, "")
        ;MouseClick ( "primary", $x, $y)
        Sleep(500)
    ElseIf WinActive($handle2) Or MouseDown("primary")=1 Then
        WinActivate($handle1, "")
        ;MouseClick ( "primary", $x, $y)
        Sleep(500)
EndIf
WEnd
EndFunc   ;==>Mouse

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    MsgBox(0, "Stop", "OK.  Bye!")
    Exit 0
EndFunc   ;==>Terminate

I used Notepad windows just for example until the whole script will work

This is what I done so far but I have some problems with my noobe code:

How can I distinguish better between two Notepad windows using &handle or something else because my Mouse function gets stuck on selection between windows ?

Link to comment
Share on other sites

MouseCoordMode 0 means relative coords to the active window. In other words, you have to activate the window first, and then do the mouse move.

Some bad code in your script. And here's an example:

; Script function: DOUBLE CLICKS
; Version: 0.0 alpha
; Features:
; Esc to terminate script, Pause/Break to "pause"


Opt("MouseCoordMode", 0)        ;1=absolute, 0=relative, 2=client

; Change into the WinTitleMatchMode that supports classnames and handles
; AutoItSetOption("WinTitleMatchMode", 4) ; DECREPATED!!

; Press Esc to terminate script, Pause/Break to "pause"
Local $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

#region Useless
; Prompt the user to run the script - use a Yes/No prompt
;$answer = MsgBox(4, "AutoIt Script", "Run?")

; Check the user's answer to the prompt
; If "No" was clicked (7) then exit the script
;If $answer = 7 Then
    ;Terminate()
;EndIf
#endregion

;HANDLE WINDOWS

$DesktopWidth= @DesktopWidth
$DesktopHeight= @DesktopHeight

;Minimizes all windows
WinMinimizeAll()

; Get the handle of a notepad window 1 and resize & move to left
Run("notepad.exe")
WinWaitActive("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
$handle1 = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
    WinMove($handle1, "", 0, 0, $DesktopWidth/2, $DesktopHeight)
EndIf

; Get the handle of a notepad window 2 and resize & move to right
Run("notepad.exe")
WinWaitActive("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:1]", "")
$handle2 = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad; ACTIVE; INSTANCE:2]", "")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
    WinMove($handle2, "", $DesktopWidth/2, 0, $DesktopWidth/2, $DesktopHeight)
EndIf

_ClickBoth("Left", 30, 35)

Exit

Func _MoveBoth($x, $y, $speed)
    _WinActivateWait($handle1)
    MouseMove($x, $y, $speed)
    Sleep(200)
    
    _WinActivateWait($handle2)
    MouseMove($x, $y, $speed)
    Sleep(200)
EndFunc


Func _ClickBoth($mousebutton, $x, $y, $clicks = 1, $speed = 0)
    _WinActivateWait($handle1)
    MouseClick($mousebutton, $x, $y, $clicks, $speed)
    Sleep(200)
    
    _WinActivateWait($handle2)
    MouseClick($mousebutton, $x, $y, $clicks, $speed)
    Sleep(200)
EndFunc

Func _WinActivateWait($handle)
    WinActivate($handle)
    WinWaitActive($handle)
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    MsgBox(0, "Stop", "OK.  Bye!")
    Exit 0
EndFunc   ;==>Terminate
Edited by Manadar
Link to comment
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
 Share

  • Recently Browsing   0 members

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