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
    Sleep(5000)
    $sFilePath = 'C:\HTML_LI.txt'
    $text = ClipGet()
    Sleep(1000)


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

EndFunc  ;==>get

 

Link to comment
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

Example()

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")
    GUISetState(@SW_SHOW)

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

    GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")
    GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")

    ; Loop until the user exits.
    Do
    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")
    EndIf
EndFunc   ;==>WM_CHANGECBCHAIN

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

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

It's the example in helpfile about _ClipBoard_ChangeChain.

Link to comment
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!

Link to comment
Share on other sites

  • 4 weeks later...

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
    Sleep(200)
WEnd

Func GetHighlightedWord()
    Send('{LCTRL}c')
    ;_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)
        EndIf
        Sleep(50)
    WEnd
    Send($ss)
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."

 

WindowsError.gif

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

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_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

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...