學(xué)印尼語遇到一個問題谆级,即需要大量復(fù)制pdf文本中的個別單詞到谷歌翻譯中莺奔,這個過程需要重復(fù)點擊和按鍵,及其耗費時間,為此寫了一個腳本 只需要
雙擊生詞
或自定義鍵盤按鍵
就可以自動復(fù)制栈虚、翻譯(需要提前在翻譯的網(wǎng)頁中設(shè)置翻譯的語言類別)、并將結(jié)果以附注形式添加到pdf中史隆,方便重復(fù)查看魂务。
本文教程的視頻為 https://www.bilibili.com/video/BV1hS4y1f7yy
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.5
Author: GDP
Script Function:
Template AutoIt script.
功能: 使用autoit腳本,通過雙擊pdf文件中不知道的單詞(通過識別被選中文字的背景色)泌射,
然后自動在翻譯網(wǎng)頁中進(jìn)行翻譯粘姜,并將翻譯結(jié)果作為單詞的 文本附注。
特點:
1- 快速翻譯單詞
2-可將翻譯結(jié)果作為附注
3-方便 雙擊單詞即可
比如有道詞典一類的軟件也可以識別鼠標(biāo)動作進(jìn)行翻譯熔酷,但不會將翻譯的結(jié)果記錄到pdf文件中
本腳本可以 快速(比通過手動地復(fù)制單詞 粘貼到瀏覽器網(wǎng)頁中搜索快)地將翻譯結(jié)果 以 附注 形式添加到
pdf文件中孤紧,方便之后查看單詞的意思
限制:
1-需要了解下autoit 的基礎(chǔ),b站有教程拒秘,一個小時可入門
2-因為pdf和pdf閱讀器原因号显,可能無法準(zhǔn)確識別已選擇文本的背景色,通過識別鼠標(biāo)雙擊比較準(zhǔn)確
-------------------------------------------------------------------------
需要提前設(shè)置及注意的的內(nèi)容包括:
1-瀏覽器位置-本腳本中瀏覽器在任務(wù)欄第一的位置
2-pdf文件的位置-本腳本中pdf文件在任務(wù)欄第二的位置
3-瀏覽器標(biāo)簽的位置-本腳本中第一個標(biāo)簽為google翻譯網(wǎng)頁
4-雙擊單詞后單詞的背景色-本腳本中使用的acrobat軟件中雙擊后出現(xiàn)的背景色
5-翻譯的對象及結(jié)果-需要提前在翻譯網(wǎng)頁中選擇正確選項
6-盡量保證pdf文件中沒有與選擇文本出現(xiàn)的背景色相同的顏色躺酒,可提前刪除pdf文件中的圖像或 其他可能相似的顏色
7-雙擊單詞后會自動識別鼠標(biāo)的位置押蚤,之后在這個位置進(jìn)行右擊并添加附注,所以雙擊后的幾秒內(nèi)且在標(biāo)注添加完成前不要移動鼠標(biāo)
8-識別顏色區(qū)域需要提前設(shè)置即 PixelSearch 函數(shù)
10-翻譯網(wǎng)頁中 播放語音 按鈕的位置
9-其他具體參數(shù)可以自己調(diào)整阴颖,以適應(yīng)自己的電腦
10-腳本無限循環(huán)活喊,不使用時及時關(guān)閉,并盡量不使用其他的軟件量愧,防止在其他window搜索到對應(yīng)顏色
#ce
#include <Date.au3>
$starttime = _NowCalc()
Sleep(2000)
While 1
$coord = PixelSearch(114, 160,1454, 732,0x99C1DA);識別單詞是否被雙擊,雙擊后單詞會有顏色背景帅矗,根據(jù)不同的pdf閱讀器調(diào)整顏色
;PixelSearch 里的坐標(biāo)指的是 區(qū)域內(nèi)左上角 和 右下角兩點各自的的 x和 y 坐標(biāo)
If Not @error Then
ToolTip("單詞被選中 ")
$pos = MouseGetPos() ;first get the pos,use ctrl + tab for open script and get the mouse positon
Send("^c") ;復(fù)制選中的單詞
Sleep(500)
MouseClick("left",222,851,1,2) ;打開瀏覽器
MouseClick("left",80,17,1,2) ;open google translate
MouseClick("left",300,322,1,2) ;點擊輸入框
Send("^a"); choose all the words
Send("{BACKSPACE 20}") ;delet the contentt in the frame
Send("^v"); input the word
sleep(1000) ;wait one second for loading
MouseClick("left",987,326,2) ;choose the translation result
Send("^c") ;復(fù)制選中的翻譯結(jié)果
MouseClick("left",202,426,1,2) ;tap pronounction button
MouseClick("left",402,844,1,2) ;點擊pdf
MouseMove($pos[0],$pos[1])
MouseClick("right") ;右鍵點擊偎肃,只移動鼠標(biāo)為自己操作
Send("n")
Send("^v") ; paste the world
Sleep(500)
$starttime = _NowCalc()
Else
$currenttime = _NowCalc()
$iDateCalc = _DateDiff( 's',$starttime,$currenttime);計算有多少時間沒有選擇新的單詞
If $iDateCalc<>0 And mod($iDateCalc, 30) = 0 Then ;提醒的時間最少30s起步
ToolTip("已經(jīng): " & $iDateCalc & "S沒有選擇新的單詞" );提醒有多久沒有選擇新的單詞
Else
ToolTip("")
EndIf
Sleep(500)
EndIf
WEnd
除了識別雙擊后的文字背景色, 也可以識別鍵盤操作浑此,先將光標(biāo)移動到我們的目標(biāo)單詞累颂,然后 讓腳本識別鍵盤特定按鍵,然后進(jìn)行后續(xù)相同的操作凛俱。即使用另一個函數(shù)即, 可自定義按鍵
If _IsPressed("11",$hDLL) And _IsPressed("10",$hDLL) Then
autoitscript.com/autoit3/docs/ 網(wǎng)頁介紹了如何識別雙擊即下面的腳本
<pre class="geshi geshiprinted lang-autoit ipsCode" style="box-sizing: border-box; font-family: Consolas, "Courier New", "Andale Mono", monospace; font-size: 12px; overflow: auto; tab-size: 4; white-space: pre-wrap; line-height: 13.2px; text-rendering: optimizespeed; background: rgb(248, 248, 248); clear: both; direction: ltr; overflow-wrap: normal; margin: 0px 0px 0px 10px; border-radius: var(--radius-1); padding: 5px; border-color: rgb(201, 201, 201); border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 4px !important; border-image: initial; max-height: 500px; color: rgb(53, 60, 65); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[#Include](https://www.autoitscript.com/autoit3/docs/keywords/include.htm) <Misc.au3> ; Used for the _IsPressed
[HotKeySet](https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm)("{ESC}", "_ExitScript") ;Press Ecs key to Exit script
[Local](https://www.autoitscript.com/autoit3/docs/keywords.htm) $hDLL = [DllOpen](https://www.autoitscript.com/autoit3/docs/functions/DllOpen.htm)("user32.dll") ; Dll as calling _IsPressed function repeatedly
[While](https://www.autoitscript.com/autoit3/docs/keywords.htm) 1
$nLeftclicks = 0 ;Initialize left click count on each iteration
[If](https://www.autoitscript.com/autoit3/docs/keywords.htm) [_IsPressed](https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm)("01", $hDLL) [Then](https://www.autoitscript.com/autoit3/docs/keywords.htm) ;If left mouse button pressed
$Pos = [MouseGetPos](https://www.autoitscript.com/autoit3/docs/functions/MouseGetPos.htm)() ;Get mouse position
[Do](https://www.autoitscript.com/autoit3/docs/keywords.htm)
[While](https://www.autoitscript.com/autoit3/docs/keywords.htm) ([_IsPressed](https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm)("01", $hDLL)) ;Wait until user releases button
[Sleep](https://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(10)
[WEnd](https://www.autoitscript.com/autoit3/docs/keywords.htm)
$nLeftclicks += 1 ;Increment click count
[sleep](https://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100) ;Wait for 100ms
$aTemp = [MouseGetPos](https://www.autoitscript.com/autoit3/docs/functions/MouseGetPos.htm)() ;Get new mouse position again
[Until](https://www.autoitscript.com/autoit3/docs/keywords.htm)([Not](https://www.autoitscript.com/autoit3/docs/keywords.htm) ($aTemp[0] = $Pos[0] [and](https://www.autoitscript.com/autoit3/docs/keywords.htm) $aTemp[1] = $Pos[1] [and](https://www.autoitscript.com/autoit3/docs/keywords.htm) [_IsPressed](https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm)("01", $hDLL))) ;Loop until mouse is on a new position or it is not pushed again
[ToolTip](https://www.autoitscript.com/autoit3/docs/functions/ToolTip.htm)("X: " & $Pos[0] & "Y: " & $Pos[1] & "Number of continous clicks: " & $nLeftclicks)
[ConsoleWrite](https://www.autoitscript.com/autoit3/docs/functions/ConsoleWrite.htm)("X: " & $Pos[0] & "Y: " & $Pos[1] & "Number of continous clicks: " & $nLeftclicks & [@crlf](https://www.autoitscript.com/autoit3/docs/macros.htm#%40CRLF))
[EndIf](https://www.autoitscript.com/autoit3/docs/keywords.htm)
[Wend](https://www.autoitscript.com/autoit3/docs/keywords.htm)
[Func](https://www.autoitscript.com/autoit3/docs/keywords.htm) _ExitScript()
[DllClose](https://www.autoitscript.com/autoit3/docs/functions/DllClose.htm)($hDLL)
[Exit](https://www.autoitscript.com/autoit3/docs/keywords.htm)
[EndFunc](https://www.autoitscript.com/autoit3/docs/keywords.htm) ;=> _ExitScript</pre>