autohotkeymousemove

MouseMove is not moving the mouse cursor


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

Solution

  • 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:

    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