Jump to content

davelf

Members
  • Posts

    4
  • Joined

  • Last visited

Reputation Activity

  1. Like
    davelf got a reaction from Astinus007 in Read text from a firefox window?   
    Thanks for the tip, Distrophy.
    The following code copies text to the clipboard using plain old CTRL-A and CTRL-C, then uses StringInStr() to search the contents of the clipboard.

    Dave


    CODE#comments-start
    This script periodically checks a Firefox web page for a certain word or phrase.
    When the text is found, the word or phrase is highlighted, and the browser window
    is copied to the clipboard.

    Press the "`" key to exit the script.
    On many keyboards, that's the key to the left of the number 1 key
    in the upper left corner of the keyboard.

    #comments-end

    ; Press the "`" key to exit the script.
    HotKeySet("`", "End")

    ; Enter text to watch for.
    $lookfor = InputBox("Enter search text", "Enter search text")
    ; Exit if cancel button is pushed.
    If @error = 1 Then Exit

    $rate = InputBox("Check how often?", "Enter rate in milliseconds at which to check. Entering 2000 will check every two seconds.", "2000")
    ; Note: This script does not check if $rate is a valid number.
    ; Exit if cancel button is pushed.
    If @error = 1 Then Exit

    ; Select window to watch.
    ; 262144 + 1 = Message box stays on top so user can click the OK or cancel button.
    ; after clicking window to watch.

    $which_window = MsgBox(262145, "Select window to watch", "Click on the window to watch for " & $lookfor & ", then click OK. Press the ` key to exit the script.")
    ; Exit if cancel button is pushed.
    If $which_window = 2 Then Exit


    ; Get the title so we can activate this window later.
    $lookhere = WinGetTitle("")
    WinActivate($lookhere)

    ; Watch for desired text.
    Do
    ; Pause for $rate milliseconds.
    Sleep($rate)
    ; Optional: Use WinActivate to switch to $lookhere window
    ; in case another window has become active since the last search.
    ; WinActivate($lookhere)

    ; Select All and copy to clipboard
    Send("^a^c")
    ; Deselect all.
    Send("{LEFT}")

    ; Put text from clipboard into a string.
    ; Images are ignored.
    ; This will copy at least the first 1on the page.
    ; Note: Script tested OK with 15,000 characters.
    ; There's probably a limit to how many characters you can copy.
    $text = ClipGet()
    Until StringInStr($text, $lookfor) > 1 ; Until desired text is found.

    MsgBox(4096, "'" & $lookfor & "' found.", "'" & $lookfor & "' found.")

    WinActivate($lookhere) ; In case window has lost focus.
    ; Go To top of page
    Send("^{HOME}")
    ; Highlight desired text by searching for it using Find.
    Send("^f")
    Sleep(100)
    Send($lookfor)
    ; Close Find dialog
    Send("{ESC}")

    ;Copy screen contents to clipboard
    Send("!{PRINTSCREEN}")
    MsgBox(4096, "Screen capture status", "Desired text is highlighted. Image of browser window has been copied to the clipboard.")

    Func End()
    MsgBox(0, "Script ended", "` key pressed. Script ended")
    Exit
    EndFunc ;==>End


×
×
  • Create New...