# PixelSearch, Move Mouse to..

## Recommended Posts

Hey guys (and girls if any ^^)

I've started Playing around with PixelSearch, and after being shocked that it is not using X,Y i found it far smarter^^

For the Simple Version:

I need to PixelSearch the Screen for a Color. And Then Move the Mouse to that place.

```Sleep(3000)
\$Color = PixelSearch(0, 0, 1000, 1000, 0xE94434, 10)
If Not @error Then
MouseClick("left", \$Color,\$Color)
Else```
<- The Variable For the Mouse is also Not Working How can i move the Mouse to a Variable instead of Set Cordinates?

There is more than one Pixel of The Color.

And There will Most Likely Be More Than One Area With Them on the Screen, but the Mouse is only Supposed To Move to One Area with the Pixels.

So i think i will split the The Screen Into a Grid and Run the PixelSearch Function Until i Find One Window with The Color.

```\$Color = PixelSearch(0, 0, 100, 100, 0xE94434, 10)
If Not @error Then
Else```

I need the Script to "Understand 3d"

So i need to Calculate the Range between The Pixelsearch Window and the Center of The Screen.

Got any Help for me:) ?

Pieces of Script, Tutorials, articles ?

Thx for the Help !

##### Share on other sites

In Autoit Help under PixelSearch:

Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

##### Share on other sites

In Autoit Help under PixelSearch:

Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)

So you are Saying that:
```\$Color = PixelSearch(500, 300, 800, 600, 0x634f30, 10)
If Not @error Then
MouseClick("Right",\$Color,1)
Else
MsgBox(0, "Error", "Error")
EndIf```
???

Because That just Moves the Mouse to x= 0 y= 0 cordinates

##### Share on other sites

So you are Saying that:

```\$Color = PixelSearch(500, 300, 800, 600, 0x634f30, 10)
If Not @error Then
MouseClick("Right",\$Color,1)
Else
MsgBox(0, "Error", "Error")
EndIf```
???

Because That just Moves the Mouse to x= 0 y= 0 cordinates

Do you know how arrays work?

PixelSearch returns an array (Array[0] = x, Array[1] = y)

MouseClick syntax is MouseClick( "button" , x, y)

Comeon, this is pretty simple...

##### Share on other sites

I can't see how i make the mouse use pixelsearch array,sorry, just started programming saturday

Edit: but that is not the Big problem I figure that one out, thx for the Reminder of the Help File

Edited by Schoening
##### Share on other sites

Look at PixelSearch and MouseClick in the Help file. There's working code examples for just about every AutoIt native function in fact.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

##### Share on other sites

Ok, I have figured the PixelSearch Array thing out now.. Sorry I Posted and Started Searching AFTER !

## Create an account

Register a new account

• ### Similar Content

• By Dave1
Hello everyone,
I have several signals on the screen that need to be monitored while a program is running. These signals are scattered around an image which is maximized on 4  equal resolution screens - the AutoIT Window Info does not recognize any objects on the program meaning that I'm left with the PixelSearch() and PixelCheckSum() functions to monitor the signals:
The signals are as small as a 5x5 pixel area and their coordinates are known.
I've been digging around for a while now in this forum about the PixelSearch() and PixelCheckSum()  and found some interesting and useful ideas for the use of them. I also came across some other UDF functions like MultiMon(), FastFind(), TtColXY() and the ImageSearch2015 scripts that might be useful for the final output. I don't know if hovering the mouse by using TtColXY() and output its ToolTip() information onto the log file will be faster than using PixelSearch() and/or PixelCheckSum() in a loop for all signals' coordinates.
The colours of the signals are below:
red - 0x00FF00 (opaque red)
green - 0x00FF00 (opaque green)
yellow - 0xFFFF00 (opaque yellow)
black - 0x000000 (opaque black, default colour)
EDIT:
The desired output is to monitor and record/log the changes and status of each inside a .txt file or a .csv with the below format:
Local Machine Time        Signal,      Change,               delta-t
14:32:07                  Signal1     Green - Yellow         DELTA-t1
14:34:02                  Signal1     Yellow - Red           DELTA-t1
14:35:14                  Signal2     Yellow - Red           DELTA-t2
...
Below is the code I came up with.
1 - I'm not sure about how to put the message into the log file.
2 - I tested this script but it is not recording the message into the log file.
3 - Is there other way to calculate the duration in these lines?
\$iTimeDiffh = _DateDiff('h', \$tChange, \$tCurrent) ; time difference in hours \$iTimeDiffm = _DateDiff('n', \$tChange, \$tCurrent) ; time difference in minutes \$iTimeDiffs = _DateDiff('s', \$tChange, \$tCurrent) ; time difference in seconds \$durationCheckSum = \$iTimeDiffh & ":" & \$iTimeDiffm & ":" & \$iTimeDiffs ; Timestamp of the signal until PixelCheckSum \$sLogMsg = " " & \$SignalID[0] & " " & \$ColourCheckID & " - " & \$NewCheckID & " " & \$durationCheckSum _FileWriteLog(\$LogFile, \$sLogMsg) Thanks in advance!

• Hey.
Is there anything that does the same thing as this?

Namely I'm talking about detecting when something has changed on screen.
The FastFind library is crashing without any errors after running:
FFSnapShot(\$left, \$top, \$right, \$bottom, 0) FFSnapShot(\$left, \$top, \$right, \$bottom, 1) \$diff = FFLocalizeChanges(0, 1) And then trying to overwritite the old snapshot (0 or 1).
If I use always different snapshot numbers its using too much memory and will eventually crash my pc.

It takes 2 snapshots and compares them returning the area that has changed very quickly (left, top, right ,bottom).
Can anyone help me do this?
Looping PixelGetColor would require a bunch of extra code to my purpose and its not as efficient...

Thanks

• By Dan_555
Hi, here are few functions for the ListBox.
I have searched the forum, but most of the functions are for listview, so i took one example code from melba23 (clear selection) and
wrote few more functions. (Because my current project needs them).

These functions work only on a Multi-selection ListBox .
Edit: Only 1 function does not work with single selection box.
The functions do: Clear Selection, Delete Selected items, Invert Selection, Move selected items up and down.
The example code has 2 Listboxes. The selected items on the left ListBox can be moved up and down. The right Listbox has buttons for the other functions.
#include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Local \$singlesel = 0, \$iMsgBoxAnswer = 0 ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question, Modality=Task Modal \$iMsgBoxAnswer = MsgBox(8228, "Choose Listbox selecton type", "Yes for single, No for multi selection box") If \$iMsgBoxAnswer = 6 Then \$singlesel = 1 ;Yes Local \$BL_1,\$BL_2,\$BR_1,\$BR_2,\$BR_3,\$BR_4,\$BR_5,\$BR_6 Global \$hForm1 = GUICreate("Listbox test", 349, 287) \$LB_1 = GUICtrlCreateList("", 6, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$LBS_MULTIPLESEL, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) If \$singlesel = 1 Then \$LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) Else \$LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$LBS_MULTIPLESEL, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) \$BR_3 = GUICtrlCreateButton("Reverse Sel", 272, 22, 68, 17) EndIf \$BL_1 = GUICtrlCreateButton("Up", 20, 3, 35, 18) \$BL_2 = GUICtrlCreateButton("Down", 60, 3, 35, 18) \$BR_1 = GUICtrlCreateButton("Up", 200, 3, 35, 18) \$BR_2 = GUICtrlCreateButton("Down", 240, 3, 35, 18) \$BR_4 = GUICtrlCreateButton("Clear Sel", 217, 22, 52, 17) \$BR_5 = GUICtrlCreateButton("Delete", 175, 22, 40, 17) \$BR_6 = GUICtrlCreateButton("Populate", 290, 3, 50, 18) GUISetState(@SW_SHOW) For \$x = 0 To 50 If \$x <= 10 Then GUICtrlSetData(\$LB_1, \$x & " test", 0) GUICtrlSetData(\$LB_2, \$x & " Test", 0) Next While 1 \$nMsg = GUIGetMsg() Switch \$nMsg Case \$GUI_EVENT_CLOSE Exit Case \$BL_1 \$a = Listbox_ItemMoveUD(\$LB_1, -1) If \$a > -1 Then WinSetTitle(\$hForm1, "", "Moved items: " & \$a) Case \$BL_2 \$a = Listbox_ItemMoveUD(\$LB_1, 1) If \$a > -1 Then WinSetTitle(\$hForm1, "", "Moved items: " & \$a) Case \$BR_1 Listbox_ItemMoveUD(\$LB_2, -1) Case \$BR_2 Listbox_ItemMoveUD(\$LB_2, 1) Case \$BR_3 Listbox_ReverseSelection(\$LB_2) Case \$BR_4 Listbox_ClearSelection(\$LB_2) Case \$BR_5 Listbox_DeleteSelectedItems(\$LB_2) Case \$BR_6 ;Populate GUICtrlSetData(\$LB_2, "") ; Clears the listbox For \$x = 0 To 50 GUICtrlSetData(\$LB_2, \$x & " Test", 0) Next EndSwitch WEnd ;note \$hLB_ID - is the Listbox id Func Listbox_DeleteSelectedItems(\$hLB_ID) Local \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Get selected items Local \$i, \$slb = 0, \$y, \$x If \$aSel[0] = 0 Then ;If the array is empty, there is no selection, or it is a single selection listbox For \$x = 0 To _GUICtrlListBox_GetCount(\$hLB_ID) - 1 \$y = _GUICtrlListBox_GetSel(\$hLB_ID, \$x) If \$y = True Then \$slb = 1 _GUICtrlListBox_DeleteString(\$hLB_ID, \$x) ;Perform a delete on single sel. LB ExitLoop EndIf Next EndIf If \$slb = 0 Then _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = \$aSel[0] To 1 Step -1 ;Loop backwards and delete the selected items _GUICtrlListBox_DeleteString(\$hLB_ID, \$aSel[\$i]) Next _GUICtrlListBox_EndUpdate(\$hLB_ID) EndIf EndFunc ;==>Listbox_DeleteSelectedItems Func Listbox_ClearSelection(\$hLB_ID) ;Removes the selection from multi and single selection ListBox Local \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Code from Melba23 - Autoit Forum Local \$slb, \$x, \$y If \$aSel[0] = 0 Then _GUICtrlListBox_SetCurSel(\$hLB_ID, -1) \$slb = 1 EndIf If \$slb = 0 Then _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = 1 To \$aSel[0] _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i], False) Next _GUICtrlListBox_EndUpdate(\$hLB_ID) EndIf EndFunc ;==>Listbox_ClearSelection Func Listbox_ReverseSelection(\$hLB_ID) ;Logically, this function works only on multi-selection listboxes Local \$i Local \$aCou = _GUICtrlListBox_GetCount(\$hLB_ID) Local \$cSel = _GUICtrlListBox_GetCaretIndex(\$hLB_ID) ;Save the caret _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = 0 To \$aCou _GUICtrlListBox_SetSel(\$hLB_ID, \$i, Not (_GUICtrlListBox_GetSel(\$hLB_ID, \$i))) Next _GUICtrlListBox_SetCaretIndex(\$hLB_ID, \$cSel) ;Restore the caret _GUICtrlListBox_EndUpdate(\$hLB_ID) EndFunc ;==>Listbox_ReverseSelection Func Listbox_ItemMoveUD(\$hLB_ID, \$iDir = -1) ;Listbox_ItemMoveUD - Up/Down Move Multi/Single item in a ListBox ;\$iDir: -1 up, 1 down ;Return values -1 nothing to do, 0 nothing moved, >0 performed moves Local \$iCur, \$iNxt, \$aCou, \$aSel, \$i, \$m = 0, \$y, \$slb = 0 ;Current, next, Count, Selection, loop , movecount \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Put selected items in an array \$aCou = _GUICtrlListBox_GetCount(\$hLB_ID) ;Get total item count of the listbox If \$aSel[0] = 0 Then \$y = _GUICtrlListBox_GetCurSel(\$hLB_ID) If \$y > -1 Then _ArrayAdd(\$aSel, \$y) \$aSel[0] = 1 \$slb = 1 EndIf EndIf ;WinSetTitle(\$hGUI, "", \$aSel[0]) ;Debugging info Select Case \$iDir = -1 ;Move Up For \$i = 1 To \$aSel[0] If \$aSel[\$i] > 0 Then \$iNxt = _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i] - 1) ;Save the selection index - 1 text _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i] - 1, _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i])) ;Replace the index-1 text with the index text _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i], \$iNxt) ;Replace the selection with the saved var \$m = \$m + 1 EndIf Next For \$i = 1 To \$aSel[0] ;Restore the selections after moving If \$aSel[\$i] > 0 Then If \$slb = 0 Then _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i] - 1, 1) Else _GUICtrlListBox_SetCurSel(\$hLB_ID, \$aSel[\$i] - 1) EndIf EndIf Next Return \$m Case \$iDir = 1 ;Move Down If \$aSel[0] > 0 Then For \$i = \$aSel[0] To 1 Step -1 If \$aSel[\$i] < \$aCou - 1 Then \$iNxt = _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i] + 1) _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i] + 1, _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i])) _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i], \$iNxt) \$m = \$m + 1 EndIf Next EndIf For \$i = \$aSel[0] To 1 Step -1 ;Restore the selections after moving If \$aSel[\$i] < \$aCou - 1 Then If \$slb = 0 Then _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i] + 1, 1) Else _GUICtrlListBox_SetCurSel(\$hLB_ID, \$aSel[\$i] + 1) EndIf EndIf Next Return \$m EndSelect Return -1 EndFunc ;==>Listbox_ItemMoveUD
• By AnRios
Greetings friends!
I have been searching the help file and Google, with no success, to find a way to validate images from a folder and mark them somehow in a spreadsheet.
My context is: I made a code with the help of the community that captures images from SAP and saves them in a folder.  Now I'd like to identify which ones are black, if it's even possible. I read about PixelSearch, but did not get it to work. If someone could point me in the right direction, I'd appreciate it.
The code I'm using:
#include <File.au3> #include <ScreenCapture.au3> \$x = InputBox("Title", "Amount of Images To Capture", "", "", 320, 150) If @error Then Exit \$x = Number(\$x) \$y = InputBox("Title", "Batch Name", "", "", 320, 150) If @error Then Exit \$y = String(\$y) HotKeySet("{HOME}", "printscreen") Func printscreen() \$FilePath =("C:\Fiscalizacao\Fotos"&"/") \$FileName = \$y & " - " \$FileList = _FileListToArray(\$FilePath, \$FileName & '*.jpg', 1) If Not IsArray(\$FileList) Then \$FileName&= '1.jpg' Else \$FileName &= \$FileList[0] + 1 & '.jpg' EndIf _ScreenCapture_Capture(\$FilePath & "\" & \$FileName, 354, 196, 673, 436) EndFunc HotKeySet("{BS}", "Terminate") Func Terminate() Exit 0 EndFunc For \$i = 1 to \$x Opt("WinTitleMatchMode",2) If NOT WinExists("Relatorio") Then MsgBox(0, "Atenção!", "Relatório do MOM deve estar aberto!") Call("Terminate") EndIf Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Sleep (250) Opt("WinTitleMatchMode",2) SendKeepActive("Relatorio") Send("{ENTER}") Sleep (1000) Send("{HOME}") Sleep (200) Opt("WinTitleMatchMode",2) WinActivate("Relatorio") Send("{DOWN}") Next
• By plankton
While IsArray(PixelSearch(100, 100, 300, 300, 0xffffff))     Send("{ESC}")     Sleep(1000) ﻿WEnd ﻿ M﻿sgBox(0,"Loop exited","") Hi, above is my function that will execute ESC button when white color is present in specific area which is color 0xffffff.
But how do I do the opposite like when white color is not present in that specific area? Like this below code which gives me error

While IsArray(PixelSearch(100, 100, 300, 300, <>0xffffff))     Send("{ESC}")     Sleep(1000) ﻿WEnd ﻿ M﻿sgBox(0,"Loop exited","")

×

• Wiki

• Back

• #### Beta

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