Jump to content

Text Selected on Web and Copied

Recommended Posts


Hi, I would like to select text on my browser and then start the my au3 file which will copy my selected text to the clipboard and paste into a text file.   Problem is that I can't get ClipPut to copy selected text (from a webpage) to the clipboard (without putting the selected text in a variable in the program...defeating the purpose).    Obviously I am new.  Any suggestions?  Thank you!

Func get()

    ; ClipPut() this is where I want the prog to signal to windows to put whatever text is selected into clipboard
    $sFilePath = 'C:\HTML_LI.txt'
    $text = ClipGet()

    ; Write data to the file using the handle returned by FileOpen.
    FileWrite($sFilePath, $text)

EndFunc  ;==>get


Share this post

Link to post
Share on other sites

Test this script:

#include <Clipboard.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>

Global $g_idMemo, $g_hNext = 0


Func Example()
    Local $hGUI

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

    ; Initialize clipboard viewer
    $g_hNext = _ClipBoard_SetViewer($hGUI)


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

    ; Shut down clipboard viewer
    _ClipBoard_ChangeChain($hGUI, $g_hNext)
EndFunc   ;==>Example

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

; Handle $WM_CHANGECBCHAIN messages
Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    ; Show that message was received
    MemoWrite("***** $WM_CHANGECBCHAIN *****")

    ; If the next window is closing, repair the chain
    If $wParam = $g_hNext Then
        $g_hNext = $lParam
        ; Otherwise pass the message to the next viewer
    ElseIf $g_hNext <> 0 Then
        _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd")

; Handle $WM_DRAWCLIPBOARD messages
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    ; Display any text on clipboard

    ; Pass the message to the next viewer
    If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam)

It's the example in helpfile about _ClipBoard_ChangeChain.

Share this post

Link to post
Share on other sites

Thank you very much for your quick response!   I have run it and nothing happened but I have to understand the code first so I am going through the process of figuring out line by line.   Thank you for your help!

Share this post

Link to post
Share on other sites

I am also looking to something similar, and rather than start a new post, I figured I would hijack this one.


I am looking to use a HotKey to call my function. I want my function to copy the selected test word and put it into the clipboard, but the clipboard is not being populated when I send the key commands to copy the text. Can someone point me to my error?

#include <Misc.au3>
HotKeySet('!w', 'GetHighlightedWord')
While 1

Func GetHighlightedWord()
    ;_SendEx('^c') have tried this function as well
    $sWord = ClipGet()
    MsgBox(0, 'What is in the clipboard?', $sWord)

EndFunc   ;==>GetHighlightedWord

Func _SendEx($ss, $warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")

        If $warn <> "" And TimerDiff($iT) > 1000 Then
            MsgBox(0, "Warning", $warn)
EndFunc   ;==>_SendEx


edit Not sure why the colors are off on the code?

EDIT 2,the colors now appear to be correct, maybe a refresh fixed the code colors?

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."



WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes




GDI Basics


GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post

Link to post
Share on other sites
1 hour ago, nitekram said:

I would hijack this one.

Hijacker's will be arrested, so don't do this.

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