Kreatorul Posted August 13, 2006 Posted August 13, 2006 I want to make a robot for Yahoo! Messenger...here is the scrip...but it's not working #include <GUIConstants.au3> GUICreate("Y!M robot", 500,420, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018) GuiCtrlCreateLabel( "First id", 5, 7) $id1= GUICtrlCreateInput ( "", 40, 5, 100, 20) GuiCtrlCreateLabel( "First answer", 160, 32) $answer1=GUICtrlCreateInput ( "", 220, 5, 100, 20) GuiCtrlCreateLabel( "First id", 5, 32) $id2 = GUICtrlCreateInput ( "", 40, 30, 100, 20) GuiCtrlCreateLabel( "First answer", 160, 7) $answer2=GUICtrlCreateInput ( "", 220, 30, 100, 20) $btn = GUICtrlCreateButton ("Let's do it", 40, 75, 60, 20) GUISetState () $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn exitloop EndSelect Wend Opt("WinTextMatchMode", 1) Opt("WinTitleMatchMode", 2) IF WinActive( $id1, "") Then Send( $answer1 & "{ENTER}" ) ElseIf WinActive( $id2, "" ) Then Send( $answer2 & "{ENTER}") EndIf If you have an ideea why this doesen't work please tell me
rbhkamal Posted August 13, 2006 Posted August 13, 2006 (edited) Please explain more about your objective. RK Edited August 13, 2006 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
Kreatorul Posted August 13, 2006 Author Posted August 13, 2006 I created a gui with 4 inputboxes in the first input box you write the id, in the second u write the answer for the first id and same with all the input boxes When somebody writes something i want the script to check if the title of the window matches one of the ids from the inputboxes..and then send the answer from the inputs acording to the window title...if it's window title 1 then send answer 1 etc...it's easy but it's not working...and i'm not good with autoit...sorry 4 my english
Richard Robertson Posted August 13, 2006 Posted August 13, 2006 I am having trouble understanding that. You are making a bot with InputBoxes? What are answers for IDs? Is that similar to a password?
rbhkamal Posted August 13, 2006 Posted August 13, 2006 (edited) OK, 1) Any GUICtrlCreate.... function will return the Control ID of the created GUI item, to retrieve the text from and Input you should use GUICtrlread()2) if you use an option like {Opt("WinTextMatchMode", 1)} and then you use {Opt("WinTextMatchMode", 2)}the active option would be Opt("WinTextMatchMode", 2).3)I recommend that you use the function Controlsend() instead of Send().Edit: I hope you are using SciTEAfter all your script will be like this:expandcollapse popup#include <GUIConstants.au3> GUICreate("Y!M robot", 500,420, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018) GuiCtrlCreateLabel( "First id", 5, 7) $id1= GUICtrlCreateInput ( "", 40, 5, 100, 20) GuiCtrlCreateLabel( "First answer", 160, 32) $answer1=GUICtrlCreateInput ( "", 220, 5, 100, 20) GuiCtrlCreateLabel( "First id", 5, 32) $id2 = GUICtrlCreateInput ( "", 40, 30, 100, 20) GuiCtrlCreateLabel( "First answer", 160, 7) $answer2=GUICtrlCreateInput ( "", 220, 30, 100, 20) $btn = GUICtrlCreateButton ("Let's do it", 40, 75, 60, 20) GUISetState () $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn exitloop EndSelect Wend ;;Removed Opt("WinTitleMatchMode", 1) Opt("WinTitleMatchMode", 2) IF WinActive( GUICtrlRead($id1), "") Then ;Added GUICtrlRead() ControlSend( GUICtrlRead($id1) , '' , 00000 , GUICtrlRead($answer1) & "{ENTER}" ) ; Read the help file ElseIf WinActive( GUICtrlRead($id2), "" ) Then ControlSend( GUICtrlRead($id2) , '' , 00000 , GUICtrlRead($answer2) & "{ENTER}" ) ; Read the help file EndIf ;Note: ;Read the help file about ControlSend() you need to replace 00000 with the right control ID, you will have to install SciTE Edited August 13, 2006 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
Kreatorul Posted August 13, 2006 Author Posted August 13, 2006 (edited) I discovered something weird...if the window wich I send the answer activates the answer it's still not sent...but when I close the script then it writes the text and sends it to the window...it's weird...anybody know why it does that? Edited August 13, 2006 by Kreatorul
rbhkamal Posted August 13, 2006 Posted August 13, 2006 (edited) I discovered something weird...if the window wich I send the answer activates the answer it's still not sent...but when I close the script then it writes the text and sends it to the window...it's weird...anybody know why it does that?because you used this:IF WinActive( GUICtrlRead($id1), "") Then ;Added GUICtrlRead() ControlSend( GUICtrlRead($id1) , '' , 00000 , GUICtrlRead($answer1) & "{ENTER}" ) ; Read the help file ElseIf WinActive( GUICtrlRead($id2), "" ) Then ControlSend( GUICtrlRead($id2) , '' , 00000 , GUICtrlRead($answer2) & "{ENTER}" ) ; Read the help file EndIf Edit: Notice that I used ' YIMInputWindow1 ' in controlsend(), I got that from AutoIt window info tool. Edited August 13, 2006 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
rbhkamal Posted August 13, 2006 Posted August 13, 2006 let me know if you have any questions. RK "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
Kreatorul Posted August 13, 2006 Author Posted August 13, 2006 10x man i really apreciate your help i'll check this out latter because i am busy right now...i'll let you know if it works
Kreatorul Posted August 14, 2006 Author Posted August 14, 2006 Yeah the script works fine but only if the Y!m window exists...when i push the button send the message if winexists...i want something like when I push the button...WinWaitActive("", "Y!m input window) and wait untill the window is active... Because i want to use this while i'm away from the pc...but i really suck at GUI....
rbhkamal Posted August 15, 2006 Posted August 15, 2006 (edited) I think this will do it:Edit: The script below was modifiedexpandcollapse popup#include <GUIConstants.au3> Opt("WinTitleMatchMode", 1);Moved this to the top of the script and changed it to "1", you can changes this if you want. Global $Windows_Count = 2;This should be increased when adding more IDs to your GUI Global $ID[ $Windows_Count + 1] , $Answer[$Windows_Count + 1] ;Storing the GUI IDs in an array will make things easier GUICreate("Y!M robot", 400, 100, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018) ;##### Window number one ############### ;{ GuiCtrlCreateLabel( "ID_1", 5, 7) $ID[1]= GUICtrlCreateInput ( "1", 40, 5, 100, 20) GuiCtrlCreateLabel( "Reply_1", 160, 7) $Answer[1]=GUICtrlCreateInput ( "2", 220, 5, 100, 20) ;} ;##### Window number two ############### ;{ GuiCtrlCreateLabel( "ID_2", 5, 32) $ID[2] = GUICtrlCreateInput ( "11", 40, 30, 100, 20) GuiCtrlCreateLabel( "Reply_2", 160, 32) $Answer[2] = GUICtrlCreateInput ( "22", 220, 30, 100, 20) ;} ;##### Window number Three ############### ;{ ;If you want to add another ID: ; 1) Create the GUI input boxes ; 2) Increase $Windows_Count to 3 ; 3) Store the New GUI controls to the arrays $Answer[] and $ID[] ;} $Start = GUICtrlCreateButton ("Start", 120, 65 , 100, 25) GUISetState () $msg = 0 While $msg <> $GUI_EVENT_CLOSE ;{ $msg = GUIGetMsg(); If $msg = $Start Then ;{ ;Now the "start" button should be "Stop" GUICtrlSetData( $Start , "Stop" ); Start(); ;Restting the button to "Start" GUICtrlSetData( $Start , "Start" ); ;} EndIf ;} Wend ;############### Functions ###################### Func Start() Local $L_a = 0 ;Just a temp variable Local $L_Stop = $Start Local $L_Msg Local $L_Title = '' Do ;{ Sleep( 10 ) $L_Msg = GUIGetMsg() If $L_Msg = $GUI_EVENT_CLOSE Then Exit; ;Will loop through all the IDs and check if a window exists with that ID in it's title. For $L_a = 1 to $Windows_Count ;{ $L_Title = GUICtrlRead($ID[$L_a]) &' - Instant Message' If (WinExists( $L_Title , "")) And (StringStripWS( GUICtrlRead($ID[$L_a]) , 8 ) <> '' ) Then ;{ ;Setting the inputbox color to Green becuase the send was successfull GUICtrlSetBkColor( $ID[$L_a] , 0x00ff00 ) ;Yahoo IM was crashing, So I had to wait from the window to be active before dealing with it. WinActivate( $L_Title , "" ) WinWaitActive( $L_Title , "" , 500 ) ;If the window title exists and the title is not a space or empty send the text to that window ControlSend( $L_Title , '' , 'YIMInputWindow1' , GUICtrlRead($Answer[$L_a]) & "{ENTER}" ) ;Closing the window to prevent the script from sending multiple messages. Sleep( 500 );Just a small sleep to show you what the script wrote, remove that if you want WinKill( $L_Title ) ;} Else ;{ ;Set the Input color to red because the window was not found GUICtrlSetBkColor( $ID[$L_a] , 0xff0000 ) ;} EndIf ;} Next ;} Until $L_Msg = $L_Stop ; If the user pressed "Stop" (Used to be the start button) exit this loop. Return 0 EndFunc Edited August 15, 2006 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
Kreatorul Posted August 15, 2006 Author Posted August 15, 2006 This is working...but only for the first id...If I have the first id and the reply then the second id and the reply for the second id when the second id window apears it sens the reply for the first id... I really can't figure out why it does that....I can't understand the code either...because it got 2 complicated 4 me
rbhkamal Posted August 15, 2006 Posted August 15, 2006 This is working...but only for the first id...If I have the first id and the reply then the second id and the reply for the second id when the second id window apears it sens the reply for the first id...I really can't figure out why it does that....I can't understand the code either...because it got 2 complicated 4 me I modified the script in my last post, try it.Make sure the the titles will match.RK "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
Kreatorul Posted August 16, 2006 Author Posted August 16, 2006 This doesen't work...the $L_Title is not a sollution because if you have 2 email adresses in one(an yahoo service) in the YM window it will show the id which you are sending from instead of "Instant message". I tried to modify the value for $L_Title but even that is not a solution because than it will work only for ppl who have 2 mail adresses in one....I have 2 find another way around...but...i'm still thinking...thx for your help sorry to bother you with this
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now