Can someone assist with a script

06/22/2017 03:54 kleankanteen#1
Can someone help me create a simple script. I would greatly appreciate it. I am pretty new to autoIT and it can make my head spin at times. I ALMOST had this working years ago and gave up on it.

I need it to do the following.

While left mouse button is held down
Pixel search in specific area (I can enter the location and color if u leave it blank).
If color is detected, release left click.

That's all I need it to do. Anyone make a script like that for me so I can adjust the coordinates and color?

Thanks guys.
06/22/2017 08:59 MrFifaUltimate#2
Did not test the code.

Code:
#include <Misc.au3>

Func findPixel()
    If _IsPressed("01") == 1 Then
        Local $coords = PixelSearch(left, top, right, bottom, color)
        If Not @error Then
            MouseUp($MOUSE_CLICK_LEFT)
        Else
            findPixel()
        EndIf
    EndIf
EndFunc
06/22/2017 09:25 kleankanteen#3
Quote:
Originally Posted by MrFifaUltimate View Post
Did not test the code.

Code:
#include <Misc.au3>

Func findPixel()
    If _IsPressed("01") == 1 Then
        Local $coords = PixelSearch(left, top, right, bottom, color)
        If Not @error Then
            MouseUp($MOUSE_CLICK_LEFT)
        Else
            findPixel()
        EndIf
    EndIf
EndFunc
Thanks for this. It is a good start and looks similar to what I was working with 4 years ago.

Couple questions to help me understand.

which part of the script is telling it to search for the color while left mouse is pressed down. And will it continuously search while they key is held?
06/22/2017 09:33 MrFifaUltimate#4
The function checks if the left mouse button is pressed (_IsPressed("01") == 1).
PixelSearch set @error if its unsuccessfull.
If @error is not checked the function calls itself again (recursion).

=> As long as the left mouse button is held down and the Pixel is not found the script will continue searching.
06/22/2017 11:43 Moneypulation#5
PHP Code:
#include <Misc.au3>

HotKeySet("{ESC}","_exit")

Global 
$hDLL DllOpen("user32.dll")

Global 
$left 0
Global $top 0
Global $right 0
Global $bottom 0
Global $color 0
Global $shade 0

While True
    
If _IsPressed("01",$hDLLThen
        checkPixel
()
    EndIf
WEnd

Func checkPixel
()
    While 
True
        
If Not _IsPressed("01",$hDLLThen
            ExitLoop
        
Else
            
$ps PixelSearch($left,$top,$right,$bottom,$color,$shade)
            If 
IsArray($psThen
                MouseUp
("primary")
                
ExitLoop
            
EndIf
        EndIf
    
WEnd
EndFunc

Func _exit
()
    
DllClose($hDLL)
    Exit
EndFunc 
This should do. Enter your PixelSearch coords in the global variables at the top of the script. You can exit the script by pressing ESC or just replace it with your prefered hotkey.
06/23/2017 09:25 kleankanteen#6
Quote:
Originally Posted by MrFifaUltimate View Post
Did not test the code.

Code:
#include <Misc.au3>

Func findPixel()
    If _IsPressed("01") == 1 Then
        Local $coords = PixelSearch(left, top, right, bottom, color)
        If Not @error Then
            MouseUp($MOUSE_CLICK_LEFT)
        Else
            findPixel()
        EndIf
    EndIf
EndFunc
Quote:
Originally Posted by Moneypulation View Post
PHP Code:
#include <Misc.au3>

HotKeySet("{ESC}","_exit")

Global 
$hDLL DllOpen("user32.dll")

Global 
$left 0
Global $top 0
Global $right 0
Global $bottom 0
Global $color 0
Global $shade 0

While True
    
If _IsPressed("01",$hDLLThen
        checkPixel
()
    EndIf
WEnd

Func checkPixel
()
    While 
True
        
If Not _IsPressed("01",$hDLLThen
            ExitLoop
        
Else
            
$ps PixelSearch($left,$top,$right,$bottom,$color,$shade)
            If 
IsArray($psThen
                MouseUp
("primary")
                
ExitLoop
            
EndIf
        EndIf
    
WEnd
EndFunc

Func _exit
()
    
DllClose($hDLL)
    Exit
EndFunc 
This should do. Enter your PixelSearch coords in the global variables at the top of the script. You can exit the script by pressing ESC or just replace it with your prefered hotkey.
I appreciate the help. I am having trouble with the color. It says there is an error. I am using 7D1918. Is that not a correct format for that line?
06/23/2017 10:29 MrFifaUltimate#7
You have to use the Hex-Representation ([Only registered and activated users can see links. Click Here To Register...]).
=> #7d1918
06/23/2017 10:58 kleankanteen#8
Quote:
Originally Posted by MrFifaUltimate View Post
You have to use the Hex-Representation ([Only registered and activated users can see links. Click Here To Register...]).
=> #7d1918
ok this is what I have in both scripts.

Local $coords = PixelSearch(1051, 565, 1051, 569, #7d1918)

and for the other one

Global $color = #7d1918

and this is the error message I get when i try to run either of them.

Unable to parse line and there is a ^Error under the #7d1918 on both.

I used 0x7d1918 and i can get the script to run, it just doesnt seem to work yet. ill tweak the location a bit
06/23/2017 11:30 MrFifaUltimate#9
Oh i was wrong. Its correct to use the Hex-Representation with '0x' instead of '#'. You can also use the Decimal-Representation (8198424).

There must be a difference between your searched color and the color-code.
06/23/2017 13:59 kleankanteen#10
Quote:
Originally Posted by MrFifaUltimate View Post
Oh i was wrong. Its correct to use the Hex-Representation with '0x' instead of '#'. You can also use the Decimal-Representation (8198424).

There must be a difference between your searched color and the color-code.
The script you gave me doesnt seem to run. I run it and nothing happens. The other scrip shows AH running on my pc.

Does AH have an issue with not working with games open unless you tell it to run in a certain exe program? Seems like AHK works better with games. Is this script convertible to AH?
06/24/2017 01:49 psydinger#11
Quote:
Originally Posted by kleankanteen View Post
The script you gave me doesnt seem to run. I run it and nothing happens. The other scrip shows AH running on my pc.

Does AH have an issue with not working with games open unless you tell it to run in a certain exe program? Seems like AHK works better with games. Is this script convertible to AH?
You don't need to switch to AutoHotKey, you can achieve the same with AutoIt.

Have you tried running it with F5 within ScitE and see if there are any errors popping up before compiling it into an executable? Are you sure that you are using the right color and coordinate values?

Make something simple: try testing the script on an example image or enviroment. Make it pop-up a MsgBox() on sucess with the result values and see if it works.

Your best bet right now is trying to narrow down the problem one step at the time.
06/27/2017 07:59 kleankanteen#12
I will spend some more time working on these. I am working a lot right now so I haven't had the time.