In this tutorial, I show how to quickly copy and paste large amounts of text into fields on a form after retrieving data from a database table. This is a recent problem that I wanted to solve, as simply sending the variable’s content to a field takes time if you use Send () and the variable’s content contains a large amount of text. Just FYI, to use Send () with a variable it is used as follows:

send($variable, 1)

You need the second parameter (that is, the flag) ‘1’ in the function. The ‘1’ flag means that the data is sent raw. The default value is ‘0’, which is defined as “Text contains special characters such as + and! To indicate SHIFT and ALT keystrokes.”

AutoIt: ClipPut (), place content on clipboard

However, this is not really the most efficient method of sending large bodies of text to, say, the notepad or the fields of a form. Once you retrieve your data and put this data into a variable, all you need to do is the following:

Func printOutput2()

Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) ;get value of table's field by index number
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("^v")
EndFunc

The ClipPut function places the text inside your clipboard. So all you need to do is Send () Control + v keys like:

send("^v")

AutoIt: ClipGet (), get clipboard content

I tried to use the ClipGet function; however this did not work for me. The ClipGet function returns the value when using the MsgBox function. So with MsgBox () this works:

Func printOutput2()

Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) ;get value of table's field by index number
MsgBox(0, "test2", ClipGet())

Now to run the function, all you need to type is:

printOutput2())

AutoIt: Copy file as in Explorer

If you want to copy a file as you would in Explorer, use the FileCopy function:

FileCopy("C:file_to_copy.txt", "D:mydirfile_to_copy.txt")

The format to use this function is:

FileCopy ( "source", "dest" [, flag] )

There are a few flags that you can use with the FileCopy function:

[optional] this flag is a combination or one of the following:

0 = (default) does not overwrite existing files

1 = overwrite existing files

8 = Create the target directory structure if it does not exist.

If you want to combine the flags, add the values. In other words, if you want to overwrite an existing file in the destination and check if the destination directory exists or not and if it doesn’t, then create the directory, then you would use ‘9’ as the flag.

So the flag would be used as:

FileCopy("C:file_to_copy.txt", "D:mydirfile_to_copy.txt", 9)

You can use wildcards when copying files like ‘*’ denoting zero or more characters and ‘?’ A denoting zero or one character. So if you want to copy all the files in the temp directory (i.e C: temp ) and then copy them to another directory, you should use the following code:

FileCopy("C:temp*.*", "D:mydir")

Note that you cannot have more than one wildcard in the file name and extension. So this will NOT work:

FileCopy("C:tempd*g?.*", "D:mydir")

You should use regular expressions to accomplish this more complex task.

Another note that applies specifically to the extension is that the first 3 characters of the extension will be matched. In other words, this:

FileCopy("C:temp*.txt", "D:mydir")

will copy all files with the extension ‘txt’ as well as any extension like ‘txt *’. Then the extension ‘txt1’, ‘txt2’, ‘txt3’ will also be copied.