Jump to content

clipboard to variable and vice versa


 Share

Recommended Posts

I wanna transfer text that is placed into the clipboard into a variable. then be able to send it from the variable back to notepad or some other word processor. i currently am using something of the sort:

WinActivate("First Program")

WinWaitActive("First Program")

; Go to beginning of field

Send("{HOME}")

; Select all data in field and copy selected text

Send("{CTRLDOWN}a{CTRLUP}")

Send("{CTRLDOWN}c{CTRLUP}")

; Switch to Notepad

WinActivate("Untitled - Notepad")

WinWaitActive("Untitled - Notepad")

; Paste copied text

Send("{CTRLDOWN}v{CTRLUP}")

; Press End, insert a comma & press Enter

send("{END},{ENTER}")

what i wanna do is that when i copy the data into the clipboard that instead of switching into notepad i get the data placed into a variable. that way i can capture all the fields and then go to notepad and just paste all data. this will save me cycles as i wont be switching over to notepad as much. right now i am looping the data you just saw up top a good 34 times per record. i would rather have 34 variables capture the data then switch over to notepad and paste all 34 variables in one shot. Thanks in advance.

Link to comment
Share on other sites

$myvar &= ClipGet() & @CRLF

Or you could _arrayadd each clipget and use _filewritefromarray.

What kind of document is it you're reading? There may be better ways.

I am transfering a database that lacks an export feature. so i am copying all fields(first name, last name, address, ect ect) so i wanna get the data from each field and enter it into the new company database. My code works fine, but its code is tooo inefficient. Rather than switching between applications everytime per field i would rather grab all the information per record before switching out. I am transfering the info to notepad as i am making a tab delimited database so that i can be imported into any database, seeing as our new database is structured differently.

Edited by Joegio13
Link to comment
Share on other sites

Use edxor to monitor and capture new content rather than pasting to notepad. Now you don't have to switch app. You just have to move between the fields.

Send("^A"); Select all
Send("^C"); Copy
Send("{TAB}"); Next field

Edited by Uten
Link to comment
Share on other sites

Use edxor to monitor and capture new content rather than pasting to notepad. Now you don't have to switch app. You just have to move between the fields.

Send("^A"); Select all
Send("^C"); Copy
Send("{TAB}"); Next field
here's the updated code. I still need a way to transfer data from the clipboard to a variable, and variable to clipboard.

WinActivate("First Program")

WinWaitActive("First Program")

; Go to beginning of field

Send("{HOME}")

; Select all data in field and copy selected text

Send("^a")

Send("^c")

; Switch to Notepad

WinActivate("Untitled - Notepad")

WinWaitActive("Untitled - Notepad")

; Paste copied text

Send("^v")

; Press End, insert a comma & press Enter

send("{END},{ENTER}")

Link to comment
Share on other sites

here's the updated code. I still need a way to transfer data from the clipboard to a variable, and variable to clipboard.

Maybe you missed the post from xcal or just ignored it, I don't know but you should pay attention to it.

Look up the functions of ClipGet() and ClipPut().

Send("^a") ;Select all text.
Send("^c") ;Copy selected text.
$variable = ClipGet() ;Retrieves text from clipboard.

Also please enclose your code into the [ autoit ]...[ / autoit ] tags. (NOTE: Without any spaces!)

I would recommend using FileWrite to write it back to a txt file, or put it into a csv file.

I hope this helps a bit,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Look up the functions of ClipGet() and ClipPut().

Yep yep. (Since he missed it the first and possibly the second time, maybe three is the charm?)

Note: The title of your post is exactly what ClipPut and ClipGet do, try searching the helpfile/forums first.

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Sorry, I deleted my original post. I had something like this in mind: $myvar &= $clip & @CRLF.

Here's an example of how it would output. Just copy a few things and then press ESC.

HotKeySet('{escape}', 'quit')

$quit = 0
ClipPut('')
$myvar = ''

While 1
    $clip1 = ClipGet()
    Do
        $clip2 = ClipGet()
        Sleep(50)
    Until $clip1 <> $clip2
    Sleep(50)
    $myvar &= $clip2 & @CRLF  ;this is the magic line sticking clips to one variable
WEnd

Func quit()
    MsgBox(0, 'My Clips', $myvar)
    Exit
EndFunc

edit - modified slightly (original wasn't consistent).

Edited by xcal
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...