Jump to content

I'm new to Autoit. :)


 Share

Recommended Posts

Well I've seen some scripts, used a few, and made a few of my own already.

I guess I can't really say I made a few of my own.. rather I edited a script a ton, until it suited my needs.

Since I'm so new to this, I'm not fully understanding a bunch of things about Autoit..

I'm just looking for some guidance for a script I'm writing. Here's what I want it to do in english [in this order].

Function start.

Move mouse.

Click.

Loop Pixelsearch until it detects a certain pixel (After the click, something is going to load. I don't want to use Sleep, because the load time is irratic. Using a looped pixelsearch ensures that the script won't continue until it's ready to)

Split into two functions: If pixelsearch detects a pixel, do some commands, then repeat the entire function. If it doesn't detect that pixel, do some commands, then repeat the entire function.

Now I just have to figure out how to do this..

Point me to a guide?

I know (generally, from looking at other scripts) how to do most everything I said, I just need to know how to add a looped pixelsearch to a function that will stop the script from continuing until I find the requested pixel. I think I know how to split into two functions, but I'm not positive as I've not tried it yet.

Link to comment
Share on other sites

Hey Welcome To The Fourm.

You should check through the help section in scite and look for these functions then try and use them to make your script.

MouseClick

Do Until Loop

PixelSearch

PixelGetColor

WinWait

If you require more help feel free to ask :D.

Edited by Venix
Link to comment
Share on other sites

Or if you tell us which program you try to automate we might show you a better way to do it.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

All I need help with at the moment is the do/until loop.

How would I go about writing this?

Obviously, my guess is wrong:

TEST()

Func TEST()

WinActivate("Paint")

Sleep(1000)

Do

$PIXEL_TEST = PixelSearch(0, 0, 800, 600)

Until $PIXEL_TEST = 0xFF0000

Send(1)

TEST()

EndIf

Sleep(500)

Basicly, activate Windows Paint, search for red. when/if if finds red, press 1 then repeat the script.

Fix? :idea:

Edited by lml
Link to comment
Share on other sites

  • Moderators

PixelSearch returns a value of an Array.

If you do not understand what that is, maybe you should check the wiki out. There are some pretty in depth examples and explanations there.

You're obviously trying to just jump in, I won't discourage that, but it's frustrating for the other members to assist you if you've not bothered to read the tutorials which is blatently clear you haven't.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

PixelSearch returns a value of an Array.

If you do not understand what that is, maybe you should check the wiki out. There are some pretty in depth examples and explanations there.

I understand what an array is. How does that effect my script though? I just want the script to pause until it's finished loading a certain screen(pixel)..

If I do:

$PIXEL_X = PixelSearch(0, 0, 800, 600, 6523365, 3, 0, 0)

Then I'll get a two-element array of that pixel's coordinates. (x = $PIXEL_X[0], y = $PIXEL_X[1])

So, how does having those coordinates in an array help? How would I loop a search until it found my requested color?

Should I instead be using PixelChecksum? (I don't think so, because the pixels change more than once. I click, the screen changes to a load screen after a second, then changes again after 3-4 seconds. I want the script to continue after the 2nd screen)

You're obviously trying to just jump in, I won't discourage that, but it's frustrating for the other members to assist you if you've not bothered to read the tutorials which is blatently clear you haven't.

I've been using AutoIt Help (F1 from AutoIt's editor). I didn't know there was anything else until just now (google searched Autoit Wiki), and I'm still having trouble finding anything to do with loops in the wiki.

True, I am trying to jump in. I apologize if my way of learning through example is unorthodox, though I'm very curious how it's frustrating to assist me. This should be a simple 3line code, should it not? .. I've made it very clear what I'm requesting, I've asked how to write it, tried to write it, failed, posted my code, and asked what needed fixed. I'm the frustrated one.

Link to comment
Share on other sites

Change this:

Do
    $PIXEL_TEST = PixelSearch(0, 0, 800, 600)
Until $PIXEL_TEST = 0xFF0000

To this:

Do
    Sleep(10) ; need this or your script will eat up all the CPU resources
    $PIXEL_TEST = PixelSearch(0, 0, 800, 600, 0xFF0000); you need to have the color to search for or it won't work
Until @error <> 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Change this:

Do
$PIXEL_TEST = PixelSearch(0, 0, 800, 600)
Until $PIXEL_TEST = 0xFF0000

To this:

Do
Sleep(10) ; need this or your script will eat up all the CPU resources
    $PIXEL_TEST = PixelSearch(0, 0, 800, 600, 0xFF0000); you need to have the color to search for or it won't work
Until @error <> 1
Awesome!! Works perfectly. Thank you VERY much. :D

I guess my only concerns now... How do you hold down a keyboard key (Keydown/Keyup?), and is there any way to add a timeout? Like.. if it doesn't hit the requested pixel within 60 seconds, do something else?

Current code:

Do
Sleep(100)
$PIXEL_IN = PixelSearch(200, 500, 260, 650, 0xFDF683)
Until
@error <> 1

Would be cool if it instead did something like..?: (Excuse my shitty coding skills, lol)

TEST()
Func TEST()
     Do
     Sleep(100)
     $PIXEL_IN = PixelSearch(200, 500, 260, 650, 0xFDF683)
     Until
     @error <> 1
If Sleep(60000) and @error = 0
     Then Send("{ENTER}")
     Sleep(100)
     TEST()
EndIf
Sleep(1000)
TEST()
(In english: Function start, search for PIXEL_IN until it hits or until 60seconds have passed. If 60 seconds pass, press enter and restart script. If pixelsearch hits the pixel, continue the script normally.
Link to comment
Share on other sites

TEST()
[ Do other stuff after success ]

Func Test()
  While 1
    $hTimer = TimerInit()
    Do
      Sleep(100)
      PixelSearch(200, 500, 250, 550, 0xFDF683)
      $iError = @error
    Until Not $iError Or (TimerDiff($hTimer) / 10^3) > 60
    If $iError Then
      Send("{ENTER}")
      ContinueLoop
    ExitLoop
  WEnd
  Return True
EndFunc

EDIT: Added Send()

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...