Jump to content

How to paste different parts of data from clipboard

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.


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


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


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 post
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.")

;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)

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

;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.")


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.


Edited by BetaLeaf



Link to post
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)


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

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")
    ; 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])


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

    No registered users viewing this page.

  • Similar Content

    • By AspirinJunkie
      I've noticed that for the task of "reading a file row by row into an array" FileReadToArray is consistently slower than a FileRead + StringSplit.
      The following script:
      Results in the following output for me:
      And the output with switched call sequence:
      This surprises me, since I first assume that the native function offers more optimization possibilities than having to create an array in AutoIt via an intermediate string.
      So I thought that maybe FileReadToArray is more economical with memory. But again FileReadToArray seems to consume more memory than the StringSplit variant. For this I got the PeakWorkingSetSize after the call of the respective function.
      After FileReadToArray the Size is always higher than with StringSplit. Since this is not the case if one changes the order of the two functions (see above), one can assume that FileReadToArray actually has this difference. The difference is mostly the double file size. Which would make sense if the file is completely saved internally as a UTF-16 string.
      Can anyone explain to me why FileReadToArray performs so unexpectedly poor - or am I missing something?
    • By AndreyS
      Developers, can anyone explain this phenomenon to me?
      Run this code and wait for nothing without doing a few minutes and you will start receiving randomly, either one or the second message. But none of them should never appear on the logic of the code!
      As I understand sometimes the function ClipGet () returns an empty value. Why is this happening?
      Dim $ClipGetText ClipPut("12345") While 1 Sleep(5) ;reduced to 5 to better see the problem if ClipGet()<>$ClipGetText And ClipGet()<>"" Then $ClipGetText=ClipGet() Beep(800,100) ConsoleWrite(ClipGet()&"|"&$ClipGetText&@CRLF) ElseIf ClipGet()="" Then Beep(800,100) ConsoleWrite("Empty"&@CRLF) EndIf WEnd  
    • By k4rl3on
      I have problem with ClipGet () function: If the clipboard contains a large amount of data the use of the function pushes the consumption of cpu resources to 100% and my script unresponds until I force it to end.
      I tried to work around the problem by limiting the size of the recovered data from the clipboard

      Local = $ClipBoardData = StringMid(ClipGet (), 1.1024) I also used:

      DllCall ("psapi.dll", "int", "EmptyWorkingSet", "long", -1) to free the memory after each call to ClipGet ()
  • Create New...