image search mouse doesnt click target

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NewberEnerNeeder1
Posts: 47
Joined: 26 Mar 2019, 06:06

image search mouse doesnt click target

Post by NewberEnerNeeder1 » 26 Jan 2023, 15:13

Code: Select all

        {
        	sleep 200
        	MouseGetPos, xpos, ypos 
        	MouseGetPos,,, WinUMID
            sleep 200
        	MOUSECLICK,RIGHT, %FoundX1%,%FoundY1%
            sleep 200
        	Mousemove, %xpos%, %ypos%
        	WinActivate, ahk_id %WinUMID%
        	sleep 2000
        }
it finds the target and the mouse moves to the target but it doesnt click it

i tried left click and right click and i also tried sleep 200 delays and double clicking it

help!

User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Re: image search mouse doesnt click target

Post by BrockPlaysFortnite » 26 Jan 2023, 16:00

You have the mouseclick before the mousemove so it's clicking first then landing on the image

I don't know what %FoundX1%,%FoundY1% mean but I assume this is what you are trying to do

Code: Select all

       {
        	MouseGetPos, xpos, ypos 
        	;MouseGetPos,,, WinUMID I am not sure what this line is for but I think it might overwrite the last one
            sleep 200
        	Mousemove, %xpos%, %ypos% ;will move mouse first
	  	    sleep 200      	
        	MouseClick    ;will single click 
            sleep 200
        	WinActivate, ahk_id %WinUMID%
        	sleep 2000
        }
if this is not what you are trying to do we need to see the imagesearch code to see what else might be going wrong. (I'll guess that %FoundX1%,%FoundY1% are the results of your imagesearch?) If it's finding the target though then the problem has to be with the MouseClick. I personally always use image search like this. It could be you're not giving it enough of a sleep to actually be on top of the image before it clicks. To be absolutely sure use a very large number like 5000 as a test

Code: Select all

MouseMove, ImageFoundX, ImageFoundY
sleep 5000
MouseClick

;not sure why but I always do it this way ^ instead of this way v 
;might be that the bottom way has caused problems for me in the past 

MouseClick, right, ImageFoundX, ImageFoundY

Fortnite Youtuber BrockPlaysFortnite :D | AHK completely redefined the way I do things. What used to take me hours to do over and over can now be done with the click of a button. Don't give up! It's worth learning it front to back :wave:
(Note: I'm still a noob so my code may suck sometimes and there is almost assuredly a better way to do it)

NewberEnerNeeder1
Posts: 47
Joined: 26 Mar 2019, 06:06

Re: image search mouse doesnt click target

Post by NewberEnerNeeder1 » 26 Jan 2023, 17:36

Code: Select all

MouseMove, ImageFoundX, ImageFoundY
sleep 20
MouseClick


thanks for the help

i think 5000 might be too long not sure maybe 20

i changed it to
MOUSECLICK,RIGHT, %FoundX1%,%FoundY1%,1,down
sleep 200
MOUSECLICK,RIGHT, %FoundX1%,%FoundY1%,1,up

and it clicked it
but i want to try your way also, it might work better

thx again

Post Reply

Return to “Ask for Help (v1)”