Skip to content

Instantly share code, notes, and snippets.

@NazCodeland
Created April 15, 2024 14:19
Show Gist options
  • Save NazCodeland/5a9400258b5408714e0f37905478dfef to your computer and use it in GitHub Desktop.
Save NazCodeland/5a9400258b5408714e0f37905478dfef to your computer and use it in GitHub Desktop.
Captures the current mouse position, reads a target position from a file, moves the mouse to the target position without delay.
#include <File.au3>
; Get the current coordinates
$currentCoords = MouseGetPos()
; The x and y coordinates should be saved on one line separated by a comma. Example: 200,400
$newCoordsString = FileRead("./coordinates.txt")
; Close the file after reading
FileClose("./coordinates.txt")
; Split the string into an array using comma as the delimiter
$newCoords = StringSplit($newCoordsString, ",")
; Move the mouse to the new coordinates
MouseMove($newCoords[1], $newCoords[2], 0)
; Open the file for writing and overwrite the original coordinates
$file = FileOpen("./coordinates.txt", 2)
; Check if the file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
FileWrite($file, $currentCoords[0] & "," & $currentCoords[1])
; Close the file
FileClose($file)
Exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment