Jump to content
Sign in to follow this  
Orcc

Help with Script need get colro and mouse to move

Recommended Posts

Orcc

I'm kinda new to auto it but, it seems this is something I am willing to learn

I wrote a simple script to do the following things move the mouse to a certain color,

then left click, send key f1. Then send key E. But I been testing it over and over and modifying it but it doesn't seem to work

Can someone hep review it and tell me what I'm doing wrong?

Below is the script. Also how do I set pause to be infinite?

Global $Paused

HotKeySet("{End}", "ExitProg") ;;To exit the progam

HotKeySet("{Home}", "StartProg") ;;To start the program

HotKeySet("{Insert}", "TogglePause") ;; Key to pause and unpause

While 1

Sleep(100) ;;;Waits for function call

Wend

Func StartProg()

$coord = PixelSearch( 0, 0, 1024, 768, 0x0c0d0d )

If Not @error Then

MouseClick ( "Left")

send("{F1}")

send("{e}")

EndIf

EndFunc

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(1000000)

WEnd

EndFunc

Func ExitProg()

Exit 0 ;;;Exits the program

EndFunc

Share this post


Link to post
Share on other sites
maqleod

I don't see where you are actually moving the mouse to the coordinates that you find with pixelsearch()

your click should reference those coordinates, like so:

MouseClick("Left",$coord[0],$coord[1])


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites
Orcc

I was under the impression it would move the mouse to find that color? If that is false, can you steer me to the right path? where should i go to read up on it?

Knowledge is life.

Share this post


Link to post
Share on other sites
maqleod

I was under the impression it would move the mouse to find that color? If that is false, can you steer me to the right path? where should i go to read up on it?

Knowledge is life.

pixelsearch() just scans an area of the screen for the pixel information provided and returns coordinates of the given pixel if it finds it.

the code I provided above using mouseclick() will move the mouse to the coordinates returned by your pixelsearch before it clicks.


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites
Orcc

So i redid the code and it wasn't that much different tell me if it's wrong still. now for what i intend for it to perform.

Also is there a way to put the program to find more then one color? of so is it just putting more pixel search in?

BTW, Thank's for the fast reply's.

Global $Paused

HotKeySet("{End}", "ExitProg") ;;To exit the progam

HotKeySet("{Home}", "StartProg") ;;To start the program

HotKeySet("{Insert}", "TogglePause") ;; Key to pause and unpause

While 1

Sleep(100) ;;;Waits for function call

Wend

Func StartProg()

$coord = PixelSearch( 0, 0, 1024, 768, 0x0c0d0d )

If Not @error Then

MouseClick("Left",$coord[0],$coord[1])

send("{F1}")

send("{e}")

EndIf

EndFunc

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(1000000)

WEnd

EndFunc

Func ExitProg()

Exit 0 ;;;Exits the program

EndFunc

Share this post


Link to post
Share on other sites
Authenticity

sleep(1000000) :D

Use @DesktopWidth and @DesktopHeight instead of fixed values. You can make array of colors and pass each in a loop to the PixelSearch() function.

Share this post


Link to post
Share on other sites
Orcc

Yeah I wondering how to set the sleep, to infinite till I unpause. So I set it to 1000000. still looking that info up.

Quote Authenticity

"You can make array of colors and pass each in a loop to the PixelSearch() function"

Can you show me where to look, on how to loop it. The array of colors doe's it range from" A to Z" or it's pre-set like

0x1ag6agd

oxa4dfad

ox156446

preset it that way?

let me put a sample of what your saying? See if it's correct?

Global $Paused

HotKeySet("{End}", "ExitProg") ;;To exit the progam

HotKeySet("{Home}", "StartProg") ;;To start the program

HotKeySet("{Insert}", "TogglePause") ;; Key to pause and unpause

While 1

Sleep(100) ;;;Waits for function call

Wend

Func StartProg()

$coord = PixelSearch( 0, 0, 1024, 768, 0x0cafd0 )

$coord = PixelSearch( 0, 0, 1024, 768, 0x0c0d0d )

$coord = PixelSearch( 0, 0, 1024, 768, 0x0fofof )

$coord = PixelSearch( 0, 0, 1024, 768, 0xagager)

$coord = PixelSearch( 0, 0, 1024, 768, 0x0fykfsr ) <---Like that?

$coord = PixelSearch( 0, 0, 1024, 768, 0x0agrah )

$coord = PixelSearch( 0, 0, 1024, 768, 0x0c0d0d )

$coord = PixelSearch( 0, 0, 1024, 768, 0x0cagah )

$coord = PixelSearch( 0, 0, 1024, 768, 0x0clolia )

If Not @error Then

MouseClick("Left",$coord[0],$coord[1])

send("{F1}")

send("{e}")

EndIf

EndFunc

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(1000000)

WEnd

EndFunc

Func ExitProg()

Exit 0 ;;;Exits the program

EndFunc

Share this post


Link to post
Share on other sites
Chapi

Yeah I wondering how to set the sleep, to infinite till I unpause. So I set it to 1000000. still looking that info up.

Global $Paused
HotKeySet("{Insert}", "TogglePause");; Key to pause and unpause

$Paused = False

Func TogglePause()
    $Paused = Not $Paused
        while $paused
              sleep(100)
        wend
EndFunc

Share this post


Link to post
Share on other sites
Orcc

So making sleep timer to (100) would make it infinite not 100 milliseconds? Well I am going to test it. Thank you.

Share this post


Link to post
Share on other sites
BlackDragonBE

No...

Making a hotkey that pauses or unpauses your script by checking a variable will do that, and not "infinite", the Sleep(100) sleeps 100ms to have mercy on the CPU.

Share this post


Link to post
Share on other sites
Orcc

Thanks for clearing that up about the pause issue.

Still wondering about the color pixel issue. Should i set a thousand colors to search for or is there and array "range" of Pre-set colors I can set the program to find?

Share this post


Link to post
Share on other sites
Authenticity

What are the colors you're looking for? There might be logic behind it so there is no need for thousands array elements. If you want to find 256 variations of green you can query for PixelSearch with shade-variation of 256, for example.

Share this post


Link to post
Share on other sites
Orcc

What are the colors you're looking for? There might be logic behind it so there is no need for thousands array elements. If you want to find 256 variations of green you can query for PixelSearch with shade-variation of 256, for example.

This program is to get a color off a character then I want it to perform a action on that character. So the charater has 20 colors black blue light blue red etc. But i want to be able to get that character info and perform a action on that character.

Share this post


Link to post
Share on other sites
Authenticity

Dim $sColors = '0x00FF00FF|0x00CC50D1|0x000000FF|0x0000FF00|0xDEADBEEF|0x78563412|0x00FFFFFF'
Dim $aColors = StringSplit($sColors, '|')

For $i = 1 To $aColors[0]
    Local $aPos = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $aColors[$i])
    If Not @error Then
        ; Do something with the coordinate and exit the loop.
        ExitLoop
    EndIf
Next

Share this post


Link to post
Share on other sites
Orcc

Dim $sColors = '0x00FF00FF|0x00CC50D1|0x000000FF|0x0000FF00|0xDEADBEEF|0x78563412|0x00FFFFFF'
Dim $aColors = StringSplit($sColors, '|')

For $i = 1 To $aColors[0]
    Local $aPos = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, $aColors[$i])
    If Not @error Then
        ; Do something with the coordinate and exit the loop.
        ExitLoop
    EndIf
Next

I don't get this? so the loop is wrong? I need the script to run over and over. so it wont exit until. I give the command.

So with autoit dim colors what does that do?

Share this post


Link to post
Share on other sites
Authenticity

If you want it to run until you'll stop it just wrap it in an outer loop and set a hot-key to stop it.

HotKeySet('{ESC}', '_EXIT')

.
.
.
While 1
   ; Inner while loop.
   Sleep(50)
WEnd

Func _EXIT()
   Exit
EndFunc

The string with the pipes - '|' is for clarity and simplicity so you don't have to declare an array variable and assign each color like:

$aColors[0] = 0x0000FF00 ; Green

$aColors[1] = 0x00FF0000 ; Red

... etc.

Share this post


Link to post
Share on other sites
Orcc

If you want it to run until you'll stop it just wrap it in an outer loop and set a hot-key to stop it.

HotKeySet('{ESC}', '_EXIT')

.
.
.
While 1
   ; Inner while loop.
   Sleep(50)
WEnd

Func _EXIT()
   Exit
EndFunc

The string with the pipes - '|' is for clarity and simplicity so you don't have to declare an array variable and assign each color like:

$aColors[0] = 0x0000FF00 ; Green

$aColors[1] = 0x00FF0000 ; Red

... etc.

The loop process is correct hot key

While

funcend

exit

I have those in my script.

So the "|" Key will simplify the code so i don't have to type out $coord=0xofofof Over and over. Gotcha. Thanks all the help has been .. well Helpful. Thanks all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.