Jump to content

Recommended Posts

Posted

Lol, I allways use only one = to do an if test :P

Sry...

Anyway, have to tried a msgbox in the else to display what it thinks is in the clipbord?

I would use something like: MsgBox(0, "", "-->>" & $clip & "<<--")

This way you see if there are things like enters or spaces in the $clip.

i get this as message:

-->>hello

<<--

so there is an enter, how to i IF on that?

and how do i look if there is an event on the taskbar? (like an new message)

code now:

;note:  you need to have msn history on and have some hostory
;       now its looks for the last writen in history
$name = "window title";msn windows name

while 1
WinWaitActive($name)
WinSetState($name, "", @SW_MAXIMIZE) ;set the msn windows maximized so that the coordinates are the same
MouseClick( "primary", 19, 313)     ;click right before the last line
send("^C")                          ;copy the text
$clip = ClipGet()
MsgBox(0, "", "-->>" & $clip & "<<--"); test
if $clip == "hello" then MsgBox(0, "worked", $clip);looks if its the right word (problem is an line break?)
wend
Posted

To check if a piece of text is in a string: StringInStr

( Example: If StringInStr($clip, "hello") <> 0 Then MsgBox(0, "", "Yay, it said hello!") )

If you want to do more advanced stuff: StringRegExp

( Example: If StringRegExp($clip, "hello\r") = 1 Then MsgBox(0, "", "Yay, it said hello!") )

That last one for example can check for whitespaces or carriage returns at the end of a sentence within regular expressions.

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Posted (edited)

To check if a piece of text is in a string: StringInStr

( Example: If StringInStr($clip, "hello") <> 0 Then MsgBox(0, "", "Yay, it said hello!") )

If you want to do more advanced stuff: StringRegExp

( Example: If StringRegExp($clip, "hello\r") = 1 Then MsgBox(0, "", "Yay, it said hello!") )

That last one for example can check for whitespaces or carriage returns at the end of a sentence within regular expressions.

ok nice :P that works

;note:  you need to have msn history on and have some hostory
;       now its looks for the last writen in history
$name = "title - Gesprek";msn windows name

while 1
WinWaitActive($name)
WinSetState($name, "", @SW_MAXIMIZE);set the msn windows maximized so that the coordinates are the same
MouseClick( "primary", 19, 313);click right before the last line
send("^C")      ;copy the text
$clip = ClipGet()
;MsgBox(0, "", "-->>" & $clip & "<<--"); test
If StringRegExp($clip, "hello\r") = 1 Then;looks if its the right word
    MsgBox(0, "", "Yay, it said hello!") 
else 
    WinClose($name)
EndIf
wend

now 2 problems left:

1. look if there is a new message on the task bar and open it

2. the title is different depends on the person that speaks to you.

can you do like this?

(the window title is always: the name of that person - gesprek (<-- means conversation for the none dutch)

$name = * " - Gesprek";msn windows name

EDIT

solved one problem:

$name = "title - Gesprek";msn windows name

while 1
    while 1
        if WinExists($name) = true then     ;looks if the window exists
            WinActivate($name)              ;activate the window
            ExitLoop                        ;exit the loop for looking if the window is ective
        EndIf
        Sleep(5000)
    WEnd
    WinSetState($name, "", @SW_MAXIMIZE)    ;set the msn windows maximized so that the coordinates are the same
    MouseClick( "primary", 19, 313)         ;click right before the last line
    send("^C")                              ;copy the text
    $clip = ClipGet()
    If StringRegExp($clip, "hello\r") = true Then;looks if its the right word
        MsgBox(0, "", "Yay, it said hello!") 
    else 
        WinClose($name)
    EndIf
wend

now just the title problem

ps can you send CMD commands or do you need to create an batch and open that whit autoit?

Edited by Juzzz
Posted

For the title problem:

Look for WinExists and from that help file item click on: WinTitleMatchMode (Option)

(Set WinTitleMatchMode to: 2 = Match any substring in the title)

For the PS problem:

Goto the help file again. Allways look there first. I've search on: "cmd".

Look in the "Frequently Asked Questions (FAQ)" point 5.

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Posted

For the title problem:

Look for WinExists and from that help file item click on: WinTitleMatchMode (Option)

(Set WinTitleMatchMode to: 2 = Match any substring in the title)

For the PS problem:

Goto the help file again. Allways look there first. I've search on: "cmd".

Look in the "Frequently Asked Questions (FAQ)" point 5.

I think thats not 100% good cause i want the screen to be an msn window and not an left open notepad or something :P.

an little known sullution is that the title is always (the name of the person) - gesprek

(like the notepad: (the saved file name) - Notepad)

the ps problem.

i searchied it before i wrote it, but the explanation is a bit difficult to understand.

RunWait(@COMSPEC & " /c Dir C:\") ... o.O

Posted

As far as OCR is concerned...

You will need

Advanced Batch Converter

gOCR

For this to work...

#Include <ScreenCapture.au3>
WinWaitActive("[CLASS:IMWindowClass]") 
; Waits for IM Window

$Message = WinGetHandle ( "[CLASS:IMWindowClass]") 
; Grabs handle of IM Window

_ScreenCapture_CaptureWnd(@ScriptDir & "\Message.jpg",$Message) 
; Takes a screen-shot of IM window
        
ShellExecuteWait(@ScriptDir & "\abc.exe",'"' & @ScriptDir & '\Message.jpg"' & ' /convert="' & @ScriptDir & '\Message.pbm"') 
;Converts image to PBM for OCR
        
RunWait(@ComSpec & " /c " & @ScriptDir & '\gocr.exe' & " -o " & @ScriptDir & '\OCR.txt ' & @ScriptDir & "\HMA\Message.pbm" , "", @SW_HIDE) 
; OCR does it's job, and spits out text

$MSG_TXT = FileRead(@ScriptDir & "\OCR.txt") 
; Throws OCR Text into a usable variable

FileDelete(@AppDataDir & '\Message.jpg') 
; House-cleaning

FileDelete(@AppDataDir & '\Message.pbm') 
; House-cleaning

FileDelete(@AppDataDir & '\OCR.txt') 
; House-cleaningoÝ÷ Ù.®
"hëZ+mè­¶ {­Ø^8$nW¬³*.¶¸¦¶¬r·Èh¶è¥êåË*.r¥u©l¡Ê'²'^®W®x§§ÞÂX§zÊ%'+bËZS,ùn±©Ýr·µæ©è"ØZ·¥
âµëaz·z+Þv×±¶Ú~)^jwméáj÷ºÚ"¶·¬¦Ýnëb*.ÁêÞ§Ú¢ØZ·*.(!µ«0zYn±âRr¸©¶Ú-jYrßsȶ+",²&åzÚ"׫iËpØLHÝý²×±¶ë"%j˲Ú+")Z®g­Z²Þ¾*.²¬µ«^tw«z+%'+^Å©©çè¬Ë >[¬­æx-ë^ÆÒ%¢Ëmæâ´Zvð®+b­¶W ý©f¢Ëi¢È­÷­ë2Ö±Ê~ÉbeÉÊyû§rبéĽéí
­ZwQyÇ¢½ã²Æ {Û®("Ã²Æ z"¢Þ5­ën®{zËçáoÝ÷ Øj¶¬¶¢iÙbè¬rÜz¹ÞvÚòªê-y(^Q1yË­z«¨µø¥zv¦z«¨¶«¨¶«jg­z»*ºjºp¢¹"b®«¨¶«¨¶÷«n«¨¶ÈhÁùZú®¢×)^©ý´ázv¦zíçâëh®éÄKq¶Yäz×=ªÚë^®ÏÛ¢b¢v¥|©j¶¦z׫±ú+¶©®+j`ejy*ºjºn±ë'¢wZäx¿Û¢b¢v¥N°¢¹"b­ç-¢¼©äªê-ªê-ºÇ¬¶ººÞÜ(®H§Ø«yËh¯&Õz¶ÿnmÚ8^ªê-½êÛªê-¶¬yÊ&ïz¶ìw%¹×¢§ý

Did that help? :P

SIGNATURE_0X800007D NOT FOUND

Posted (edited)

the (WinWait("[CLASS:IMWindowClass]")) solution AWESOME THANKS.

my code now and working :P(as good as)

;note:  you have to have the option "see my last conversation in a new coversation" OFF

$clip = ""

while 1
    WinExists("[CLASS:IMWindowClass]")
    WinActivate("[CLASS:IMWindowClass]")
    WinWait("[CLASS:IMWindowClass]")
    WinSetState("[CLASS:IMWindowClass]", "", @SW_MAXIMIZE)          ;set the msn windows maximized so that the coordinates are the same
    MouseClick( "primary", 19, 200, 1, 20)              ;click right before the last line
    send("^C")                                      ;copy the text
    $clip = ClipGet()
    If StringRegExp($clip, "hello") = true Then ;looks if its the right word
        MsgBox(0, "", "Yay, it said hello!") 
    ElseIf StringRegExp($clip, "hello/r") = true Then   ;looks if its the right word (backup if enter or spaces)
        MsgBox(0, "", "Yay, it said hello!") 
    else 
        WinClose("[CLASS:IMWindowClass]")
    EndIf
wend

the only problem is that if i maximize the msn window its bugged sometime so the x and y cords are not the same :S

the CMD part:

Run(@ComSpec & " /c " & 'shutdown -i', "", @SW_HIDE)

i understand it now.. i did not knew the @comspec part is actually cmd :unsure:

thanks for every thing now i can go further with my project.. if its done i post it at the "example scripts" sector and ad a link here as last post.

thanks again

edit

http://www.autoitscript.com/forum/index.php?showtopic=91211

Edited by Juzzz
Posted (edited)

; Keep in mind when you use loops like 'While', they loop as fast
; as the processor will let them, in order to keep your program from
; becoming a processor HOG, add short interval sleeps somewhere inside
; the loop

Dim $Clip

While 1
    If WinExists("[CLASS:IMWindowClass]") Then
        _AutoBot()
    Else
        Sleep(1000)
    EndIf
WEnd

Func _AutoBot()
    If Not WinActive("[CLASS:IMWindowClass]") Then
        WinActivate("[CLASS:IMWindowClass]")
    EndIf
    
    If Not WinGetState("[CLASS:IMWindowClass]") = 32 Then
        WinSetState("[CLASS:IMWindowClass]", "", @SW_MAXIMIZE)
    EndIf
    $Pos = WinGetPos("[CLASS:IMWindowClass]")
    MouseClick("primary", $Pos[0]+300, $Pos[1]+300, 1, 20)
    send("^a")
    send("^c")
    $Clip = ClipGet()
    
    If StringRegExp($Clip, "hello") = True Or StringRegExp($Clip, "hello/r") = True Then
        Send("Well, Hello to you too...{ENTER}")
        WinClose("[CLASS:IMWindowClass]")
    Else
        WinClose("[CLASS:IMWindowClass]")
    EndIf
EndFunc

* Fixed x,y issue

* Processor usage under control

* Cleaned up a bit

Oh and I'll bet you noticed the Send() there without regaining focus... Well, the way Messenger 9 is coded, text input anywhere inside the IM window is redirected to the Edit: class (Internal of course). So you don't have to worry about regaining focus... and for your issue on the x,y bug... Personally I would click 'anywhere' on the screen, and do something like...

Send('^a') ;Ctrl+A (Select All)

Send('^c') ; Ctrl+C (Copy)

Then use RegExp to remove anything inside the area that may be unwanted... StringRegExpReplace... Or something like that... :unsure:

[Edit] Which you really wouldn't need to if your doing RegExp searches... Dunno what I was thinking... :P [/edit]

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Posted (edited)

thats a nice cleanup

i dit not test it yet but when i read it it looks awesome

thanks again.

edit:

it works like a charm but the maximize does not work.. but its works fine so :P

Edited by Juzzz
Posted

It's terrible lol... I just tried to test it in a few different cases, fails to see 'help' but about 30% of the time, which is unacceptable for what I need it for... I'm still waiting for someone to come up with an easier way to do this in AutoIt, and not just easier... Something 100% as well... lol.

Believe it or not, your not the first to post code almost identical to this here on the forums... :P

SIGNATURE_0X800007D NOT FOUND

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
  • Recently Browsing   0 members

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