Jump to content
Sign in to follow this  


Recommended Posts


Seeing as how I created the _ClipPutHTML() & _ClipPutHyperlink() functions, I figured why not complete the set of available functions and finish out the HTML clipboard read/set UDFs.

The below example is included in the ZIP file on my site.

Example: HTML Clipboard Monitor

#include <Misc.au3>     ; _IsPressed()

#include <_ClipGetHTML.au3>
; ================================================================================================
; <HTMLClipBoardMonitor.au3>
; Simple program used to Monitor and Report on HTML formatted ClipBoard data
; Functions:
; MemoWrite() ; from the AutoIT documentation examples
; Dependencies:
; <_ClipGetHTML.au3> ; _ClipGetHTML()
; See also:
; <_ClipPutHTML.au3>
; Author: Ascend4nt, and [??] (whoever coded the AutoIT Help examples with MemoWrite())
; ================================================================================================

Global $iMemo

; MemoWrite and GUI creation courtesy of AutoIT Help Examples

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

Local $hGUI
Local $sHTMLStrPrev="",$aHTMLData
Local $sPlainText,$aHTMLLinks

; Create GUI
$hGUI = GUICreate("HTML ClipBoard Monitor ([F5] Forces Refresh)", 600, 400)
$iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, 0x200000)    ; $WS_VSCROLL=0x00200000
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    If Not @error And ($aHTMLData[0]<>$sHTMLStrPrev Or _IsPressed("74")) Then
    ; Clear the Edit Control
    MemoWrite("==== New HTML Data received ("&@HOUR&':'&@MIN&":"&@SEC&") ===="&@CRLF&"Version #"&$aHTMLData[1]&@CRLF& _
    "Fragment Start:"&$aHTMLData[2]&", Fragment End:"&$aHTMLData[3]&@CRLF& _
    "Selection Start (optional [-1=unavailable]):"&$aHTMLData[4]& _
    ", Selection End (optional):"&$aHTMLData[5]&@CRLF& _
    "Source URL (optional string):"&$aHTMLData[6]&@CRLF& _
    "4 characters at Fragment Start:"&StringMid($aHTMLData[0],$aHTMLData[2],4)&@CRLF& _
    "4 characters at Fragment End:"&StringMid($aHTMLData[0],$aHTMLData[3],4)&@CRLF)
    If $aHTMLData[4]<>-1 Then
    MemoWrite("4 characters at Selection Start:"&StringMid($aHTMLData[0],$aHTMLData[4],4)&@CRLF& _
    "4 characters at Selection End:"&StringMid($aHTMLData[0],$aHTMLData[5],4))
    MemoWrite("---- CF_HTML Header (size="&StringLen($aHTMLData[7])&") ----"&@CRLF&$aHTMLData[7]&@CRLF)
    MemoWrite("---- RAW HTML Data (UTF-8 size="&StringLen($aHTMLData[0])&") ----"&@CRLF&BinaryToString($aHTMLData[0],4)&@CRLF)
    MemoWrite("---- Plain Text Variant (size="&StringLen($sPlainText)&") ----"&@CRLF&$sPlainText)
    ; Want to put it back just the way it came? This is one approach, but
    ; the Offsets will not be placed properly
    ; This is the proper way:

    Local $sHTMLData=$aHTMLData[7]&$aHTMLData[0]

Until _IsPressed("1B") Or GUIGetMsg()=-3    ; $GUI_EVENT_CLOSE=-3

Get the Code at my Site

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
*EDIT: added Memory Lock/Unlock (recommended and often-used way to ensure a successful grab of a Clipboard memory object), and added clarification on correct way to get memory block size Edited by Ascend4nt

Share this post

Link to post
Share on other sites


Edited by Ascend4nt

Share this post

Link to post
Share on other sites


Edited by Ascend4nt

Share this post

Link to post
Share on other sites

Autoit v3.3.10.2

Thanks for this excellent work!

There's a small bug in the URL extraction: url containing the z letter are truncated.

Character classes

A character classes defines a set of allowed (resp. disallowed) characters, which the next character in subject is expected to match (resp. not to match).
Inside a character classes, most metacharacters loose their meaning (like $ . or *) or mean something else (like ^).

[ ... ] Matches any character in the explicit set: "[aeiou]" matches any lowercase vowel. A contiguous (in Unicode codepoint increasing order) set can be defined by putting an hyphen between the starting and ending characters: "[a-z]" matches any lowercase ASCII letter. To include a hyphen (-) in a set, put it as the first or last character of the set or escape it (-).
Notice that the pattern "[A-z]" is not the same as "[A-Za-z]": the former is equivalent to "[A-Z[]^_`a-z]".
To include a closing bracket in a set, use it as the first character of the set or escape it: "[][]" and "[[]]" will both match either "[" or "]".
Note that in a character class, only d, D, h, H, p{}, P{}, s, Q...E, S, v, V, w, W, and x sequences retain their special meaning, while b means the backspace character (Chr(8)). [^ ... ] Matches any character not in the set: "[^0-9]" matches any non-digit. To include a caret (^) in a set, put it after the beginning of the set or escape it (^).




 So ^ rnz are not intepreted. I replaced :

Local $sSourceURL=StringRegExp($sHTMLHeader,"(?i)SourceURL:([^ \r\n\z]+)",1)


Local $sSourceURL=StringRegExp($sHTMLHeader,"(?i)SourceURL:(.*)\r\n",1)
Edited by Silpark

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  

  • Similar Content

    • By wysocki
      I have a smartphone and I use it to access my email. However, when composing an email on it I have a problem. My list of phone contacts on the phone is very different from my list of email contacts in my Thunderbird desktop app.  I use my Gmail address book to store primarily phone contacts, and I use Thunderbird for my list of email contacts. I wanted a way to get my Thunderbird contact list onto my smartphone to be able to compose emails to addresses in that list. Here's my solution.
      I wrote a script to export my Thunderbird Personal Address Book to a csv file. It then reads that file and re-writes it with html wrappers around the data to make it into a nicely formatted web page. It then uploads the htm file to my website. On my smartphone, I created a shortcut to the file's URL and whenever I click it, I get the list displayed. Each contact shows name and email address along with a COPY button that will put the address into the clipboard. Then in my email client, I can easily paste that address into it. Alternatively, clicking on the actual email link will open a new message dialog in your email client with that address already entered.
      To use the app, all you need to do is use Thunderbird and have a webserver available. You'll need to download the FTPEX.AU3 file from this website and make a few changes to some constants around line 17 for FTP login info, etc.
    • By SkysLastChance
      What would be the best way to grab the last digits of this <span>? One of the problems I know I am going to have is sometimes it will be 1 digit other times it might be 3. 

      I am trying to get the list of spans and I get this error.

      $oInputs = _IETagNameGetCollection($oIE, "span") $sTxt = "" For $oInput In $oInputs     $sTxt &= $oInput.Innertext & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Form Input Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & "         Types :" & @CRLF & $sTxt)  
    • By rudi
      from other postings here as a start I'm quite Close to my Goal of putting formatted text to the clipboard:
      #include-once #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg, $g_hRichEdit Example("The first text will be formatted ""as is""" & @CRLF & _ "(Default Font and font size)", "This text is formatted differently") MsgBox(0, "Rich Text copied", "Formatted Text put to clipboard") Func Example($TextDefault, $TextCourier) Local $hGui, $iMsg, $idBtnNext, $iStep = 0 $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, $TextDefault, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($g_hRichEdit, -1, -1) ; set selection behind last CHAR in RTF_EDIT _GUICtrlRichEdit_SetFont($g_hRichEdit, 8, "Courier New") ; change font to 8pt, Courier New _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & $TextCourier) _GUICtrlRichEdit_SetSel($g_hRichEdit, 0, -1) ; select all the content of the RTF_EDIT _GUICtrlRichEdit_Copy($g_hRichEdit) ; put the selection to the clipboard EndFunc ;==>Example  
      Finally the clipboard content has to hold pre-formatted data to be pasted into an email body. for the 2nd part I'd like to add a frame around the text, like I did manually before taking this screenshot.

      Any suggestions, or maybe some absolutely different Approach?
      CU, Rudi.
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
    • By Colduction
      Hello AutoIt Scriptwriters! 
      I want to read https based site that it's address is: Soft98 (https://soft98.ir/)
      I've tried with "_INetGetSource", "BinaryToString(InetRead)" and "InetRead" but none of them don't help me
      How can i get this site html source code without opening IE Windows? 
  • Create New...