3 posts in this topic
How to put data to clipboard in all available formats? I use _ClipBoard_GetData to save all formats data to files but when I try to put them again to clipboard using _ClipBoard_SetData, I have available only the last data format which I used. After that when I try put this data to "Microsoft Word" I get only "Cleaned" text format. When I the set last format as a HTML and I put to "Micorosft Word" everything fine, but I can't put to Notepad (I get empty value). When I doing this same with _ClipBoard_GetDataEx to save data to memory object (not to file) and put them again using _ClipBoard_SetDataEx all data formats are available... Help?
I've been copying a lot of text from PDF files and other documents. Problem is, this text appears badly mangled when pasted again, causing formatting issues. I've been trying to write a script that would automatically reformat the copied string:
#include <Clipboard.au3> #include <Misc.au3> If _Singleton("PasteModify", 1) = 0 Then MsgBox(0, "NOPE.", "Already Running.") Exit EndIf #NoTrayIcon Opt("TrayMenuMode", 1) $AboutTrayItem = TrayCreateItem("About") TrayCreateItem("") $ExitTrayItem = TrayCreateItem("Exit") TraySetState() $hDLL = DllOpen("user32.dll") Beep(1100,300) While 1 While _IsPressed("11",$hDLL) If _IsPressed("43",$hDLL) Then Beep(1300,150) ;Sleep(750) ;fixes the issue, but not very elegantly. $OriginalClipboardData = ClipGet() $ClipGetError = @error $RegexClipboardData = StringRegExpReplace($OriginalClipboardData, '[\r\n\t]+', ' ') $StripWSClipboardData = StringStripWS($RegexClipboardData,4) ClipPut($StripWSClipboardData) MsgBox(0,$ClipGetError,"ORIGINAL: " & $OriginalClipboardData & @CRLF & @CRLF & "POST-REGEX APPLIED: " & StringRegExpReplace($OriginalClipboardData, '[\r\n\t]+', ' ') & @CRLF & @CRLF & "STRIPWS APPLIED: " & $StripWSClipboardData & @CRLF & @CRLF & "END RESULT: " & ClipGet()) While _IsPressed("43",$hDLL) Sleep(250) WEnd EndIf WEnd Local $msg = TrayGetMsg() Select Case $msg = $AboutTrayItem MsgBox(64, "About", "When CTRL+C is pressed, a reformatted version of the string that has thereby been copied, without any newline characters, should be placed on the clipboard.") Case $msg = $ExitTrayItem ExitLoop EndSelect WEnd DllClose($hDLL) Beep(600,300)
However, every now and then it seems like there's a conflict between this script Windows' access to the clipboard.
If I don't include a long enough sleep (see script), ClipGet() will return that my clipboard is empty, even though it wasn't empty before and I have only selected new text and pressed Ctrl+C since.
Any suggestions? Could I check for clipboard access perhaps...?