# Difference between two pixel location

## Recommended Posts

I have located a red pixel on my screen with PixelSearch as \$coord1. That red pixel will move to other location as \$coord2. If the difference it let's say 5 pixels, I have to do something...

Also I'd like to add time for this loop. I'd like to run this search only for 30 sec.

```\$coord1= PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)

for \$time=300 to 1 step -1

if \$time=1 then
msgbox("info","Pixel didn't move")

else

\$coord2= PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)

if \$coord1 - \$coord2 > 5 then         ;does this really calculate the difference?
msgbox("info","Pixel moved")

endif

endif

next```

I'd like to get some ideas how to calculate the difference between two pixels and it the difference is something I'd like to do something. I can see on my screen that the red pixel is in the different location but it won't start my next action.

##### Share on other sites

This works for me, and the color has to be unique.

```Local \$left = 0
Local \$top = 0
Local \$right = @DesktopWidth
Local \$bottom = @DesktopHeight
Local \$color = 0xFF0000
Local \$variation = 10
Local \$Time

\$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
If @error = 1 Then
MsgBox(64, 'Error', 'No pixel with that color found!')
Exit
EndIf

While 1
Sleep(60)
\$Time = \$Time + 0.1
ConsoleWrite('\$Time '& \$Time &@CRLF)
If \$Time <= 29.9 Then
\$coord2 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
If Not @error Then
If \$coord1[0] - \$coord2[0] > 5 OR \$coord1[1] - \$coord2[1] > 5 Then
\$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
MsgBox(64, "info", "Pixel moved")
EndIf
EndIf
EndIf
If \$Time >= 29.9 Then
Exit
EndIf
WEnd```

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

# IUIAutomation - Topic with framework and examples

##### Share on other sites

Thats not realy a good way to make a function run for 30 seconds.. Its totaly based on the execution time of the function and will vary from each execution , not to mention different cpus will have a different base line...

Why not use standard TimerDiff?

##### Share on other sites

It only tests 2 directions of a pixel move also.

Monkey's are, like, natures humans.

##### Share on other sites

This works for me, and the color has to be unique.

Â

Thank you! I'll give it a try.

Â

Why not use standard TimerDiff?

Â

This one seems interesting. I'll try this one also!!

Â

It only tests 2 directions of a pixel move also.

Â

I only want to see if my pixel moves during 30sec time, nothing more. If pixel move, I'd like to do something. Not sure what do you mean by this...

##### Share on other sites

Â

I only want to see if my pixel moves during 30sec time, nothing more. If pixel move, I'd like to do something. Not sure what do you mean by this...

Â

He means the example posted will only detect if a pixel moves in the positive direction of the start posistion.. You should use Abs() to also detect movement in the negative direction.. Or what about a vector length from the start position?

Edited by Geir1983

##### Share on other sites

He means the example posted will only detect if a pixel moves in the positive direction of the start posistion.. You should use Abs() to also detect movement in the negative direction.. Or what about a vector length from the start position?

Â

Oh dear... you are right! I have to add that. Thank you!

##### Share on other sites

Sorry guys, i was up for too long, you're all correct, free to add the sugestions to the code.

About the "only 2 directions" issue..

Something like this maybe?

```If \$coord1[0] - \$coord2[0] > 5 OR \$coord1[1] - \$coord2[1] > 5 Then
\$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
MsgBox(64, "info", "Pixel moved")
ElseIf \$coord1[0] - \$coord2[0] < 5 OR \$coord1[1] - \$coord2[1] < 5 Then
\$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
MsgBox(64, "info", "Pixel moved")
ElseIf (\$coord1[0] - \$coord2[0])+(\$coord1[1] - \$coord2[1]) < 5  OR (\$coord1[0] - \$coord2[0])+(\$coord1[1] - \$coord2[1]) > 5 Then
\$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
MsgBox(64, "info", "Pixel moved")
EndIf```

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

# IUIAutomation - Topic with framework and examples

##### Share on other sites

Try this.

```Local \$left = 10, \$top = 10, \$right = 100, \$bottom = 100, \$color = 0xFFFFFF, \$variation = 90

Local \$coord1 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
If @error Then
Exit
EndIf

Local \$iTime = 0, \$coord2

Local \$hTimer = TimerInit()
While TimerDiff(\$hTimer) < 30000
\$coord2 = PixelSearch(\$left, \$top, \$right, \$bottom, \$color, \$variation)
If Abs(\$coord1[0] - \$coord2[0]) >= 5 Or Abs(\$coord1[1] - \$coord2[1] >= 5) Then
\$iTime = TimerDiff(\$hTimer)
ExitLoop
EndIf
Sleep(10)
WEnd

If \$iTime Then
MsgBox(64, "info", "Pixel moved in " & Round(\$iTime / 1000, 3) & " secs")
Else
MsgBox(64, "info", "Pixel did not moved in 30 secs")
EndIf```

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...