Hi all,
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:
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...?
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:
[ autoit ]
#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...?