qUser4eva Posted August 26, 2008 Posted August 26, 2008 How can I get and set the clipboard data using HTML?E.g. user copies this text from webpage: Hello world.AutoIt reads the clipboard as <b>Hello world.</b>.Thanks!
nerdgerl Posted August 26, 2008 Posted August 26, 2008 How can I get and set the clipboard data using HTML? E.g. user copies this text from webpage: Hello world. AutoIt reads the clipboard as <b>Hello world.</b>. Thanks! $newstring = "<B>" & ClipGet() & "</B>" My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."
qUser4eva Posted August 26, 2008 Author Posted August 26, 2008 (edited) Thanks for the response. I was essentially asking how to read data with its HTML preserved from the clipboard; I'm not trying to add my own.For instance, the user would press Ctrl+A (select all) and then Ctrl+C (copy) in firefox, and AutoIt could read the rendered HTML page source from the clipboard.Thanks in advance. Edited August 26, 2008 by qUser4eva
nerdgerl Posted August 27, 2008 Posted August 27, 2008 Thanks for the response. I was essentially asking how to read data with its HTML preserved from the clipboard; I'm not trying to add my own.For instance, the user would press Ctrl+A (select all) and then Ctrl+C (copy) in firefox, and AutoIt could read the rendered HTML page source from the clipboard.Thanks in advance.HA! I knew the question was too easy! I read it wrong!! LoL My AutoIT's:[topic="53958"]Personal Encyclopedia/Dictionary[/topic][topic="46311"]MS Access (Style) Database[/topic]"Some people are born on third base and go through life thinking they hit a triple."
Nahuel Posted August 28, 2008 Posted August 28, 2008 IF I'm not wrong, Firefox has that option built-in (It's either Firefox or Opera).It could be possible... perhaps using ClipGet() (or the _Clipboard*() functions for more advanced options) and _InetGetSource(). The only problem I can think of right now is how to make the script know where the HTML code of that part starts and where it ends.
qUser4eva Posted August 29, 2008 Author Posted August 29, 2008 (edited) Although, I'm sure how to do it, I think the best approach would be to use _ClipBoard_GetData([$iFormat = 1]), and somehow pass "HTML" as $iFormat to the function. How do I do that? thanks. Edited August 30, 2008 by qUser4eva
larryc Posted January 28, 2009 Posted January 28, 2009 Did this ever get solved? I'm looking to do the same thing. I've googled using HTML fragments http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx and http://support.microsoft.com/kb/274326 , but I can't get it working in Autoit.
qazwsx Posted January 28, 2009 Posted January 28, 2009 maybe you could read the pages source to a variable. Then find the text which is selected and take all of the html tags associated with it from the source. Fairly roundabout, but im not sure if another solution has been found.
larryc Posted January 28, 2009 Posted January 28, 2009 I think I answered my own question. I had to bastardize the _clipboard_setdata function, but it appears to be working. Running this script will put HTML formatted data onto the clipboard, which can then be pasted into an application such as Email, Word, etc. CODE #include <ClipBoard.au3> ; Open the clipboard If Not _ClipBoard_Open (0) Then msgbox (0,'Error',"_ClipBoard_Open failed") $iFormat = _ClipBoard_RegisterFormat ("HTML Format") If $iFormat = 0 Then msgbox(0,'',"_ClipBoard_RegisterFormat failed") ;msgbox(0,'','$iformat is ' & $iFormat) $i = _ClipBoard_GetData($iFormat) ;msgbox(0,'$i is',$i) $m_sDescription = _ "Version:1.0" & @CrLf & _ "StartHTML:aaaaaaaaaa" & @CrLf & _ "EndHTML:bbbbbbbbbb" & @CrLf & _ "StartFragment:cccccccccc" & @CrLf & _ "EndFragment:dddddddddd" & @CrLf $sStart = "<HTML><BODY><FONT FACE=Arial SIZE=1 COLOR=BLUE>" $sFrag = '<B>This is bold</B> and <I>this is italic.</I> And this is a <a href="http://www.yahoo.com">hyperlink</a>' $sEnd = "</FONT></BODY></HTML>" ;msgbox(0,'test',stringFormat( "%010s",stringLen($m_sDescription))) $sData = $m_sDescription & $sStart & $sFrag & $sEnd $sData = stringReplace($sData, "aaaaaaaaaa", stringFormat("%010s",stringLen($m_sDescription))) $sData = stringReplace($sData, "bbbbbbbbbb", stringFormat("%010s",stringLen($sData))) $sData = stringReplace($sData, "cccccccccc", stringFormat("%010s",stringLen($m_sDescription & $sStart))) $sData = stringReplace($sData, "dddddddddd", stringFormat("%010s",stringLen( $m_sDescription & $sStart & $sFrag))) ;msgbox(0,'sdata',$sData) if (my_ClipBoard_SetData($sData,$iformat,1) == 0 ) then msgbox(0,'Error','Error putting data on clipboard') _ClipBoard_Close() Func My_ClipBoard_SetData($vData, $iFormat = 1,$force = 0) Local $tData, $hLock, $hMemory, $iSize If ($force ==1) Then $iSize = StringLen($vData) + 1 $hMemory = _MemGlobalAlloc($iSize, $GHND) If $hMemory = 0 Then Return SetError(-1, 0, 0) $hLock = _MemGlobalLock($hMemory) If $hLock = 0 Then Return SetError(-2, 0, 0) $tData = DllStructCreate("char Text[" & $iSize & "]", $hLock) DllStructSetData($tData, "Text", $vData) _MemGlobalUnlock($hMemory) Else ; Assume all other formats are a pointer or a handle (until users tell me otherwise) $hMemory = $vData EndIf If Not _ClipBoard_Open(0) Then Return SetError(-5, 0, 0) If Not _ClipBoard_Empty() Then Return SetError(-6, 0, 0) If Not _ClipBoard_SetDataEx($hMemory, $iFormat) Then _ClipBoard_Close() Return SetError(-7, 0, 0) EndIf _ClipBoard_Close() Return $hMemory EndFunc ;==>my_ClipBoard_SetData
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now