MouseMove Issue Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Ashkael
Posts: 2
Joined: 10 Oct 2018, 17:20

MouseMove Issue

10 Oct 2018, 17:38

Hello,
I would like to ask for some help regarding non-functioning MouseMove command that I just do not understand (I just started using autohotkey yesterday, so sorry if this is a silly question :D ).
So basically this is my code from the start till the erroneous line:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^!o::
CoordMode, Mouse, Screen
Loop, 10
{
 Send, {Ctrl down}{PgUp}{Ctrl up}

}
Send, {Ctrl down}{Home}{Ctrl up}
Send, {Down}{Down}{Right}
Sleep, 100
Send, {Ctrl down}{PgDn}{Ctrl up}
Sleep, 100
Send, {Ctrl down}{Home}{Ctrl up}
Send, {Down}{Down}{Right}
Send, {Ctrl down}{PgDn}{Ctrl up}
Sleep, 100
Send, {Ctrl down}{Home}{Ctrl up}
Send, {Down}{Down}{Right}
Send, {Ctrl down}{PgDn}{Ctrl up}
Sleep, 100
Send, {Ctrl down}{Home}{Ctrl up}
Send, {Down}{Down}{Right}
Send, {Ctrl down}{PgDn}{Ctrl up}
Sleep, 100
Send, {Ctrl down}{Home}{Ctrl up}
Send, {Down}{Down}{Right}
Sleep, 200
Send, {Alt down}{Tab}{Alt up}
MouseMove, 330, 147
Sleep, 200

Gui, Add, text, , Enter Amount of HPLC Runs :):
Gui, Add, Edit, vNum
Gui, Add, Button, default, OK
Gui, Show
Return

GuiClose:
ButtonOK:
Gui, Submit

Loop, %Num%
{
 MouseGetPos, CoordXRec, CoordYRec
 Sleep, 200
 Click, 2
 Sleep, 1500
 Click, right
 Sleep, 200
 MouseMove, 250, 98, , R
 Sleep, 500
 MouseMove, 50, 20, , R
 Sleep, 200
 Click
 Sleep, 200
MouseMove, 100, 380
For some reason, the "MouseMove, 100, 380" command places mouse cursor to position 175, 499 relative to the screen rather than 100, 380 and I just can not understand that to save my life. If I'm not missing anything, the MouseMove command should definitely be relative to the screen because I have "CoordMode, Mouse, Screen" as my first line. I found another command, "DllCall("SetCursorPos", int, 100, int, 380)", which fixed the problem for me, and placed the mouse cursor to 100, 380, making the rest of my code function. However, that does not explain why MouseMove didn't work for me in the first place, and I would like to ask, what am I missing?
Noesis
Posts: 299
Joined: 26 Apr 2014, 07:57

Re: MouseMove Issue  Topic is solved

11 Oct 2018, 00:24

Ashkael wrote: the MouseMove command should definitely be relative to the screen because I have "CoordMode, Mouse, Screen" as my first line.
This is what you are missing, you have the CoordMode as the first line within a hotkey (not within the autoexecute section) so it only applies to the hotkey which contains it i.e the ^!o hotkey. The misbehaving mousemove lies outside the scope of this hotkey so is using the default mode of window coords.

To fix it move the coordmode line into the autoexecute section, which is essentially the top of the script before any returns or hotkey definitions, so in your case it needs to be above the ^!o:: hotkey definition line, instead of below it.
Ashkael
Posts: 2
Joined: 10 Oct 2018, 17:20

Re: MouseMove Issue

11 Oct 2018, 11:16

Thank you for speedy reply, I tested the code today by "inserting CoordMode, Mouse, Screen" in autoexecute section and changing all the " "DllCall("SetCursorPos"" lines with MouseMove, and the script remained functioning :). I would never have figured it out myself so thanks for all the help!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Bort P, Desperate for my F9, ElektroBerry, flint, Gully, KHA, mehrez1989, SuperFoobar and 200 guests