2016-11-04 17 views
0

你必須在計算器的問題和答案的許多代碼示例箱文件代碼樣本框 - 如何選擇框中的所有文本,並保存在一個點擊AutoHotkey的

我想這樣的:如果我去那個框中,我可以在中單擊一下f2將文本從該框中直接保存到文件中。

的AutoHotkey的(AHK)腳本必須這樣做:

  • 選擇所有文字複製文本到剪貼板
  • 保存的文本文件(例如。 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

難道你希望你的腳本工作?當然你必須知道'^ a'選擇瀏覽器文檔中的所有文本,而不僅僅是當前選擇的「代碼框」。無論如何,由於現代瀏覽器不公開任何文檔內容,AHK無法讓你走得很遠。將本地JavaScript注入瀏覽器文檔(例如,使用[用戶腳本](https://wiki.greasespot.net/User_script))是最強大的選擇。 – MCL

回答

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 
+0

讓我們[在聊天中繼續討論](http://chat.stackoverflow.com/rooms/127409/discussion-between-arnoldburg-and-user3419297)。 – arnoldburg

+0

user3419297謝謝,這對我很有用:如果你想保存它,它會詢問每個盒子。 – arnoldburg

相關問題