windows超级运行框-表达式计算(12)—功能汇总

1、环境准备

  1. windows 7,8,10,11操作系统
  2. ahk 2.x_64位
  3. 翻译 功能需要联网使用

2、使用方式

 输入win+R打开windows运行框 

  1. get/getpath 命令获取配置文件环境变量
  2. set/sets 设置 “用户/系统” 环境变量或者path
  3. encode/decode 中文编码和解码
  4. len 计算字符串长度或者剪切板字符串长度
  5. uuid/cpuid 获取随机id 或者cpu序列号
  6. asc/chr/ord 计算字符的asc码值,中文对应数值,把数值转为对应字符
  7. low/up 把字符串转为小写或大写
  8. + – * /  ** ^ % ()  k(千) w(万) y(亿)  sqrt 数学表达式计算
  9. mean/meank/meanj     翻译中<->英文 ,中<->韩,中<->日
  10. toBase , 0x , o ,(1001010)   任意进制转化,16进制转10进制,8进制转10进制,2进制转10进制
  11. sum/avg  计算数据总和/平均

 

3、代码

;cpuid预先获取,因为耗时
setTimer ()=>ak.getCpuid() ,-1

#HotIf  winActive("运行") and winActive("ahk_class #32770")
#MaxThreadsPerHotkey 10
;在运行框中执行强大的计算功能,包括数学运算等
:*?:==::{
  try{
       rawText:=ControlGetText("Edit1","A") ;
       fullResult:=runbox.calculateExpression(rawText)
       if fullResult{
           ControlsetText(fullResult,"Edit1","A")
       }
       ControlSend("{END}","Edit1","A")
   }
}
#HotIf
;==========================================================================================================系统快捷键映射

;执行各种运算取值
class runbox
{
    static getconfigPath:=A_ScriptDir "\getconfig.txt"
    static userAgent:="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"

    ;执行比表达式计算,"==" 触发,callflag是其他函数调用该方法
    static calculateExpression(rawstr,callflag:=0)
    {
        ;从配置文件getconfig.txt中获取值
        if inStr(rawStr,"get ")==1 and (not (str:=Trim(Ltrim(rawStr,"get")))==Trim(rawStr)){
            result:=this.getExpression(str,&prefix)
            fulltxt:= rawStr . (prefix?"":"=") . result
            return fulltxt
        }
        ;从配置文件getconfig.txt中获取值
        if inStr(rawStr,"getpath ")==1 and (not (str:=Trim(Ltrim(rawStr,"getpath")))==Trim(rawStr)){
            result:=this.getEnvExpression(str)
            fulltxt:= rawStr . "=" . result
            return fulltxt
        }
        ;设置环境变量user/sys
        if (a:=(inStr(rawStr,"set ")==1) and (not (str:=Trim(Ltrim(rawStr,"set")))==Trim(rawStr)))
            or (inStr(rawStr,"sets ")==1 and (not (str:=Trim(Ltrim(rawStr,"sets")))==Trim(rawStr))){
            result:=this.setEnvExpression(str,a?1:0) ;返回成功/失败
            fulltxt:= rawStr . " " . result
            return fulltxt
        }
        ;把字符转换为uncode编码
        if inStr(rawStr,"encode ")==1{
            result:=this.charcodeExpression(Trim(LTrim(rawStr,"encode")),1)
            return result
        }
        ;把字unicode编码转换为字符串
        if inStr(rawStr,"decode ")==1 or inStr(rawStr,"\u")==1{
            result:=this.charcodeExpression(Trim(LTrim(rawStr,"decode")),0)
            return result
        }
        ;计算字符串长度
        if inStr(rawStr,"len ")==1{
            str:=Trim(LTrim(rawStr,"len"))
            result:=str?strLen(str):strLen(A_clipboard)
            fulltxt:=rawStr . (str?"":"[剪切板]") "=" . result
            return fulltxt
        }
        ;获取cpuid
        if strLower(trim(rawStr))=="cpuid"{
            cpuid :=ak.cpuid or ak.getCpuid()
            fulltxt:= rawStr . "=" . cpuid
            return cpuid
        }
        ;获取uuid随机值
        if strLower(trim(rawStr))=="uuid"{
            uuid:=ak.uuid()
            fulltxt:= rawStr . "=" . uuid
            return uuid
        }
        ;计算字符的asc码值
        if inStr(rawStr,"asc ")==1{
            result:=this.ascOrChrExpression(trim(LTrim(rawStr,"asc")),1)
            fulltxt:= rawStr . "=" . result
            return fulltxt
        }
        ;计算数字所代表字符
        if inStr(rawStr,"ord ")==1 or inStr(rawStr,"chr ")==1{
            result:=this.ascOrChrExpression(Trim(LTrim(LTrim(rawStr,"ord"),"chr")),0)
            fulltxt:= rawStr . "=" . result
            return fulltxt
        }
        ;转换为大写
        if inStr(rawStr,"up ")==1{
            result:=strUpper(Trim(Ltrim(rawStr,"up")))
            fulltxt:= rawStr . "=" result
            return fulltxt
        }
        ;转换为小写
        if inStr(rawStr,"low ")==1{
            result:=strLower(Trim(Ltrim(rawStr,"low")))
            fulltxt:= rawStr . "=" result
            return fulltxt
        }
        ;计算数学表达式
        if (result:=this.mathExpression(rawStr)){
            fulltxt:=rawStr . result
            return result
        }
        ;计算平方根
        if inStr(rawStr,"sqrt ")==1{
            str:=Trim(Ltrim(rawStr,"sqrt"))
            result:=ak.get_bignumber(sqrt(str),3,0) ;该函数自带 = 或者  ≈
            fulltxt:=rawStr . result
            return fulltxt
        }
        ;翻译中<->英翻译,中<->韩互译,中<->日互译 ,注意:判断顺序不能换
        if ((i2:=(inStr(rawStr,"meank ")==1)) or (i3:=inStr(rawStr,"meanj ")==1 or i1:=(inStr(rawStr,"mean ")==1)) ){
           str:= inStr(trim(rawStr)," ")?subStr(rawStr,inStr(trim(rawStr)," ")+1):trim(A_Clipboard)
           result:=this.meanExpression(str,i1??""?"url_ALL":false or i2??""?"url_KO":"" or i3??""?"url_JA":"")
           fulltxt:=rawStr . (inStr(Trim(rawStr)," ")?"":"[剪切板]") "=" . result
           return fulltxt
        }
        ;2进制转为10进制 ,传入字符串(11111000011111)
        if (str:=RTrim(LTrim(Trim(rawStr),"("),")"))!=Trim(rawStr) and not RegExReplace(str,"[10]",""){
            result:=ak.otherToTen(str,2)
            fulltxt:=rawStr . "=" . result
            return callflag?result:fulltxt
        }
        ;8进制转为10进制,传入字符串o开头
        if  inStr(tr:=trim(rawStr),"o")==1 and not RegExReplace((str:=subStr(tr,2)),"\d+","") {
            result:=ak.otherToTen(str,8)
            fulltxt:=rawStr . "=" . result
            return callflag?result:fulltxt
        }
        ;16进制转为10进制 ,传入字符串0x开头
        if  inStr(str1:=trim(rawStr),"0x")==1 and not RegExReplace((str:=subStr(str1,3)),"[a-fA-F\d]+","") {
            result:= Format("{1:d}",str1)
            fulltxt:=rawStr . "=" . result
            return result
        }
        ;10进制转为16进制,传入纯数字,不包含任何其它字符
        if  not RegExReplace((str:=trim(rawStr)),"\d+",""){
            result:=ak.tenToOther(str,16)
            fulltxt:=rawStr . "=0x" . result
            return "0x" . result
        }
        ;任意进制转换,tobase 0x100 2 十六进制转为二进制,tobase 1000 10 16 十进制转为16进制
        if  instr(rawStr,"tobase ")==1 and (str:=Trim(LTrim(rawStr,"tobase "))){
            result:=this.tobaseExpression(str)
            fulltxt:=rawStr . "=" . result
            return fulltxt
        }
        ;计算平均值
        if not (str:=Trim(LTrim(rawStr,"avg")))  or inStr(rawStr,"avg ")==1 {
            result:=this.avgExpression(str)
            fulltxt:= rawStr . (str?"":"[剪切板]") . result
            return fulltxt
        }
        ;计算总和
        if not (str:=Trim(LTrim(rawStr,"sum")))  or inStr(rawStr,"sum ")==1 {
            result:=this.avgExpression(str,0)
            fulltxt:= rawStr . (str?"":"[剪切板]") . result
            return fulltxt
        }
    }
    ;计算get表达
    static getExpression(str,&prefix)
    {
        getconfig:=ak.readFileToMap(this.getconfigPath)
        if RegExMatch(str,"^([\d.]+)",&outn)==1{ ;倍数取值
           mn:=outn[1] ;倍数
           if not (value:=ak.mapget(getconfig,"1" . strReplace(str,mn)))
              return
           regmod:="\[([\+\-\*/\d.^%\(\)]+)\]"
           while RegExMatch(value,regmod, &OutputVar){
                prefix:=1
                num :=ak.polish_notation( mn . "*" . "(" .  OutputVar[1]  . ")" )
                value :=strReplace(value,"[" . OutputVar[1] . "]", ak.get_bignumber(num,3,0),,,1)
           }
           return value
        }
        prefix:=0
        return ak.mapget(getconfig,str,1) or this.getEnvExpression(str) ;直接取值或者是取环境变量
    }
    ;计算getEnv表达式
    static getEnvExpression(key)
    {
        return ((s:=reg.getEnv(key,0))?s . "(系统)":"" ) . "`n" . ((u:=reg.getEnv(key))?u . "(用户)":"")
    }
    ;设置setEnv 表达式,user=0表示系统,默认用户
    ;设置path时 ,set path= 清空path,set -path="xx" 删除某个path,set path="xxx"增加一个path
    static setEnvExpression(str,user)
    {
      if index:=inStr(str:=Trim(str),"="){
         key:=RTrim(subStr(str,1,index-1))
         value:=LTrim(subStr(str,index+1))
         if not key and not value
            return "(失败)"
         if  value='""'{
            reg.delEnv(key,user)
            return not reg.getEnv(key,user)?"(删除成功)":"(删除失败)"
         }else if key="path"{
            reg.pathPush(value,user)
            return ak.arrHas(reg.pathArr(user),value)?"(成功)":"(失败)"
         }else if key="-path"{
            reg.pathPop(value,user)
            return not ak.arrHas(reg.pathArr(user),value)?"(成功)":"(失败)"
         }else{
            reg.setEnv(key,value,,user)
            return  reg.getEnv(key,user)?"(添加成功)":"(添加失败)"
         }
      }else{
         return "[失败]"
      }
    }
    ;计算平均值或者总和 flag:=1 平均值,flag:=0 总和 ,返回结果带有"="或者是"≈"
    static avgExpression(str,flag:=1)
    {
        str:= not str ? A_clipboard :str ;获取剪切板数据
        str:=RegExReplace(RegExReplace(trim(str),"^[\s\r\n]+"),"[\s\r\n]+$","") ;截取开头结尾的空格换行回车
        str:=RegExReplace(trim(str),"[\s\r\n]+","+",&rcount) ;缩减空格
        mathExp:="(" . str . ")" . (flag? ("/" . (rcount+1)):"")
        result:=this.mathExpression(mathExp)
        index:=inStr(result,"=") || inStr(result,"≈") ;获取结果
        return subStr(result,index)
    }
    ;进制转换,str原字符串,二进制:111100011 十进制:1024 十六进制:0x100 八进制o100
    ;fromdecimal:需要转换的数据,todecimal:转换后的数据
    static tobaseExpression(str)
    {
        args:=strSplit( RegExReplace(trim(str),"\s+"," ") ," ")
        if(args.length==2){
            tmpMap:=Map("2","(","8","o","16","0x")
            return ak.mapget(tmpMap,args[2]) . ak.tenToOther(this.calculateExpression(args[1],1),args[2]) . (args[2]=="2"?")":"")
        }else if (args.length==3){
            return ak.tenToOther(ak.otherToTen(args[1],args[2]),args[3])
        }
    }
    ;搜狗翻译 翻译的语种,kr韩国,ja日本,其它就是中英,其他-中互换
    static meanExpression(keyword,typeFlag:="url_ALL")
    {
        if not ak.ConnectedToInternet(){ ;互联网没有连接
             return
        }
        _map:=Map()
        _map.set("url_ALL",'https://fanyi.sogou.com/text?keyword={1}') ;任意语言转为中文,中文转英文
        _map.set("url_KO",'https://fanyi.sogou.com/text?keyword={1}&transfrom=auto&transto=ko&model=general&exchange=true') ;中韩互换
        _map.set("url_JA",'https://fanyi.sogou.com/text?keyword={1}&transfrom=auto&transto=ja&model=general&exchange=true') ;中日互换
        encode_url:=ak.urlEncode(Format(_map.get(typeFlag),keyword))
        static req := ComObject("WinHttp.WinHttpRequest.5.1")
        req.Open("get",encode_url,true) ;true 异步,false 同步(默认)
        req.setRequestHeader("User-Agent",this.userAgent) ;在open之后
        req.send()
        req.WaitForResponse()
        result:=req.ResponseText
        return ak.getInnerHtml(result,"trans-result",0)
    }
    ;计算数学表达式+,- ,x ,/ % ** 操作,支持括号,支持k(千),w(万),y(亿)
    static mathExpression(str)
    {
        ;计算数学表达式
        str2:=RegExReplace(str,"[abcdefghijlmnopqrstuvxzABCDEFGHIJLMNOPQRSTUVXZ]+","")
        if str!=str2
            return
        if(InStr(str, "+") or InStr(str, "-") or  InStr(str, "*") or InStr(str, "/")
            or InStr(str, "%")  or InStr(str, "**")or  InStr(str, "=") or InStr(str,"≈")or InStr(str, "^"))
        {
             str:=InStr(str, "=")>0 ? ak.getSuffix(str,"="):str ;使连续计算成为可能
             str:=InStr(str,"≈")>0 ? ak.getSuffix(str,"≈"):str ;连续计算约等于
             str:=RegExReplace(str,"\s+","")         ;缩紧字符串
             if inStr(str,"y") or inStr(str,"w") or inStr(str,"k")
                 char_flag:=1
             str2:=ak.set_bignumber(str)              ;处理字符y,w,k
             result:=ak.polish_notation(str2)         ;用逆波兰表达式计算值
             result:=ak.get_bignumber(result,3,char_flag??0)      ;保留三位小数
             fulltxt:=str . result                                ;result中有等号
             return fulltxt
        }
    }
    ;计算编码,默认编码,0表示解码
    static charcodeExpression(str,encode:=1)
    {
        if encode{
            result:=ak.encodeUtf8(str)
        }else{
            result:=ak.decodeUtf8(str)
        }
        return result
    }
    ;计算asc码值
    static ascOrChrExpression(str,sacb)
    {
       str2:=RegExReplace(str,"\s+"," ")  ;让空格变小
       Loop parse ,str2 ," "{
         result .= (" " . ak.getAscOrChr(Trim(A_LoopField),sacb))
       }
       return result
    }

}
;==========================================================================================================系统快捷键映射



;----------------------------------------------------------------------------------------------------------Reg工具类
;注册表操作工具
class reg
{
    ;用户环境变量位置
    static HCU:="HKEY_CURRENT_USER\Environment"
    ;系统环境变量位置
    static HLM:="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment"

    ;获取当前某个环境变量的值 ,默认是当前用户
    static getEnv(key,user:=1)
    {
        return  ak.mapget(this.getEnvMap(user),key,1)
    }
    ;获取当前所有环境变量 ,默认是当前用户
    static getEnvMap(user:=1){
        regpath:=user?this.HCU:this.HLM
        retMap:=Map()
        Loop Reg, regpath ,"KV"{
            retMap.set(A_LoopRegName,RegRead())
        }
        return retMap
    }
    ;删除环境变量,默认当前用户
     static delEnv(key,user:=1){
        regpath:=user?this.HCU:this.HLM
        RegDelete regpath ,key
    }
    ;设置环境变量,立即生效,默认是当前用户
    static setEnv(key,value,type:="REG_SZ",user:=1)
    {
        regpath:=user?this.HCU:this.HLM
        RegWrite value, type, regpath, key
    }
    ;添加一个键值对到path ,默认是当前用户
    static pathPush(key,user:=1){
        arr:=this.pathArr(user)
        if(arr and ak.arrHas(arr,key))
            return
        else
           arr.push(key)
        pathStr:=ak.joinArr(arr,";","","")
        this.setEnv("Path",pathStr,"REG_EXPAND_SZ",user)
    }
    ;在path中删除一个键值,默认是当前用户
    static pathPop(key,user:=1){
        paths:=ak.arrDelete(this.pathArr(user),key)
        pathStr:=ak.joinArr(paths,";","","")
        this.setEnv("Path",pathStr,"REG_EXPAND_SZ",user)
    }
    ;返回path集合array ,默认是当前用户
    static pathArr(user:=1){
       retarr:=[]
       pathstr:=Rtrim(this.path(user),";")
       loop parse ,pathstr,";"
           retarr.push(A_loopField)
       return retarr
    }
    ;返回一个path字符串,默认是当前用户
    static path(user:=1){
        return this.getEnv("Path",user)
    }
}
;----------------------------------------------------------------------------------------------------------Reg工具类
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ak工具类class
class ak
{
    static cpuid:=""
    ;Fucn 逆波兰表达式计算 + - x ÷ 幂(**/^) 模(%)  expression:数学表达式可以带括号
    ;参考:https://blog.csdn.net/assiduous_me/article/details/101981332
    static polish_notation(expression)
    {
        operator_list:=Map("+",0,"-",0,"*",0,"`/",0,"%",0,"^",0) ;注意list的haskey操作只是检测索引
        operatorlevel_map:=Map("(",0,"+","1","-",1,"*",2,"/","2","%",2,"^",3,")",4)
        operator_map:=Map("+","add","-","sub" ,"*","multi","/","divi","%","mod2","^","pow")
        expression:=strReplace(strReplace(RegExReplace(trim(expression),"\s+",""),"**","^") ,"(-","(0-")
        expression:=inStr(expression,"-(")==1?strReplace(this.insertStrAt(expression,this.mirrorSymbolIndex(expression,"(",")"),")"),"-(","(0-("):expression
        ;①.获取一个中缀表达式集合类似 100+2 -> ["100","+","2"]
        middlefix_list:=[],fix:=""
        Loop parse,expression{
            current_value:=A_LoopField
            if(operatorlevel_map.has(current_value))
            {
              tmp:=""!=fix?middlefix_list.push(fix):""
              middlefix_list.push(current_value)
              fix:=""
            }else fix:=fix . current_value
        }
       tmp2:=fix!=""?middlefix_list.push(fix):""
       if(middlefix_list[1]="-"){ ;处理开头为负数
           middlefix_list.insertAt(1,"(")
           middlefix_list.insertAt(2,"0")
           middlefix_list.insertAt(5,")")
       }
       ;②.转换为后缀表达式(逆波兰表达式)
        operator_stack:=[] ,suffix_list:=[],number_stack:=[]
        for index ,currentElmt in middlefix_list
        {
          if(operator_list.has(currentElmt))
          {
              while(operator_stack.length>0 && operatorlevel_map.get(operator_stack.get(operator_stack.Length))>=operatorlevel_map.get(currentElmt))
                 suffix_list.push(operator_stack.pop())
              operator_stack.push(currentElmt)
          }else if(currentElmt=="(")
             operator_stack.push("(")
          else if(currentElmt==")"){
             while(operator_stack.length>0 && operatorlevel_map.get(operator_stack.get(operator_stack.length))>operatorlevel_map.get("("))
                suffix_list.push(operator_stack.pop())
             if(operator_stack.length>0)
                 operator_stack.pop()
          }else
              suffix_list.push(currentElmt)
        }
        while(operator_stack.length>0)
            suffix_list.push(operator_stack.pop())
        ;③.计算表达式最终的值,规则数字入栈,操作符就出栈两个元素计算值并把结果入栈
        for key,opertor_or_number in suffix_list{
           if(operator_list.has(opertor_or_number)){
                number2:=number_stack.pop(),number1:=number_stack.pop()
                tmpObj:={add:number1+number2,sub:number1-number2,multi:number1*number2,pow:number1**number2}
                T1:=opertor_or_number=="/"?(tmpObj.divi:=number1/number2):""       ;除法容易引发除0异常
                T2:=opertor_or_number=="%"?(tmpObj.mod2:=mod(number1,number2)):""  ;取模容易引发除0异常
                number_stack.push(tmpObj.%operator_map.get(opertor_or_number)%)
           }else
                number_stack.push(opertor_or_number)
        }
        return number_stack.pop()
    }
   ;Func 计算对称符号所在位置str:原字符串,firstIndex:左边符号所在位置,symbol:右边符号 返回右边符号在原字符串中索引 "-((10000+500)-500)/2" 返回18
   static mirrorSymbolIndex(str,Lsymbol,Rsymbol)
   {
       flag:=false ,list:=[]
       Loop Parse  ,str {
          if(Lsymbol==(sub:=subStr(Str,A_index,1))){
            list.push(sub)
            flag:=true
          }
          R:=Rsymbol==subStr(Str,A_index,1)?list.pop():""
          if(list.length==0 and flag)
            return A_index
       }
       return 0
   }
   ;Func 在字符串种插入片段 ,str:原字符串,index:插入位置(位置之后插入),frag:插入片段
   static insertStrAt(str,index,frag)
   {
       return subStr(str,1,index) . frag . subStr(str,index+1)
   }
    ;Func 处理算式中含有k,w,y的,formula 表达式
    static set_bignumber(formula)
    {
      formula:=RegExReplace(formula,"(\d*\.*\d*)k|K","($1*1000)")      ;处理1k
      formula:=RegExReplace(formula,"(\d*\.*\d*)w|W","($1*10000)")     ;处理 1w
      formula:=RegExReplace(formula,"(\d*\.*\d*)y|Y","($1*100000000)") ;处理1亿
      return formula
    }
    ;func 作用:处理大的数字,
    ;参数:bigNumber数字类型的大数字,char_flag:0,1(是否带k,w,y), scale 数字类型保留几位小数
    ;返回:返回字符串
    ;msgBox % Round(100,2)
    static get_bignumber(bigNumber,scale:=0,char_flag:=1)
    {
        ;判断有几位小数
        index:=InStr(bigNumber,".")
        left :=index=0?strLen(bigNumber):InStr(bigNumber,".")-1
        unit:="",prefix:="="
        if char_flag{
            if(left==4) ;单位K
            {
                result:=Round(bigNumber/1000,scale)
                prefix:=(result==bigNumber/1000)?"=":"≈"
                unit:="k"
            }else if(left>4 && left <9) ;单位w
            {
                result:=Round(bigNumber/10000,scale)
                prefix:=(result==bigNumber/10000)?"=":"≈"
                unit:="w"
            }else if(left>=9) ;单位亿
            {
                result:=Round(bigNumber/100000000,scale)
                prefix:=(result==bigNumber/100000000)?"=":"≈"
                unit:="亿"
            }else{ ;小于1k
                result:=Round(bigNumber,scale)
                prefix:=(result==bigNumber)?"=":"≈"
            }
        }else{ ;正常表示方式
            result:=Round(bigNumber,scale)
            prefix:=(result==bigNumber)?"=":"≈"
        }
        result:=RegExReplace(result,"\.0+$","") ;去掉 2.000这样式的
        if(InStr(result,".")>0)
            result:=RegExReplace(result,"0+$","")
        return prefix . result . unit
    }

   ;Func获取cpuid,需要在脚本开始阶段就执行
   static getCpuid()
   {
       query := "SELECT * FROM Win32_Processor"
       wmi := ComObjGet("winmgmts:\\.\root\cimv2")
       col := wmi.ExecQuery(query)
       for obj in col {
           return this.cpuid:=obj.ProcessorID
       }
       return ""
   }
   ;Func 生成32位UUID来源于guid
   static uuid()
   {
       shellobj := ComObject("Scriptlet.TypeLib")
       return RegExReplace(shellobj.GUID,"({|}|-)","") ;去掉花括号和-
   }

   ;Func  十进制转换为任意进制,n:10000 ,也可传入16进制0x
    static tenToOther(n,b)
    {
          return (n < b ? "" : this.tenToOther(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55))
    }
    ;Func 计算任意进制的十进制,str:101010(二进制) 或者其他进制,不能带o或者0x前缀
    static otherToTen(n,b)
    {
         MI:=strLen(n) ;幂
         Loop  parse, n
             result .= A_Loopfield  "*" b "^" MI-A_Index "+"
         return this.polish_notation(rtrim(result,"+"))
    }
    ;Func 帮助map获取值,优化原生map报错问题,ignoreCase是否忽略大小写
    static mapget(map1,key,ignoreCase:=0)
    {
        try{
          if ignoreCase{
            for k ,v in map1 {
                if k=key
                    return v
            }
          }
          return map1.get(key)
        }catch as e{
           return ""
        }
    }
    ;获取并保存数组中的值所在位置0
    static arrHas(arr2,value)
    {
        for item in arr2{
            if item==value
                return A_index
        }
        return 0
    }
   ;Func连接数组Array ,arr:数组 ,separator:分隔符,L: 左边添加符号 R:右边添加符号
   static joinArr(arr  ,separator:=","  ,L:="["  ,R:="]")
   {
      for i in arr{
         L.=(this.joinObj(i) . separator)
      }
      return Rtrim(L,",")  . R
   }
    ;删除数组中的值
    static arrDelete(arr2,value)
    {
        arr3:=[]
        for item in arr2{
            if item!=value{
                arr3.push(item)
            }
        }
        return arr3
    }
   ;Fucn读取配置文件到map返回一个Map,filePath:文件所在路径 ,注释符号"#"
   static readFileToMap(filePath,separator:="=")
   {
        configs:=Map()
        for line in this.readFileToList(filePath){
          configs[trim(subStr(line,1,inStr(line,separator)-1))]:=trim(subStr(line,inStr(line,separator)+1))
        }
        return configs
   }
   ;Fucn读取配置文件到list返回一个Array,filePath:文件所在路径 ,注释符号"#"
   static readFileToList(filePath)
   {
        lines:=[]
        Loop read, filePath
           tmp:=(line:=trim(A_LoopReadLine)) and (not (inStr(line,"#")==1))?lines.push(line):unset
        return lines
   }
   ;Func 利用js对url编码,由于采用js方式加密所以字符串中的“ " ”需要处理一下
   static urlEncode(url)
   {
       static htmlfile := ComObject('htmlfile')
       htmlfile.write('<meta http-equiv="X-UA-Compatible" content="IE=edge">')
       return  htmlfile.parentWindow.encodeURI(url) ;还有一个方法encodeURIComponent会连http都编码
   }
   ;func 获取一个字符asc码值或是chr值
   static getAscOrChr(item,ascb:=1)
   {
        _map:=Map()
        _map.set("0","{NUL}")   ;空 ^@
        _map.set("1","{SOH}")   ;头标开始 ^A
        _map.set("2","{STX}")   ;正文开始 ^B
        _map.set("4","{EOT}")   ;正文结束 ^C
        _map.set("5","{ENQ}")   ;查询 ^E
        _map.set("6","{ACK}")   ;确认 ^F
        _map.set("7","{BEL}")   ;震铃 ^G
        _map.set("8","{BS}")    ;退格 ^H
        _map.set("9","{TAB}")   ;水平制表符
        _map.set("10","{LF}")   ;换行 ^J
        _map.set("11","{VT}")   ;竖直制表符 ^K
        _map.set("12","{FF}")   ;换页^L
        _map.set("13","{回车}") ;回车
        _map.set("14","{SO}")   ;移出 ^N
        _map.set("15","{SI}")   ;移入 ^O
        _map.set("16","{DLE}")  ;数据链路转意 ^P
        _map.set("17","{DC1}")  ;设备控制符1 ^Q
        _map.set("18","{DC2}")  ;设备控制符2 ^R
        _map.set("19","{DC3}")  ;设备控制符3 ^S
        _map.set("20","{DC4}")  ;设备控制符4 ^T
        _map.set("21","{NAK}")  ;反确认 ^U
        _map.set("22","{SYN}")  ;同步空闲 ^V
        _map.set("23","{ETB}")  ;传输块结束 ^W
        _map.set("24","{CAN}")  ;取消^X
        _map.set("25","{EM}")   ;媒体结束 ^Y
        _map.set("26","{SUB}")  ;替换 ^Z
        _map.set("27","{ESC}")  ;转意 ^[
        _map.set("28","{FS}")   ;文件分隔符 ^\
        _map.set("29","{GS}")   ;组分隔符 ^]
        _map.set("30","{RS}")   ;记录分隔符 ^6
        _map.set("31","{US}")   ;单元分隔符 ^-
        _map.set("32","{空格}") ;空格
        _map.set("127","{^BASCK SPACE}") ;退格
        ;添加常规字符
        Loop  94
           _map.set(String(A_index+32),chr(A_index+32))
        return ascb?(this.maprget(_map,item) || Ord(item)):(this.mapget(_map,item) || chr(item))
   }
   ;通过value值来寻找key ,一般是一个key映射一个数组的时候,取数组中一个值来找key
   static maprget(mmap,value)
   {
      for k ,v in mmap{
         if (type(v)=="Array" and this.arrhas(v,value) )or(v==value){
            return k
          }
      }
      return
   }
   ;Func对中文编码进行unicode编码
   static encodeUtf8(str)
   {
        resultStr:=""
        Loop  Parse, str {
           resultStr:=resultStr . "\u" .  String(Ord(A_LoopField)>0x100 ? Format("{:04X}", Ord(A_LoopField) ):A_LoopField)
        }
        return resultStr
   }
   ;Func 对中英文unicode进行解码
   static decodeUtf8(str)
   {
       ret:="",aStr:=subStr(str,1,inStr(str,"\u")-1),bStr:=subStr(str,inStr(str,"\u")),arr:=strSplit(bStr,"\u")
       for k in arr{
            ret:=k?ret . chr(Abs("0x" . subStr(k,1,4))) . subStr(k,5):""
       }
       return aStr . ret
    }
   ;判断是否连接互联网
   static ConnectedToInternet(flag:=0x40) {
      Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
   }
    ;Func 获取某个指定id的元素内容,htmlcontent:整个html页面,id:标签里面的id,htmlflag:如果有html就返回html
    ;htmlflag:=0就是只取标签中的文字,不管有多少个标签。默认该值返回标签
    static getInnerHtml(htmlcontent,id,htmlflag:=1)
    {
         js:= ComObject("htmlfile")
         js.write(htmlcontent)
         document :=js.parentWindow.document
         element:=document.getElementByID(id)
         if element{
            return htmlflag?element.innerHtml:element.innerText
         }
    }
}
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ak工具类class

4、总结

各个具体功能、用法、代码,参考之前windows超级运行框-表达式系列1-11文章、

如果不需要全部功能可以通过之前文章中的代码自己组装需要的功能,也可以直接在代码中注释掉if判断语句,很多功能使用的类和函数名都一样、

各位大佬觉得还有什么功能需要补充,欢迎评论区讨论、

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

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

sqlite数据库快速查看器

2023-12-5 18:01:18

应用

windows超级运行框-表达式计算(11)—avg /sum 平均求和

2023-12-9 15:06:22

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