Jump to content

How to paste different parts of data from clipboard


LearnIt
 Share

Recommended Posts

Hi everyone!

I recently started working after college and we use a lot of excel. As I was searching for ways to improve efficiency I came across AutoIt, so I decided to learn. I've put in some hours of reading through the search function on the website and the AutoIt library for my issue, but I cannot seem to find my answer and I am having trouble understanding some stuff.

What I am trying to do is get AutoIt to paste a string into several different boxes. I want the script to know that each '-' in the copied text it should press tab and skip past the '-' and paste/type the following numbers. Here's an example of the text I will copy and press a F5 (eventually set up a hotkey) to run the script: 0123-456-7891-01112131-000-1234-456

Here's my code so far: (Btw, I know the ending of the code doesn't make sense, I was editing it and what not, it's just that I don't know how to efficiently use the clipget() and stringsplit() functions.

#RequireAdmin
AutoItSetOption('MouseCoordMode',0)

WinWait('Oracle Applications - XXXX Production')
WinActivate('Oracle Applications - XXXX Production')
MouseClick('primary', 38, 408, 2, 0)

StringSplit(ClipGet(),"-")
Send("{TAB}")
Send(ClipGet())

I would like to paste it in the box in the attached picture.

Untitled.png

Even if there is not a way for autoit to skip past the '-' I can just copy the entire string without the '-' and I would like autoit to paste the first 4, then press tab, paste the next 3, press tab, etc etc. Any of those methods work. 
 
Thank you for taking the time to read through this and attempting to responding!
Edited by LearnIt
Adding additional information.
Link to comment
Share on other sites

Welcome to the community. I think this will get you started. Let me know if there is anything else I can do to help.

;How to create your array.
Global $x, $y ;Put this here so Au3Check wouldnt throw a not declared error.

#include "array.au3"
;set your string
$string = "123-456-7890-1234-56789-01234"; you can also use inputbox() or ClipGet() if using data from clipboard.

;Split $string anytime - is found. This turns this variable into an array.
$string = StringSplit($string, "-") ;$String[0] is always ubound($string)

;View the Array we just made.
MsgBox(64, "Info", "When you are done viewing the results of the array, click on the close button in the top right corner or press escape to continue. " & @CRLF & @CRLF & "Clicking Exit in the bottom right will terminate the script.")
_ArrayDisplay($string)

;How to process your array.

;This line sends the text in variable $string[1], which happens to contain 456

#cs ;Example Command. Also, #cs is comment start and #ce is comment end, and can be used to document functions on multiple lines.
ControlSend("Find Accounts", "", "", $string[1]) ;I am going off what I can see from your screenshot, you may need to use Tools>AU3Info. (at the top of the editor, SciTE)
#ce

;If controlsend isnt working, Try a normal send.

#cs ;Some Example Commands.
    WinActivate("Find Accounts");Ensures the app is focused.
    MouseClick("Primary", $x, $y, 2, 0);Double clicks at the Coordinates. You will want to set static values or define the variable. See footnotes.
    Send($string[5]);In this example, $string[5] contains 56789.
#ce


;Footnotes:
;Since you will probably need to store coordinates or classes in a variable, I'll teach you more about multidimensional arrays.

;Ok now lets set an example array for mouse coordinate data. I just made up some random coordinates. You must use Local or Global when using multidimensional arrays or you will get an error from AU3Check
Global $ExampleCoords = [["25", "42", "176", "94", "63", "11"], _ ;Pretend these are X Coordinates. Note that _ is the continue character. Use this to keep the script looking neat. Basically, this tells the script to continue on the next line as if it was all on one line. Similar to | in batch.
        ["36", "56", "254", "2", "84", "9"]] ;Pretend these are Y Coordinates. Also, keep in mind it is bad practice to store Global coordinates in functions or at the bottom of a script. All Global Arrays, opt(), and #includes should be the first lines on your script.

;View the Array we just made.
MsgBox(64, "Info", "Row 0 will contain your X Coordinates and will represent $ExampleCoord[0][$i]." & @CRLF & _
        "Row 1 will contain your Y Coordinates and will represent $ExampleCoord[1][$i]." & @CRLF & _
        @CRLF & _
        "$i or whatever variable you use will represent the Column.")

_ArrayDisplay($ExampleCoords)

MsgBox(64, "Info", "If You want to use Column 4 Coordinates, you will use $ExampleCoords[4][0] for X Coordinate and $ExampleCoords[4][1]" & @CRLF & _
        "In this Example, X is " & $ExampleCoords[0][4] & " and Y is " & $ExampleCoords[1][4] & @CRLF) ;Arrays start at Column 0.
        
#cs ;Some Example Commands.
MouseClick("Primary", $ExampleCoords[0][4], $ExampleCoords[1][4], 1, 0);Clicks once at the coordinates in column 4.
#ce

 

Edited by BetaLeaf

 

 

Link to comment
Share on other sites

Instead of using Paste you could try using ControlSetText for each of the input boxes. If it's a normal Windows form and not something special then it should be pretty easy to go through each Edit box and set the text for the same index of the array returned by StringSplit

#include <GUIConstants.au3>
#include <String.au3>
#include <Array.au3>

HotKeySet("{Insert}", "FillInputs")

GUICreate("Test", 150, 100)
GUICtrlCreateInput("", 10, 10, 60, 20)
GUICtrlCreateInput("", 80, 10, 60, 20)
GUICtrlCreateInput("", 10, 40, 60, 20)
GUICtrlCreateInput("", 80, 40, 60, 20)
GUICtrlCreateInput("", 10, 70, 60, 20)
GUICtrlCreateInput("", 80, 70, 60, 20)

GUISetState(@SW_SHOW)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0
    EndSwitch
WEnd

Func FillInputs()
    ; Fake clip data
    Local const $clip_data = "0123-0123-456-456-7891-7891"
    ; Split the string by the "-" with no count in the first index
    Local const $split_data = StringSplit($clip_data, "-", $STR_NOCOUNT)
    
    ; Make sure there's the same amount of clip data as there are boxes to fill
    If (UBound($split_data) <> 6) Then
        MsgBox("", "Invalid Clip Data", "Clip data is invalid. Count: " & UBound($split_data) & " | Input boxes to fill: 6")
        Return
    EndIf
    
    ; Go through each element in the split data and fill the input boxes. Not using the control id returned from GUICtrlCreateInput but the name of the class and box number
    For $i = 0 to UBound($split_data) - 1
        ControlSetText("Test", "", "Edit" & ($i + 1), $split_data[$i])
    Next
EndFunc

 

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