stackoverflow中的问题与解答中有许多代码示例框
我想要这个:如果我去那个盒子,我可以用 ONE CLICK f2 将该文本中的文本直接保存到文件中。
autohotkey(AHK)脚本必须执行此操作:
此脚本不起作用。
; ^ = Ctrl
; ! = Alt
; # = Win (Windows logo key)
; + = Shift
f2::
; this does not work it will select all text from the website
; but i want do that it select all the text in that box
; and then save it direct to a file
send ^a
send ^c ;copy selected text to clipboard
FileAppend, %Clipboard%, %A_MyDocuments%\example.ahk ;save clipboard to file
return
答案 0 :(得分:1)
也许是这样的:
F2::
FileDelete, %A_Temp%\stackoverflow website.txt
FileDelete, %A_MyDocuments%\example.ahk
ClipSaved := ClipboardAll ; save clipboard
clipboard = "" ; empty clipboard
Send, ^l ; mark the adress in your browser
Sleep, 100
Send, ^c ; copy the adress
ClipWait 1 ; wait for the clipboard to contain data
If not ErrorLevel ; If NOT ErrorLevel clipwait found data on the clipboard
{
If !InStr(clipboard, "http://stackoverflow.com")
{
MsgBox, You're NOT in stackoverflow
clipboard := ClipSaved
return
}
; otherwise:
UrlDownloadToFile, %clipboard%, %A_Temp%\stackoverflow website.txt
Sleep, 200
FileRead, Contents, %A_Temp%\stackoverflow website.txt
{
Array := StrSplit(Contents, "code>")
for key, val in Array
{
If (SubStr(val, -1) = "</")
{
If (StrLen(val) < 50)
continue
If InStr(val, "WScript")
continue
; ... add more restrictions
val := SubStr(val, 1, -2)
MsgBox, 4,, Do you want to save this code? `n`n%val%
IfMsgBox Yes
{
FileAppend, %val%, %A_MyDocuments%\example.ahk ; save val to file
break
}
}
}
}
}
Sleep, 300
clipboard := ClipSaved ; restore original clipboard
FileDelete, %A_Temp%\stackoverflow website.txt
return