ahk实现vim中一键翻译单词

用vim的过程中弄了很多方法来翻译单词始终不是很方便,有的方法还需要外部软件或者命令行工具的辅助,最后一拍脑袋还是用ahk的方法最好

效果

ahk实现vim中一键翻译单词

 

            XButton1::
            <#y::
                原值:=Clipboard
                Clipboard =
                WinGetClass, cls, A
                if( cls = "Vim" ){
                    SendInput,yiw
                    ClipWait, 1, 1
                }
                Else
                    SendInput ^c
                gosub sound
            return
            sound:
                ClipWait,0.5
                If(ErrorLevel)
                {
                    InputBox,varTranslation,请输入,你想翻译啥,我来说
                    if !ErrorLevel
                    {
                        Youdao译文:=YouDaoApi(varTranslation)
                        Youdao_网络释义:= json(Youdao译文, "web.value")
                        SplashYoudaoMsg(varTranslation, Youdao_网络释义)
                        try {
                            spovice:=ComObjCreate("sapi.spvoice")
                            spovice.Speak(Youdao_网络释义)
                        }
                    }
                }
                else
                {
                    varTranslation:=Clipboard
                    Youdao译文:=YouDaoApi(varTranslation)
                    Youdao_网络释义:= json(Youdao译文, "web.value")
                    SplashYoudaoMsg(varTranslation, Youdao_网络释义)
                    try{
                        spovice:=ComObjCreate("sapi.spvoice")
                        spovice.Speak(Youdao_网络释义)
                    }
                }
                ;Clipboard:=原值
                Clipboard:=Youdao_网络释义
            return
            SplashYoudaoMsg(title, content){
                MouseGetPos, MouseX, MouseY ;获得鼠标位置x,y
                MouseZ := MouseX + 100
                ToolTip,
                (
                    %title%
                    %content%
                )
                SetTimer,reto,1000
            }
            reto:
                ToolTip
            return
            YouDaoApi(KeyWord)
            {
                ;    KeyWord:=SkSub_UrlEncode(KeyWord,"utf-8")
                url:="http://fanyi.youdao.com/fanyiapi.do?keyfrom=qqqqqqqq123&key=86514254&type=data&doctype=json&version=1.1&q=" . KeyWord
                WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
                WebRequest.Open("GET", url)
                WebRequest.Send()
                result := WebRequest.ResponseText
                return result
            }
            json(ByRef js, s, v = "")
            {
                j = %js%
                loop, Parse, s, .
                {
                    p = 2
                    RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q)
                    loop {
                        if (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|"
                            . "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p))
                        return
                        else if (x2 == q2 or q2 == "*") {
                            j = %x3%
                            z += p + StrLen(x2) - 2
                            if (q3 != "" and InStr(j, "[") == 1) {
                                StringTrimRight, q3, q3, 1
                                loop, Parse, q3, ], [
                                {
                                    z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x)
                                    j = %x1%
                                }
                            }
                            break
                        }
                        else p += StrLen(x)
                        }
                }
                if v !=
                {
                    vs = "
                    if (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx)
                        and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul"))
                    vs := "", v := vx1
                    StringReplace, v, v, ", \", All
                    js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1)
                }
                return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul"
                ? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j
            }

给TA捐赠
共{{data.count}}人
人已捐赠
其他应用

《帝国时代》单击版作弊代码AHK辅助

2022-12-31 21:54:52

其他函数

【操作托盘图标】TrayIcon库 v2版

2023-1-2 8:55:07

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索