Jump to content
Sign in to follow this  
ColoradoDude

Having trouble Array to Clipboard?

Recommended Posts

ColoradoDude

Hello! I am wondering if I can get some help on a script or atleast a starting point I am pulling my hair out.

What I need to do is read a text file into an array which I have accomplished. Then I need to send that array to the clipboard 1 line by one:

Text File:

cats fish

dogs

rats cool

bats are ugly

So the file is read to an array then I need it to go to the clipboard 1 line. Then when ctrl+v is pressed I need the array to send the next line into the clipboard.

Any help is greatly appreciated.

-Colorado Dude

Share this post


Link to post
Share on other sites
SmOke_N

Hello! I am wondering if I can get some help on a script or atleast a starting point I am pulling my hair out.

What I need to do is read a text file into an array which I have accomplished. Then I need to send that array to the clipboard 1 line by one:

Text File:

cats fish

dogs

rats cool

bats are ugly

So the file is read to an array then I need it to go to the clipboard 1 line. Then when ctrl+v is pressed I need the array to send the next line into the clipboard.

Any help is greatly appreciated.

-Colorado Dude

Global $sFileName = "PutFileNameHere.txt"
;Create hotkey to track ctrl+v
HotKeySet("^v", "_CtrlV")

;Array to keep track of what line number you are on
Global $nTrackNum = 0

;Read file to an array
Global $aFile = StringSplit(StringStripCR(FileRead($sFileName)), @LF)

;Loop to keep script alive
While 1
    Sleep(100000)
WEnd

Func _CtrlV()
    If $nTrackNum > $aFile[0] Then
        ;If we don't reset $nTrackNum here or exit, we'll get an array error
        MsgBox(64, "Info", "You've reached the end of the file.")
        Exit
    EndIf
    $nTrackNum += 1
    ClipPut($aFile[$nTrackNum])
    Return
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
ColoradoDude

Thanks!

Share this post


Link to post
Share on other sites
ColoradoDude

Premature on the thanks it works sorta! It wont paste anything from the clipboard unless I terminate the script... Thinking about it maybe I should change the hotkey so I can paste?

-CDude

Share this post


Link to post
Share on other sites
SmOke_N

Premature on the thanks it works sorta! It wont paste anything from the clipboard unless I terminate the script... Thinking about it maybe I should change the hotkey so I can paste?

-CDude

Well we kind of blocked it from pasting, so we would need to turn off the hotkey and use Send then turn the hotkey back on:
Global $sFileName = "Put file name location here"
;Create hotkey to track ctrl+v
HotKeySet("^v", "_CtrlV")

;Global integer to keep track of what line number you are on in the array
Global $nTrackNum = 0

;Read file to an array
Global $aFile = StringSplit(StringStripCR(FileRead($sFileName)), @LF)

;Loop to keep script alive
While 1
    Sleep(100000)
WEnd

Func _CtrlV()
    If $nTrackNum > $aFile[0] Then
        ;If we don't reset $nTrackNum here or exit, we'll get an array error
        MsgBox(64, "Info", "You've reached the end of the file.")
        Exit
    EndIf
    HotKeySet("^v");Turn off hotkey
    $nTrackNum += 1
    ClipPut($aFile[$nTrackNum])
    Send("^v") ; Might want to do: Send("^v" & @CRLF)
    HotKeySet("^v", "_CtrlV");Turn back on hotkey
    Return
EndFunc

Edit:

Took redundant vars out.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


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
Sign in to follow this  

×