Sign in to follow this  
Followers 0
MasonMill

Clipboard

2 posts in this topic

Can i copy using ctrl-a / ctrl-c then put that into a clipboard within autoit? I first started using text files to transfer text but then read about autoits clipboard function. My first script looked like this:

CopyText()

;error 3 open failed
;error 4 read failed
Func CopyText()      
    ToolTip("Copying now", $tooltipX, $tooltipY)
    While 1
                mouseclick("left", 20, 300)
        Sleep(3000)
        Send("^a")
        sleep(1000)
        Send("^c")
        const $IniFile = "options.ini"
        Dim $TXTScanFileName = @ScriptDir & "\Read.txt"
        Dim $newTXTScanFileName = @ScriptDir & "\temp.txt"
        local $tempFile = _FileCreate($newTXTScanFileName)

        local $fHandle = FileOpen($TXTScanFileName)
        if @error Then ;$fHandle = -1
            consolewrite("open fail" & @CRLF)
            return seterror(3, 0, 0)
        endif

            sleep(100)

        local $fText = fileread($fHandle)
        if @Error Then
            consolewrite("read fail" & @CRLF)
            FileClose($fHandle)
            return seterror(4, 0, 0)
        endif

        FileClose($fHandle)
        FileWrite ($newTXTScanFileName, $ftext)

        $deleted = FileDelete($newTXTScanFileName)
        if $deleted = 0 Then
            consolewrite("delete fail" & @CRLF)
            FileClose($fHandle)
            return seterror(4, 0, 0)
        endif


    WEnd
EndFunc

but then i found this:

Func _Main()
    Local $hGUI, $iFormat, $iCount

    ; Create GUI
    $hGUI = GUICreate("Clipboard", 600, 400)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_HSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Open the clipboard
    If Not _ClipBoard_Open ($hGUI) Then _WinAPI_ShowError ("_ClipBoard_Open failed")

    ; Show clipboard formats available
    MemoWrite("Clipboard formats ..: " & _ClipBoard_CountFormats ())

    ; Enumerate clipboard formats
    Do
        $iFormat = _ClipBoard_EnumFormats ($iFormat)
        If $iFormat <> 0 Then
            $iCount += 1
            MemoWrite("Clipboard format " & $iCount & " .: " & _ClipBoard_FormatStr ($iFormat))
        EndIf
    Until $iFormat = 0

    ; Close the clipboard
    _ClipBoard_Close ()

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

So is there a way to convert the ctrl-a / ctrl-c to the clipboard without using the text files?

Share this post


Link to post
Share on other sites



What Window Text are you using the Mouse Clicks for? Can you not do a ControlGetText() with ClipPut() and write to file with ClipGet?

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  
Followers 0