Jump to content

Beep when text is found


 Share

Recommended Posts

Hi there, I'm pretty new to programming. I did write some code a few years ago so it should be easy to pick up but I do need some guidelines. I need a simple script that will:

1. Click a button on the screen when it appears every 2 minutes

2. After clicking the button it must search for a few words anywhere in a window (Chrome or Firefox) and make an audible beep if any of the words are found.

3. Repeat as soon as the button appears again (after around 2 minutes).

Can someone point me to a thread where something like this was discussed. I tried searching but my script requirements are too general/simple so I get a whole bunch of complicated scripts that don't apply.

Link to comment
Share on other sites

WinWait
ControlClick
WinGetText
Beep

I'm hoping the forum generates links for them, but look in the helpfile for examples. (Edit: Yep. Links working)

Chrome or Firefox could cause problems with the WinGetText not reading properly, I haven't tested it though. If not then the only solutions are Send Ctrl+A Ctrl+C and read the clipboard... Or OCR.

Edited by Mat
Link to comment
Share on other sites

Ok, I've been reading the help and the forums. This is my first time using autoit so I have no clue. Came up with the script below. Just trying to see if I can find the text first. Doesn't seem to be working though. Not sure why

$oIE = WinActivate ( "marketplace" )

;search the page

#include <IE.au3>

$sText = _IEBodyReadText ($oIE)

$aText = StringSplit($sText,@CRLF)

; Locate any text with Scythe

If StringInStr($aText,"Scythe") Then

msgbox(0,"",$aText)

EndIf

Edited by Demonscythe
Link to comment
Share on other sites

For some reason I can't read the text or source of the webpage. Used IE. So I've decided to go the send Ctrl+A Ctrl+C route. All I need to do is then find the text from the clipboard? Or do I have to paste it into notepad and then search? Just trying to find the simplest way to search for a few words on a webpage. (Adding the clicking and wait intervals seems easy enough) Are there any examples of using Ctrl+A and Ctrl+C and searchng text?

Edited by Demonscythe
Link to comment
Share on other sites

If you want to use that method, then after the text is selected and ctrl c applied, you can use ClipGet() to get the (string) contents into a variable, then as suggested above "StringInStr" for the test.

But I can tell you that you are using winactivate incorrectly in your script above. It returns the handle of a window, not an IE object. For that you need to look at _IECreate(), or _IEAttatch() before you can use $oIE like you are attempting above.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thanks for the help. Will try this out when I get home. Still need to sort out the button clicking. Any problems with the below?

WinActivate("marketplace")

send("^a")

send("^c")

$Text = ClipGet()

; Locate any text with Scythe

If StringInStr($Text,"Scythe") Then

msgbox(0,"","Yes!")

EndIf

Link to comment
Share on other sites

Another quick question. How can I search for multiple words and return if one or more of them exists? Would the below work?

WinActivate("marketplace")

send("^a")

send("^c")

$Text = ClipGet()

; Locate any text with Scythe or Axe

If StringInStr($Text,"Scythe"|"Axe") Then

msgbox(0,"","Yes!")

EndIf

Link to comment
Share on other sites

I would add a short sleep between your functions to give them tine to actually occur.

"Would the below work?"

"If StringInStr($Text,"Scythe"|"Axe") Then"

No.

Search twice

"If StringInStr($Text,"Scythe") And StringInStr($Text,"Axe") Then

Or try dive into the murky world of StringRegExp()

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I managed to make it work! Search for button, click button, search for words in clipboard and then beep if found. Great feeling when it works for the first time :graduated:

Just one more question about randomizing the sleep time between loops. I want to sleep a random time between 3 and 6 seconds before repeating the loop. Don't want to wait integer times. I know the "1" below denotes integers. If I leave it out then the time wil be randomized in milliseconds?

Sleep(Random(3000, 6000, 1))

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...