For clipboard handling with AutoHotkey I recommend the following resource called WinClip .
WinClip references
WinClip is mentioned in this AutoHotkey forum entry: 74670-class-winclip-direct-clipboard-manipulations
Unfortunately this forum is archived so you can not comment on the thread anymore.
I couldn't find a way to reach out to the author or report any issue. If you know how, please comment on this post.
You can find its documentation here: http://www.apathysoftworks.com/ahk/index.html
The script seems unmaintained since 2012. Still it is a great utility.
Examples
Get clipboard content in HTML format
This is the best way I've found to extraxt HTML from the clipboard content.
It is as easy as:
sHtml := WinClip.GetHTML()
Paste in Plain Text
WinClip.Paste(clipboard)Create Rich HotStrings
See separate post here.
Known issues
Copy to clipboard
I have tried to use the Copy method to get the current selection. Unfortunately it seems not to work. (I use Windows 10)
My wish method for getting the current selection would have been, if it were working as I am expecting:
GetSelection(type:="text"){
; Syntax:
; sSelection:=GetSelection("text"*|"html")
; Default "text"
wc := new WinClip
wc.iCopy()
If (type = "text") {
sSelection := wc.iGetText()
MsgBox %sSelection%
}
Else If (type ="html") {
sSelection := wc.iGetHTML()
}
return sSelection
}
See my current "workaround" solution: (You can download it in GitHub here)
GetSelection(type:="text"){
; Syntax:
; sSelection := GetSelection("text"*|"html")
; Default "text"
; Calls: WinClip.GetHTML
OldClipboard:= ClipboardAll ;Save existing clipboard.
Clipboard:=""
while(Clipboard){
Sleep,10
}
Send,^c ;Copy selected text to clipboard
ClipWait 1
If ErrorLevel {
Clipboard:= OldClipboard
return
}
If (type = "text") {
sSelection := clipboard
;sSelection := WinClip.GetText()
} Else If (type ="html") {
sSelection := WinClip.GetHTML()
}
; Restore Clipboard
Clipboard := OldClipboard
return sSelection
}
No comments:
Post a Comment