Jump to content

How to use selected text in autoit


Estimize
 Share

Recommended Posts

I have a program that automatically selects this bit of text and I need it to make a decision based on what this text is. For example here it is "2.18", if it shows this number I need it to repeat the function it just previously executed which is called Click_1(). Also if this value is something else for example "0.00" I need it to go onto the next function which is called Click_2. Any help is appreciated and if I missed any bits of info out which would help you answer my question just let me know. This decision also needs to be made outside of the functions Click_1/2 if possible. Thanks in advance

2.18.png

Link to comment
Share on other sites

Local $Data, $NewData;variable placeholder for selected text

While 1; make a loop to keep the script running inefinately
    WinActive(name of your program);You will probably want to use this to make the screen with the text the active window
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == $Data Then
        Click_1()
        $Data = $NewData
    EndIF
    IF $NewData == 0.00 Then
        Click_2()
        $Data == $NewData
    EndIF
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

Func Click1()
    MouseClick("",x1,y1)
EndFunc

Func Click_2()
    MouseClick("",x1,y1)
EndFunc

Haven't tested this but it is how I would write what you are explaining.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Local $Data, $NewData;variable placeholder for selected text

While 1; make a loop to keep the script running inefinately
    WinActive(name of your program);You will probably want to use this to make the screen with the text the active window
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == $Data Then
        Click_1()
        $Data = $NewData
    EndIF
    IF $NewData == 0.00 Then
        Click_2()
        $Data == $NewData
    EndIF
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

Func Click1()
    MouseClick("",x1,y1)
EndFunc

Func Click_2()
    MouseClick("",x1,y1)
EndFunc

Haven't tested this but it is how I would write what you are explaining.

If $NewData == 2.18 Then
        Click_1()
        $Data = $NewData
    EndIF
    IF $NewData == 0.00 Then
        Click_2()
        $Data == $NewData
    EndIF

 

 

is this correct or should what i changed to 2.18 stay as $data  also thanks very much for the help

 

 

Edited by Estimize
misscode
Link to comment
Share on other sites

It depends on what you want the script to do. Will it run forever? How many values will there be? The code I wrote is made to work forever. If you only want to check the number a few times then leave it at 2.18. Bottom line here is that you need to take what I wrote and test it and make changes and then test it. If you get stuck add more questions to this thread and we will help.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Can you copy and paste your code in a code window (its the <> symbols) rather than a blurry screen shot? Thy this. you can use msgbox to debug what is happening in your code to find out why it does not do what you want it to.

#include <MsgBoxConstants.au3>
HotKeySet("{F6}","Terminalte")

Local $Data = 2.18;stored value of what the selected text was as of the last check
Local $NewData;most current value of what is the selected text

Click_1();Run the function Click_1() when the script starts before the while loop

While 1; make a loop to keep the script running inefinately
    If WinExists("Function2") Then
        WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
        Sleep(250)
    Else
        MgBox(0,"Missing Window","Functions2 window is not running")
        Exit 0
    EndIf
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == $Data Then;this value starts as 2.18 as declared by line 3
        Click_1()
        $Data = $NewData;Set $Data to 2.18 after Click_1() has been run
    EndIF
    If $NewData == 0.00 Then
        Click_2()
        $Data = $NewData;This will set $Data to 0.00
    EndIF
    If $NewData <> 2.18 and $NewData <> 0.00 Then
        MsgBox(0,"NewData Value not 2.18 or 0.00","The value of $NweData is neither 2.18 nor 0.00. The value of $NewData is: " & $NewData)
        Exit 0
    EndIf   
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

Func Click1()
    MouseClick("",x1,y1)
EndFunc

Func Click_2()
    MouseClick("",x1,y1)
EndFunc

Func Terminate()
    Exit 0
EndFunc

 

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

This is the funtions2.au3 page this shouldnt be like the rest of the code sorry
Func Click_1()
   Sleep (10000)
   MouseClick("left" , 863, 356) ;Click the X button
   sleep (250)
   MouseClick("left" , 1300, 186) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("1.16") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

Func Click_2()
   Sleep (1000)
   MouseClick("left" , 863, 563) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("3.74") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

This is the mainbot.au3 page

#include <MsgBoxConstants.au3>
#include <Functions2.au3>


HotKeySet("{F6}", "_Terminate")
Local $Data, $NewData;variable placeholder for selected text

Click_1()

While 1; make a loop to keep the script running inefinately
    WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == 2.18 Then
       Click_1()
        $Data = $NewData
    EndIF
    IF $NewData == 0.00 Then
       Click_2()
        $Data == $NewData
    EndIF
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

 

Edited by Estimize
Link to comment
Share on other sites

Can you copy and paste your code in a code window (its the <> symbols) rather than a blurry screen shot? Thy this. you can use msgbox to debug what is happening in your code to find out why it does not do what you want it to.

#include <MsgBoxConstants.au3>
HotKeySet("{F6}","Terminalte")

Local $Data = 2.18;stored value of what the selected text was as of the last check
Local $NewData;most current value of what is the selected text

Click_1();Run the function Click_1() when the script starts before the while loop

While 1; make a loop to keep the script running inefinately
    If WinExists("Function2") Then
        WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
        Sleep(250)
    Else
        MgBox(0,"Missing Window","Functions2 window is not running")
        Exit 0
    EndIf
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == $Data Then;this value starts as 2.18 as declared by line 3
        Click_1()
        $Data = $NewData;Set $Data to 2.18 after Click_1() has been run
    EndIF
    If $NewData == 0.00 Then
        Click_2()
        $Data = $NewData;This will set $Data to 0.00
    EndIF
    If $NewData <> 2.18 and $NewData <> 0.00 Then
        MsgBox(0,"NewData Value not 2.18 or 0.00","The value of $NweData is neither 2.18 nor 0.00. The value of $NewData is: " & $NewData)
        Exit 0
    EndIf   
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

Func Click1()
    MouseClick("",x1,y1)
EndFunc

Func Click_2()
    MouseClick("",x1,y1)
EndFunc

Func Terminate()
    Exit 0
EndFunc

 

what are the last 11 lines for???

 

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
HotKeySet("{F6}","Terminate")

Local $Data = 2.18;stored value of what the selected text was as of the last check
Local $NewData;most current value of what is the selected text

Click_1();Run the function Click_1() when the script starts before the while loop

While 1; make a loop to keep the script running inefinately
    If WinExists("Function2") Then
        WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
        Sleep(250)
    Else
        MgBox(0,"Missing Window","Functions2 window is not running")
        Exit 0
    EndIf
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == $Data Then;this value starts as 2.18 as declared by line 3
        Click_1()
        $Data = $NewData;Set $Data to 2.18 after Click_1() has been run
    EndIF
    If $NewData == 0.00 Then
        Click_2()
        $Data = $NewData;This will set $Data to 0.00
    EndIF
    If $NewData <> 2.18 and $NewData <> 0.00 Then
        MsgBox(0,"NewData Value not 2.18 or 0.00","$NewData is neither 2.18 nor 0.00. The value of $NewData is: " & $NewData)
        Exit 0
    EndIf   
    Sleep(1000);pause the program for 1 second so it doesn't overuse your processor.
WEnd

Func Click_1()
   Sleep (10000)
   MouseClick("left" , 863, 356) ;Click the X button
   sleep (250)
   MouseClick("left" , 1300, 186) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("1.16") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

Func Click_2()
   Sleep (1000)
   MouseClick("left" , 863, 563) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("3.74") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

Can you point them out for me? I am adding features to the code in the event that the selected text is neither 2.18 nor 0.00. Its optional and you can remove it if that will never happen.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

my code is now working and chooses call_1 or 2 appropriately and I renamed them to call because I felt it fitted it's purpose better. I used this

 

#include <MsgBoxConstants.au3>
#include <Functions2.au3>

HotKeySet("{F6}", "_Terminate")
Local $Data, $NewData;variable placeholder for selected text

Sleep (5000)

MouseClick ("right", 1260, 260)
Sleep (250)
MouseClick ("left", 1214, 485)
sleep (250)
Call_1()

While 1; make a loop to keep the script running inefinately
    WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
    If $NewData == 2.18 Then
       Call_1()
        ;$Data = $NewData
     Else
       $NewData == 0.00
       Call_2()
       ;$Data == $NewData
    EndIF
    Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
WEnd

 

Now I need it to go onto call _3 if the result of the If statement call_2 is also 0.00 but if the result of the call_3 statement is 7.31 I need it to start back at call_1. If you don't understand I can explain it better because I'm sure I missed some sort of detail out, also thanks for the help so far very much appreciated. Also there can only be two values (like here 0.00 or 2.18) as what the program is asking a question and there are basically two answers every time it asks the question and one will always be 0.00. If the answer is 0.00 it will always go onto the next function for example if I was on call_2 and the answer was 0.00 I need the program to go onto call_3 but if the answer was 7.31 it goes back to call_1. Best explanation I can give. As well as this the program cannot skip call_1/2/3/4 to get to call_5 it has to go through all the call_'s in numerical order until the answer which isn't 0.00 is given then we loop back to call_1

 

 

Edited by Estimize
more info needed
Link to comment
Share on other sites

How many calls are there going to be? 5? What are the values that you want to call a click function on for these 5 calls? ie there will be click_1() = 2.18  click_2() = 0.00 click_3() =7.31 etc

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

there will be a max of 10 calls,  and you might have misunderstood, so the program executes call_1 then the result of call_1 which can either be 2.18 or 0.00 decides whether it will move onto call_2 or stay on call_1. the result of call_1 to move onto call_2 is 0.00 but if the result of call_1 is 2.18 then it just repeats call_1. So when it executes call_2 it gets a result back at the end of the function which is either 7.31 or 0.00 if the result is 0.00 it will move onto call_3 but if the result of call_2 was 7.31 then I need it to loop back to call_1 and repeat like that. the numbers are the least relevant bits I think. So if the result of call_1 and 2 and 3 was all 0.00 it moves onto call_4 and if the result of call_4 is  17.16 (that may change in future but it j=should be easily replaced) then the program loops back to call_1 and carries on from there, but if the result of call_4 is 0.00 then it needs to go onto call_5 and so on.

Link to comment
Share on other sites

You need a while loop where you have 10 + if statements or you need a do while loop or possibly several nested if statements. Really the point of this forum is to help you understand the concept of what you want your script to do and be able to write and modify your own. Are you stuck? Where are you stuck?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

You need a while loop where you have 10 + if statements or you need a do while loop or possibly several nested if statements. Really the point of this forum is to help you understand the concept of what you want your script to do and be able to write and modify your own. Are you stuck? Where are you stuck?

The while loop is the bit of program I am stuck on.

 

 

Link to comment
Share on other sites

See if you can wrap your mind around this. It would help me write more if the info you gave me was correct and complete. What would help me the most would look something like this:

1. 0.00 or 2.18

2. 0.00 or 7.13

3. 0.00 or ?

4. 0.00 or 17.16

There's  a pattern here. Find it. Manipulate it to work for you.

#include <Array.au3>

Function_1();call the main function when the program starts

Func Function1()
    While 1; make a loop to keep the script running inefinately
        GetClipData();get the value of the number
        If $NewData == 2.18 Then
            Action_1()
        EndIf
        If
            $NewData == 0.00 Then
            Function_2()
        EndIF
        Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
WEnd
EndFunc

Func Function_2()
    While 1; make a loop to keep the script running inefinately
        GetClipData();get the value of the number
        If $NewData == 7.13 Then
            Action_1()
            Function_1()
        EndIf
        If
            $NewData == 0.00 Then
            Action_3()
            Function_3()
        EndIF
        Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
    WEnd
EndFunc

Func Function_3()
    While 1; make a loop to keep the script running inefinately
        GetClipData();get the value of the number
        If $NewData == 17.16 Then
            Action_1()
            Function_1()
        EndIf
        If
            $NewData == 0.00 Then
            Action_4()
            Function_4()
        EndIF
        Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
    WEnd
EndFunc

Func GetClipData();get the number copied to the clipboard and then the value declared as a variable
    WinActive("Functions2");You will probably want to use this to make the screen with the text the active window
    Send("^c");Send Ctrl + C to copy the copied text
    sleep(250);I add this to give the computer time to copy the data to the clipboard. It may not be necessary
    $NewData = ClipGet();This will read the clipboard data in windows and set it to the variable $data for comparisons
EndFunc     

Func Action_1()
   Sleep (10000)
   MouseClick("left" , 863, 356) ;Click the X button
   sleep (250)
   MouseClick("left" , 1300, 186) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("1.16") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

Func Action_2()
   Sleep (1000)
   MouseClick("left" , 863, 563) ;Click the X button
   sleep (250)
   MouseClick("left" , 1260, 200) ;Click Amount TextBox
   sleep (250)
   for $x - 1 to 8
      send ("{BACKSPACE down}")
      sleep (100)
      Send("{BACKSPACE up}")
      sleep (100)
   Next ;Clicks Backspace 3 times
   sleep (100)
   Send("3.74") ;Inputs '1' into the amount box
   sleep (250)
   MouseClick("left" , 1245, 512) ;Click Call
   sleep (250)
   MouseClick("Left" , 790, 400)
   sleep (90000)
   MouseClick("right" , 807, 439)
   MouseClick("left" , 860, 665)
   sleep (5000)
   MouseClick("left" , 1001, 296)
   MouseClick("left" , 1012, 309)
   MouseClick("left" , 1046, 351)
   MouseClick("left" , 1046, 351)
EndFunc

 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Function_1 searches for the number 0.00 and 2.18 then it calls the function action_1 or function_2. 

Object oriented design

1. Get the number.(call the function GetClipData())

2. If the number is 0.00 then Call function_2. If the number is 2.18 run action_1 again. (The if statements in Function_1())

3. In function_2, get the number. If the number is 0.00 then call function_3. If the number is 7.18 then call function_1 (start over).(The if statements in function_2())

etc.

Look at the function_# as the sequence you were describing for the numbers you want to compare. ie Function_1 compares 0.00 and 2.18. Function_2 compares 0.00 and 7.18. Function_3 I was given missing information from you so I dont know what the comparison is. You would make Function_4 to compare 0.00 and 17.16.

 

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

I think I made a mistake in the code above.

Func Function_1();Only the first function needs to use a while loop.
    While 1; make a loop to keep the script running inefinately
        GetClipData();get the value of the number
        If $NewData == 2.18 Then
            Action_1()
        EndIf
        If
            $NewData == 0.00 Then
            Function_2()
        EndIF
        Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
    WEnd
EndFunc

Func Function_2()
    ;you might want to put a sleep here depending on how long it takes for the value to change    
        GetClipData();get the value of the number
        If $NewData == 2.18 Then
            Action_1();your click sequence
            Function_1();restart back at the top (Function_1())
        EndIf
        If
            $NewData == 0.00 Then
            Action_2();Do something because the value is 0.00
            Function_2();Go on to the next function
        EndIF
        Sleep(1000);pause the program for 1 second so it doesn't over use your processor.
EndFunc

 

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Are we on track for nested IF statements?  I wonder what the source data represents? And the fact that it can always only be one item from a set of predefined values?  Do these values always increment? Can a value reduce? What are the implications if a wrong choice is made?

Intriguing.

Skysnake

Why is the snake in the sky?

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

×
×
  • Create New...