;感谢空大佬的分享 https://github.com/telppa/Translation-Terminator
;感谢空大佬的分享 https://github.com/telppa/BeautifulToolTip
; -------------------------- Run as Administrator --------------------------
full_command_line := DllCall("GetCommandLine", "str")
If not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
Try
{
If A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
Else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
; ------------------------------------------------------------------------------
;↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓需要修改的区域↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#Include, 填你的路径\SogouTranslator.ahk
#Include, 填你的路径\NonNull.ahk
#Include, 填你的路径\Chrome.ahk
#Include, 填你的路径\UriEncode.ahk
#Include, 填你的路径\Class_bdocr.ahk
#Include, 填你的路径\JSON.ahk
#Include, 填你的路径\BTT.ahk
#Include, 填你的路径\Gdip_all.ahk
;下方填入百度OCR的Key
;例子:API_KEY:="********************************"
API_KEY:=""
SECRET_KEY:=""
;↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑需要修改的区域↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
SendMode, Input
#SingleInstance, Force
#UseHook
#InstallKeybdHook
#InstallMouseHook
#Persistent
Process , Priority, , High
SogouTranslator.init()
CoordMode, Mouse, Screen
MouseGetPos, X, Y
BTT("初始化完成",X,Y,,{coormode:"screen"})
Return
~LButton:: ;按下左键划词,然后翻译
st:=A_TickCount
BTT()
Clipboard:=
KeyWait, Lbutton, up
MouseGetPos, X, Y
sendinput,^c
ClipWait, , 0
BTT(SogouTranslator.translate(Clipboard,"auto","zh-CHS") "`n耗时:" (A_TickCount-st),X,Y+5,,{coormode:"screen"})
;翻译代码查询
;https://deepi.sogou.com/doccenter/texttranslatedoc?anchor=commonlanlist
;SogouTranslator.free()
Return
~RButton:: ;按下右键ocr,然后翻译
str:=
area:= DrawRectangle()
CoordMode, Mouse, Screen
MouseGetPos, X, Y
Area:=area.1 "|" area.2 "|" area.3 "|" area.4
pToken := Gdip_Startup()
MouseMove, 0, 0
pBitmap := Gdip_BitmapFromScreen(Area)
MouseMove, X, Y
;Gdip_SaveBitmapToFile检测截图是否正确
;Gdip_SaveBitmapToFile(pBitmap, "test.png", 100)
ocr:=new bdocr(API_KEY, SECRET_KEY)
ret:=ocr.GetOcr(pBitmap,"accurate_basic") ; 高精度识别
for k,v in JSON.Load(ret).words_result
{
str.=v.words
}
CoordMode, ToolTip, Screen
BTT(SogouTranslator.translate(str,"auto","zh-CHS"),X,Y+5,,{coormode:"screen"}))
Return
F8::ExitApp
DrawRectangle()
{
labelredraw:
SysGet, Mon1, Monitor, 1
pToken := Gdip_Startup()
CoordMode, mouse, Screen
KeyWait, Rbutton, D
MouseGetPos, x0, y0
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()
Width := Mon1Right, Height := Mon1Bottom
hdc := CreateCompatibleDC()
hbm := CreateDIBSection(Width, Height)
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
pPen := Gdip_CreatePen(0xffff0000, 1)
Loop,
{
MouseGetPos, x1, y1
w:= Abs(x1-x0)
h:= Abs(y1-y0)
;ToolTip, 基于screen坐标: %x1% , %y1%
Gdip_DrawRectangle(G, pPen, x0, y0, w, h)
;Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
Gdip_GraphicsClear(G)
GetKeyState, KeyIsDown, RButton,P
if(KeyIsDown="U")
Break
}
;↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓重画框框↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
;MsgBox, 4, , 截取的范围还满意么?
;IfMsgBox, No
;{
; Gdip_DeletePen(pPen)
; Gdip_GraphicsClear(G)
; Gdip_DrawRectangle(G, pPen, x0, y0, w, h)
; UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
; Goto, labelredraw
;}
;↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑重画框框↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Gdip_DeletePen(pPen)
Gdip_GraphicsClear(G)
Gdip_DrawRectangle(G, pPen, x0, y0, w, h)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
; 删除画布
Gdip_DeleteGraphics(G)
; 还原位图
SelectObject(hdc, obm)
; 删除 DC
DeleteDC(hdc)
; 删除位图
DeleteObject(hbm)
Gdip_Shutdown(pToken)
w:= Abs(x1-x0)
h:= Abs(y1-y0)
Return [x0,y0,w,h]
}
积分积分