1

I'm creating a program where everything works fine, except for the MouseMove instruction. i got the x,y coordinates from using GetMousePos then saving it to the clipboard

Why is MouseMove not actually moving my mouse cursor?

F1::
Loop
{
SendInput 1
Sleep, 500
Click
Sleep, 500
SendInput x
Sleep, 500
Click
Sleep, 500
SendInput e
Sleep, 500
MouseMove, 587, 593
Sleep, 500
Click
MouseMove, 600, 135
Sleep, 500
}
return

F2::ExitApp
1
  • Does adding a speed parameter to MouseMove do anything? E.g.: MouseMove, 587, 593, 10 (10 = speed (1-100), the higher the number, the slower the movement). Commented Oct 23 at 18:56

1 Answer 1

1

Auto Hot key uses window-relative coordinates, not screen-relative unless you explicitly set it

Try this v1 script:

#NoEnv
#SingleInstance Force
SendMode Input
CoordMode, Mouse, Screen
FileCreateDir, C:\data

; F1 starts loop
F1::
Loop
{
    SendInput 1
    Sleep, 500
    Click
    Sleep, 500
    SendInput x
    Sleep, 500
    Click
    Sleep, 500
    SendInput e
    Sleep, 500
    MouseMove, 587, 593
    Sleep, 500
    Click
    Sleep, 500
    MouseMove, 600, 135
    Sleep, 500
}
return

; F2 exits
F2::ExitApp

; F3 logs mouse pos + timestamp and beeps
F3::
MouseGetPos, xpos, ypos
FormatTime, timestamp,, yyyy-MM-dd HH:mm:ss
FileAppend, Screen %xpos%`,%ypos% - %timestamp%`r`n, C:\data\myclicks.txt
SoundBeep
return

https://www.autohotkey.com/docs/v2/lib/CoordMode.htm

The default coordinate system for many commands depends on the AutoHotkey version:

  • AutoHotkey v2: The default is Client, meaning coordinates are relative to the active window's client area (the part of the window that excludes the title bar and borders).

  • AutoHotkey v1: The default is Window (or ), where coordinates are relative to the active window, including its borders and title bar.

This is an outline for a v2 script:

#Requires AutoHotkey v2.0

SendMode "Input"
CoordMode "Mouse", "Screen"

; Ensure folder exists
if !DirExist("C:\data")
    DirCreate("C:\data")

; F1 starts the infinite loop
F1::
{
    Loop
    {
        Sleep(2500)

        MouseMove(587, 593)
 
        Sleep(500)
        SoundBeep()
    }
}

; F2 exits the script
F2::ExitApp()

; F3 logs mouse position + time
F3::
{
    MouseGetPos(&xpos, &ypos)
    timestamp := FormatTime(, "yyyy-MM-dd HH:mm:ss")
    FileAppend("Screen " xpos "," ypos " - " timestamp "`r`n", "C:\data\myclicks.txt")
    SoundBeep()
}

Note: Feel free to customize the folder where you save the clicks by changing C:\data in the top and bottom of script

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.