scan a specific area

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lupenhagen
Posts: 3
Joined: 19 Apr 2021, 14:15

scan a specific area

19 Apr 2021, 14:18

Code: Select all

Xbutton1::Suspend, toggle



$Rbutton::

MouseMove, 1274, 344



MouseClickDrag, left, 0, 0, 0, 500, 20, relative



sleep 40



while GetKeyState("LButton")

{

PixelSearch, x, y, 1183, 1023, 1206, 1029, 0xFFFFFF, , fast RGB

	if ErrorLevel

	MouseClickDrag, left, 0, 0, 0, -1000, 2, relative
}


In Theory this is supposed to scan a specific area for it to change white, and as soon as it does, stop pulling the mouse down, and pull it up really fast, then stop and be ready to use again. No idea what's up with it.
Last edited by gregster on 19 Apr 2021, 14:49, edited 1 time in total.
Reason: code tags added; provisional topic name added.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: I need help with a script

19 Apr 2021, 14:46

What in your script tells it to stop after it has found it has turned white? I haven’t tested it, so maybe the MouseClickDrag sufficiently releases the LButton so that the while loop will stop. If it does have that effect, then it would cause a different issue (the last one mentioned), so there is a problem either way.

Also, if ErrorLevel will execute the statement that follows it when the color white is not found, because ErrorLevel of 1 means not found. ErrorLevel is 0 when it finds the color, so if !ErrorLevel is how you tell it to execute the following line when the specified color is found.

Another potential issue is that you immediately check for the LButton to be pressed after the first part, so you missed your chance if it wasn’t already down when it first hits the while statement. If you didn’t already have the LButton down when you pressed the RButton, then the while condition won’t be true. And it might not anyway if the preceding MouseClickDrag causes the LButton to be effectively released when it gets to the while statement.
lupenhagen
Posts: 3
Joined: 19 Apr 2021, 14:15

Re: I need help with a script

19 Apr 2021, 19:30

boiler wrote:
19 Apr 2021, 14:46
What in your script tells it to stop after it has found it has turned white? I haven’t tested it, so maybe the MouseClickDrag sufficiently releases the LButton so that the while loop will stop. If it does have that effect, then it would cause a different issue (the last one mentioned), so there is a problem either way.

Also, if ErrorLevel will execute the statement that follows it when the color white is not found, because ErrorLevel of 1 means not found. ErrorLevel is 0 when it finds the color, so if !ErrorLevel is how you tell it to execute the following line when the specified color is found.

Another potential issue is that you immediately check for the LButton to be pressed after the first part, so you missed your chance if it wasn’t already down when it first hits the while statement. If you didn’t already have the LButton down when you pressed the RButton, then the while condition won’t be true. And it might not anyway if the preceding MouseClickDrag causes the LButton to be effectively released when it gets to the while statement.

Code: Select all

Xbutton1::Suspend, toggle

$Rbutton::

MouseMove, 1274, 344

MouseClickDrag, left, 0, 0, 0, 500, 20, relative
while GetKeyState("LButton")
{
PixelSearch, x, y, 1183, 1023, 1206, 1029, 0xFFFFFF, , fast RGB

	if !ErrorLevel
	MouseClickDrag, left, 0, 0, 0, -1000, 2, relative
}
So i've edited it a tiny bit, my thought process is It drags while holding down mouse one, and as soon as the pixel turns white, it pulls up, so that gets me confused with MouseClickDrag. Does that just execute that 500 distance at 20 speed and after it reaches the 500, then it scans? I need it to scan for a change WHILE mouse one is being dragged down and pressed at the same time. I feel like i'm almost there.
Last edited by gregster on 19 Apr 2021, 19:43, edited 1 time in total.
Reason: [code] tags added. Please use them yourself, next time. Thank you!
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: I need help with a script

19 Apr 2021, 19:56

lupenhagen wrote: So i've edited it a tiny bit, my thought process is It drags while holding down mouse one, and as soon as the pixel turns white, it pulls up, so that gets me confused with MouseClickDrag. Does that just execute that 500 distance at 20 speed and after it reaches the 500, then it scans? I need it to scan for a change WHILE mouse one is being dragged down and pressed at the same time. I feel like i'm almost there.
No, the mouse drag happens independently of the scan for the pixel color. It completes it fully and releases the virtual mouse button before the color scan can occur. And it doesn’t even perform any color scan because the condition of the while statement isn’t satisfied since there is no left mouse button being held down at that point, so that loop doesn’t get executed even once.
lupenhagen
Posts: 3
Joined: 19 Apr 2021, 14:15

Re: I need help with a script

19 Apr 2021, 20:09

boiler wrote:
19 Apr 2021, 19:56
lupenhagen wrote: So i've edited it a tiny bit, my thought process is It drags while holding down mouse one, and as soon as the pixel turns white, it pulls up, so that gets me confused with MouseClickDrag. Does that just execute that 500 distance at 20 speed and after it reaches the 500, then it scans? I need it to scan for a change WHILE mouse one is being dragged down and pressed at the same time. I feel like i'm almost there.
No, the mouse drag happens independently of the scan for the pixel color. It completes it fully and releases the virtual mouse button before the color scan can occur. And it doesn’t even perform any color scan because the condition of the while statement isn’t satisfied since there is no left mouse button being held down at that point, so that loop doesn’t get executed even once.
What should i do?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: scan a specific area

19 Apr 2021, 20:30

If you want to scan for the color while dragging the mouse, you can push the mouse button down using Click (i.e., Click, Down), then loop with small increments of mouse movements using MouseMove followed by the PixelSearch. When the color is no longer found and you exit the loop (or you exit because you’ve dragged the entire distance), then use Click, Up to release the mouse button.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 251 guests