查看完整视频
评论可见

您需要在视频最下面评论,方可查看完整视频

积分观看

您支付积分,方可查看完整视频

{{user.role.value}}
付费视频

您支付费用,方可查看完整视频

¥{{user.role.value}}
专属视频

只允许以下等级用户查看该视频

升级
会员专享

FindText ()7.3- 屏幕抓字生成字库工具与找字函数——FeiYue

这是一个简单的辅助工具,用于生成屏幕文字或图像的单行字符串
字库。配合强大的“查找文字()”函数,在脚本中非常好用!

在编写自动化脚本时,如果采用先抓图,再制作小图,再用
ImageSearch,操作太复杂,且不能仅使用脚本,还要打包图片。

如果仅仅采用颜色判断,显而易见太简陋了,不能精确判断
当前的屏幕文字(或图像),及精确定位。

所以这个工具就应运而生了,生成“0_”字符组成的形象化图像描述,
并且自动生成“查找文字()”的调用代码,复制到自己的脚本中就行了。

这可是我的独门秘技哦(^_^)!

;/*
;===========================================
;  FindText - 屏幕抓字生成字库工具与找字函数
;
;  脚本作者 :  FeiYue
;  最新版本 :  7.3
;  更新时间 :  2019-12-21
;
;  用法:
;  1. 将本脚本保存为“FindText.ahk”并复制到AHK程序的Lib子目录中
;  2. 抓图并生成调用FindText()的代码
;     2.1 直接点击“抓图”按钮
;     2.2 先设定截屏热键,使用热键截屏,再点击“截屏抓图”按钮
;  3. 测试一下调用的代码是否成功:直接点击“测试”按钮
;  4. 复制调用的代码到自己的脚本中
;     4.1 直接点击“复制”按钮,然后粘贴到自己的脚本中
;     4.2 取消“附加FindText()函数”的选框,然后点击“复制”按钮,
;         然后粘贴到自己的脚本中,然后在自己的脚本开头加上一行:
;         #Include <FindText>  ; Lib目录中必须有FindText.ahk
;
;===========================================
;  函数的参数和返回值:
;
;  返回变量 := FindText(
;      X1 --> 查找范围的左上角X坐标
;    , Y1 --> 查找范围的左上角Y坐标
;    , X2 --> 查找范围的右下角X坐标
;    , Y2 --> 查找范围的右下角Y坐标
;    , err1 --> 文字的黑点容错百分率(0.1=10%)
;    , err0 --> 背景的白点容错百分率(0.1=10%)
;    , Text --> 由工具生成的查找图像的数据,可以一次查找多个,用“|”分隔
;    , ScreenShot --> 是否截屏,为0则使用上一次的截屏数据
;    , FindAll -->    是否搜索所有位置,为0则找到一个位置就返回
;    , JoinText -->   是否组合图像,为1则多个数据组合为一幅图来查找
;    , offsetX --> 组合图像的每个字和前一个字的最大横向间隔
;    , offsetY --> 组合图像的每个字和第一个字的最大高低间隔
;  )
;  返回变量 --> 如果没找到结果会返回0。否则返回一个二级数组,
;      第一级是每个结果对象,第二级是结果对象的具体信息数组:
;      { 1:左上角X, 2:左上角Y, 3:图像宽度W, 4:图像高度H
;        , x:中心点X, y:中心点Y, id:图像识别文本 }
;
;  坐标都是相对于屏幕,颜色使用RGB格式,组合查找必须使用统一的颜色模式
;===========================================
;*/

if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
  ft_Gui("Show")

ft_Gui(cmd)
{
  static
  if (cmd="Show")
  {
    Gui, ft_Main:+LastFoundExist
    IfWinExist
    {
      Gui, ft_Main:Show, Center
      return
    }
    if (!ft_FuncBind1)
      ft_FuncBind1:=Func("ft_Gui").Bind("Show")
    #NoEnv
    Menu, Tray, Add
    Menu, Tray, Add, 查找文字工具, %ft_FuncBind1%
    if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
    {
      Menu, Tray, Default, 查找文字工具
      Menu, Tray, Click, 1
      Menu, Tray, Icon, Shell32.dll, 23
    }
    ft_BatchLines:=A_BatchLines
    ft_IsCritical:=A_IsCritical
    Critical
    ww:=35, hh:=12, WindowColor:="0xDDEEFF"
    ft_Gui("MakeCaptureWindow")
    ft_Gui("MakeSubPicWindow")
    ft_Gui("MakeMainWindow")
    OnMessage(0x100, Func("ft_EditEvents1"))  ; WM_KEYDOWN
    OnMessage(0x201, Func("ft_EditEvents2"))  ; WM_LBUTTONDOWN
    OnMessage(0x200, Func("ft_ShowToolTip"))  ; WM_MOUSEMOVE
    Gui, ft_Main:Show, Center
    GuiControl, ft_Main:Focus, scr
    Critical, %ft_IsCritical%
    SetBatchLines, %ft_BatchLines%
    return
    ;-------------------
    ft_Run:
    Critical
    ft_Gui(Trim(A_GuiControl))
    return
  }
  if (cmd="MakeCaptureWindow")
  {
    Gui, ft_Capture:New
    Gui, +AlwaysOnTop -DPIScale
    Gui, Margin, 15, 15
    Gui, Color, %WindowColor%
    Gui, Font, s12, Verdana
    Gui, Add, Text, xm w855 h315 +HwndhPic
    Gui, Add, Slider, ym h315 vMySlider2 gft_Run
      +Center Page20 Line20 NoTicks AltSubmit +Vertical
    Gui, Add, Slider, xm w855 vMySlider1 gft_Run
      +Center Page20 Line20 NoTicks AltSubmit
    GuiControlGet, Pic, Pos, %hPic%
    PicW:=Round(PicW), PicH:=Round(PicH), MySlider1:=MySlider2:=0
    Gui, Add, Button, xm+125 w50 vRepU  gft_Run, -上
    Gui, Add, Button, x+0    wp  vCutU  gft_Run, 上
    Gui, Add, Button, x+0    wp  vCutU3 gft_Run, 上3
    ;--------------
    Gui, Add, Text,   x+50 yp+3 Section, 灰度
    Gui, Add, Edit,   x+3 yp-3 w60 vSelGray ReadOnly
    Gui, Add, Text,   x+15 ys, 颜色
    Gui, Add, Edit,   x+3 yp-3 w120 vSelColor ReadOnly
    Gui, Add, Text,   x+15 ys, 红
    Gui, Add, Edit,   x+3 yp-3 w60 vSelR ReadOnly
    Gui, Add, Text,   x+5 ys, 绿
    Gui, Add, Edit,   x+3 yp-3 w60 vSelG ReadOnly
    Gui, Add, Text,   x+5 ys, 蓝
    Gui, Add, Edit,   x+3 yp-3 w60 vSelB ReadOnly
    ;--------------
    Gui, Add, Button, xm     w50 vRepL  gft_Run, -左
    Gui, Add, Button, x+0    wp  vCutL  gft_Run, 左
    Gui, Add, Button, x+0    wp  vCutL3 gft_Run, 左3
    Gui, Add, Button, x+15   w70 vAuto  gft_Run, 自动
    Gui, Add, Button, x+15   w50 vRepR  gft_Run, -右
    Gui, Add, Button, x+0    wp  vCutR  gft_Run, 右
    Gui, Add, Button, x+0    wp  vCutR3 gft_Run Section, 右3
    Gui, Add, Button, xm+125 w50 vRepD  gft_Run, -下
    Gui, Add, Button, x+0    wp  vCutD  gft_Run, 下
    Gui, Add, Button, x+0    wp  vCutD3 gft_Run, 下3
    ;--------------
    Gui, Add, Tab3,   ys-8 -Wrap, 灰度阈值|灰度差值|颜色相似|颜色位置|颜色分量
    Gui, Tab, 1
    Gui, Add, Text,   x+15 y+15, 灰度阈值
    Gui, Add, Edit,   x+15 w100 vThreshold
    Gui, Add, Button, x+15 yp-3 vGray2Two gft_Run, 灰度阈值二值化
    Gui, Tab, 2
    Gui, Add, Text,   x+15 y+15, 灰度差值
    Gui, Add, Edit,   x+15 w100 vGrayDiff, 50
    Gui, Add, Button, x+15 yp-3 vGrayDiff2Two gft_Run, 灰度差值二值化
    Gui, Tab, 3
    Gui, Add, Text,   x+15 y+15, 相似度 0
    Gui, Add, Slider, x+0 w100 vSimilar1 gft_Run
      +Center Page1 NoTicks ToolTip, 100
    Gui, Add, Text,   x+0, 100
    Gui, Add, Button, x+15 yp-3 vColor2Two gft_Run, 颜色相似二值化
    Gui, Tab, 4
    Gui, Add, Text,   x+15 y+15, 相似度 0
    Gui, Add, Slider, x+0 w100 vSimilar2 gft_Run
      +Center Page1 NoTicks ToolTip, 100
    Gui, Add, Text,   x+0, 100
    Gui, Add, Button, x+15 yp-3 vColorPos2Two gft_Run, 颜色位置二值化
    Gui, Tab, 5
    Gui, Add, Text,   x+10 y+15, 红
    Gui, Add, Edit,   x+2 w70 vDiffR Limit3
    Gui, Add, UpDown, vdR Range0-255
    Gui, Add, Text,   x+5, 绿
    Gui, Add, Edit,   x+2 w70 vDiffG Limit3
    Gui, Add, UpDown, vdG Range0-255
    Gui, Add, Text,   x+5, 蓝
    Gui, Add, Edit,   x+2 w70 vDiffB Limit3
    Gui, Add, UpDown, vdB Range0-255
    Gui, Add, Button, x+5 yp-3 vColorDiff2Two gft_Run, 颜色分量二值化
    Gui, Tab
    ;--------------
    Gui, Add, Button, xm vReset gft_Run, 重读
    Gui, Add, Checkbox, x+15 yp+5 vModify gft_Run, 修改
    Gui, Add, Text,   x+30, 识别文字
    Gui, Add, Edit,   x+5 yp-2 w150 vComment
    Gui, Add, Button, x+30 yp-3 vSplitAdd gft_Run, 分割添加
    Gui, Add, Button, x+10 vAllAdd gft_Run, 整体添加
    Gui, Add, Button, x+10 w80 vButtonOK gft_Run, 确定
    Gui, Add, Button, x+10 wp vClose gCancel, 关闭
    Gui, Add, Button, xm   vBind1 gft_Run, 绑定窗口
    Gui, Add, Button, x+15 vBind2 gft_Run, 绑定窗口+
    Gui, Show, Hide, 图像二值化及分割
    return
  }
  if (cmd="MakeSubPicWindow")
  {
    Gui, ft_SubPic:New
    Gui, +AlwaysOnTop -Caption +ToolWindow -DPIScale +Parent%hPic%
    Gui, Margin, 0, 0
    Gui, Color, %WindowColor%
    Gui, -Theme
    nW:=2*ww+1, nH:=2*hh+1, C_:=[], w:=11
    Loop, % nW*(nH+1)
    {
      i:=A_Index, j:=i=1 ? "x0 y0" : Mod(i,nW)=1 ? "x0 y+1" : "x+1"
      j.=i>nW*nH ? " cRed BackgroundFFFFAA" : ""
      Gui, Add, Progress, w%w% h%w% %j% +Hwndid
      Control, ExStyle, -0x20000,, ahk_id %id%
      C_[i]:=id
    }
    Gui, +Theme
    GuiControlGet, SubPic, Pos, %id%
    SubPicW:=Round(SubPicX+SubPicW), SubPicH:=Round(SubPicY+SubPicH)
    Gui, Show, NA x0 y0 w%SubPicW% h%SubPicH%, SubPic
    i:=(SubPicW>PicW), j:=(SubPicH>PicH)
    Gui, ft_Capture:Default
    GuiControl, Enable%i%, MySlider1
    GuiControl, Enable%j%, MySlider2
    GuiControl,, MySlider1, % MySlider1:=0
    GuiControl,, MySlider2, % MySlider2:=0
    return
  }
  if (cmd="MakeMainWindow")
  {
    Gui, ft_Main:New
    Gui, +AlwaysOnTop -DPIScale
    Gui, Margin, 15, 15
    Gui, Color, %WindowColor%
    Gui, Font, s12 cBlack, Verdana
    Gui, Add, GroupBox, xm y10 w250 h45 vMyGroup
    Gui, Add, Text, xp+10 yp+18 Section, % "宽度: "
    Gui, Add, Text, x+0 w50, %ww%
    Gui, Add, UpDown, vMyww Range1-50, %ww%
    Gui, Add, Text, x+15 ys, % "高度: "
    Gui, Add, Text, x+0 w50, %hh%
    Gui, Add, UpDown, vMyhh Range1-40, %hh%
    GuiControlGet, p, Pos, Myhh
    GuiControl, Move, MyGroup, % "w" px+pw " h" py+ph
    Gui, Add, Checkbox, x+30 ys Checked vAddFunc, 附加 FindText()
    GuiControlGet, p, Pos, AddFunc
    w:=720+15-(px+pw)-15
    Gui, Add, Button, x+15 ys-8 w%w% vTestClip gft_Run, 复制后测试
    Gui, Add, Text, xm, 截屏热键
    Gui, Add, Edit, x+5 w150 vNowHotkey ReadOnly
    Gui, Add, Hotkey, x+5 w180 vSetHotkey1
    Gui, Add, DDL, x+5 w150 vSetHotkey2
      , % "||F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|MButton"
      . "|ScrollLock|CapsLock|Ins|Esc|BS|Del|Tab|Home|End|PgUp|PgDn"
      . "|NumpadDot|NumpadSub|NumpadAdd|NumpadDiv|NumpadMult"
    GuiControlGet, p, Pos, SetHotkey2
    w:=720+15-(px+pw)-5
    Gui, Add, Button, x+5 yp-3 w%w% vApply gft_Run, 应用
    Gui, Font, s6 bold, Verdana
    Gui, Add, Edit, xm w720 r25 vMyPic -Wrap
    Gui, Font, s12 norm, Verdana
    Gui, Add, Button, w180 vCapture gft_Run, 抓图
    Gui, Add, Button, x+0 wp vCaptureS gft_Run, 截屏抓图
    Gui, Add, Button, x+0 wp vTest gft_Run, 测试
    Gui, Add, Button, x+0 wp vCopy gft_Run Section, 复制
    Gui, Font, s12 cBlue, Verdana
    Gui, Add, Edit, xm w720 h350 vscr Hwndhscr -Wrap HScroll
    Gui, Show, Hide, 抓图生成字库及找字代码
    return
  }
  if (cmd="Capture") or (cmd="CaptureS")
  {
    Gui, ft_Main:Default
    Gui, +LastFound
    WinMinimize
    Gui, Hide
    ShowScreenShot:=(cmd="CaptureS")
    if (ShowScreenShot)
      ft_ShowScreenShot(1)
    ;----------------------
    Gui, ft_Mini:New
    Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
    Gui, Color, Red
    d:=2, w:=nW+2*d, h:=nH+2*d, i:=w-d, j:=h-d
    Gui, Show, Hide w%w% h%h%
    s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
    s=%s%  %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
    WinSet, Region, %s%
    ;------------------------------
    Hotkey, $*RButton, ft_RButton_Off, On
    lls:=A_ListLines=0 ? "Off" : "On"
    ListLines, Off
    CoordMode, Mouse
    KeyWait, RButton
    KeyWait, Ctrl
    oldx:=oldy:=""
    Loop
    {
      Sleep, 50
      MouseGetPos, x, y, Bind_ID
      if (oldx=x and oldy=y)
        Continue
      oldx:=x, oldy:=y
      ;---------------
      Gui, Show, % "NA x" (x-w//2) " y" (y-h//2)
      ToolTip, % "鼠标位置 : " x "," y
        . "`n先点击右键一次确定选框"
        . "`n再移开鼠标避免鼠标影响"
        . "`n再点击右键一次完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    px:=x, py:=y, oldx:=oldy:=""
    Loop
    {
      Sleep, 50
      MouseGetPos, x, y
      if (oldx=x and oldy=y)
        Continue
      oldx:=x, oldy:=y
      ;---------------
      ToolTip, % "选框位置 : " px "," py
        . "`n先点击右键一次确定选框"
        . "`n再移开鼠标避免鼠标影响"
        . "`n再点击右键一次完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    ToolTip
    ListLines, %lls%
    Gui, Destroy
    WinWaitClose,,, 10
    cors:=ft_getc(px,py,ww,hh,!ShowScreenShot)
    Hotkey, $*RButton, ft_RButton_Off, Off
    if (ShowScreenShot)
      ft_ShowScreenShot(0)
    ;--------------------------------
    Gui, ft_Capture:Default
    k:=nW*nH+1
    Loop, % nW
      GuiControl,, % C_[k++], 0
    Loop, 6
      GuiControl,, Edit%A_Index%
    GuiControl,, Modify, % Modify:=0
    GuiControl,, GrayDiff, 50
    GuiControl, Focus, Gray2Two
    GuiControl, +Default, Gray2Two
    ft_Gui("Reset")
    Gui, Show, Center
    Event:=Result:=""
    DetectHiddenWindows, Off
    Gui, +LastFound
    Critical, Off
    WinWaitClose, % "ahk_id " WinExist()
    Gui, ft_Main:Default
    ;--------------------------------
    if (cors.bind!="")
    {
      WinGetTitle, tt, ahk_id %Bind_ID%
      WinGetClass, tc, ahk_id %Bind_ID%
      tt:=Trim(SubStr(tt,1,30) (tc ? " ahk_class " tc:""))
      tt:=StrReplace(RegExReplace(tt,"[;``]","``$0"),"""","""""")
      Result:="`nSetTitleMatchMode, 2`nid:=WinExist(""" tt """)"
        . "`nBindWindow(id" (cors.bind ? ",1":"")
        . ")  `; 解绑窗口使用 Bindwindow(0)`n`n" Result
    }
    if (Event="ButtonOK")
    {
      if (!A_IsCompiled)
      {
        FileRead, s, %A_LineFile%
        s:=SubStr(s, s~="i)\n[;=]+ Copy The")
      }
      else s:=""
      GuiControl,, scr, % Result "`n" s
      GuiControl,, MyPic, % Trim(ASCII(Result),"`n")
      Result:=s:=""
    }
    else if (Event="SplitAdd") or (Event="AllAdd")
    {
      GuiControlGet, s,, scr
      i:=j:=0, r:="\|<[^>\n]*>[^$\n]+\$\d+\.[\w+/]+"
      While j:=RegExMatch(s,r,"",j+1)
        i:=InStr(s,"`n",0,j)
      GuiControl,, scr, % SubStr(s,1,i-1) . Result . SubStr(s,i+1)
      GuiControl,, MyPic, % Trim(ASCII(Result),"`n")
      Result:=s:=""
    }
    ;----------------------
    Gui, Show
    GuiControl, Focus, scr
    ft_RButton_Off:
    return
  }
  if (cmd="Bind1") or (cmd="Bind2")
  {
    BindWindow(Bind_ID, (cmd="Bind2"))
    Hotkey, $*RButton, ft_RButton_Off, On
    lls:=A_ListLines=0 ? "Off" : "On"
    ListLines, Off
    CoordMode, Mouse
    KeyWait, RButton
    KeyWait, Ctrl
    oldx:=oldy:=""
    Loop
    {
      Sleep, 50
      MouseGetPos, x, y
      if (oldx=x and oldy=y)
        Continue
      oldx:=x, oldy:=y
      ;---------------
      cors:=ft_getc(px:=x,py:=y,ww,hh)
      ft_Gui("Reset")
      ToolTip, % "鼠标位置 : " x "," y
        . "`n穿透显示绑定窗口"
        . "`n点击右键完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    ToolTip
    ListLines, %lls%
    Hotkey, $*RButton, ft_RButton_Off, Off
    BindWindow(0), cors.bind:=(cmd="Bind2")
    return
  }
  if (cmd="Test") or (cmd="TestClip")
  {
    Critical, Off
    Gui, ft_Main:Default
    Gui, +LastFound
    WinMinimize
    Gui, Hide
    DetectHiddenWindows, Off
    WinWaitClose, % "ahk_id " WinExist()
    Sleep, 100
    ;----------------------
    if (cmd="Test")
      GuiControlGet, s,, scr
    else
      s:=Clipboard
    if (!A_IsCompiled) and InStr(s,"MCode(") and (cmd="Test")
    {
      s:="`n#NoEnv`nMenu, Tray, Click, 1`n"
        . "Gui, ft_ok_:Show, Hide, ft_ok_`n"
        . s "`nExitApp`n"
      ft_Exec(s)
      DetectHiddenWindows, On
      WinWait, ft_ok_ ahk_class AutoHotkeyGUI,, 3
      if (!ErrorLevel)
        WinWaitClose,,, 30
    }
    else
    {
      Gui, +OwnDialogs
      t:=A_TickCount, n:=150000
      , RegExMatch(s,"\|<[^>\n]*>[^$\n]+\$\d+\.[\w+/]+",v)
      , ok:=FindText(-n, -n, n, n, 0, 0, v)
      , X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
      MsgBox, 4096, 提示, % "找到:`t" Round(ok.MaxIndex()) "`n`n"
        . "时间:`t" (A_TickCount-t) " 毫秒`n`n"
        . "位置:`t" X ", " Y "`n`n"
        . "结果:`t" (ok ? "成功 ! " Comment : "失败 !"), 3
      for i,v in ok
        if (i<=2)
          MouseTip(ok[i].x, ok[i].y)
      ok:=""
    }
    ;----------------------
    Gui, Show
    GuiControl, Focus, scr
    return
  }
  if (cmd="Copy")
  {
    Gui, ft_Main:Default
    ControlGet, s, Selected,,, ahk_id %hscr%
    if (s="")
    {
      GuiControlGet, s,, scr
      GuiControlGet, r,, AddFunc
      if (r != 1)
        s:=RegExReplace(s,"\n\K[\s;=]+ Copy The[\s\S]*")
    }
    Clipboard:=RegExReplace(s,"\R","`r`n")
    ;----------------------
    Gui, Hide
    Sleep, 100
    Gui, Show
    GuiControl, Focus, scr
    return
  }
  if (cmd="MySlider1") or (cmd="MySlider2")
  {
    x:=SubPicW>PicW ? -(SubPicW-PicW)*MySlider1//100 : 0
    y:=SubPicH>PicH ? -(SubPicH-PicH)*MySlider2//100 : 0
    Gui, ft_SubPic:Show, NA x%x% y%y%
    return
  }
  if (cmd="Reset")
  {
    if !IsObject(ascii)
      ascii:=[], gray:=[], show:=[]
    CutLeft:=CutRight:=CutUp:=CutDown:=k:=0, bg:=""
    Loop, % nW*nH
    {
      show[++k]:=1, c:=cors[k]
      gray[k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
      ft_Gui("SetColor")
    }
    Loop, % cors.CutLeft
      ft_Gui("CutL")
    Loop, % cors.CutRight
      ft_Gui("CutR")
    Loop, % cors.CutUp
      ft_Gui("CutU")
    Loop, % cors.CutDown
      ft_Gui("CutD")
    return
  }
  if (cmd="SetColor")
  {
    c:=c="Black" ? 0x000000 : c="White" ? 0xFFFFFF
      : ((c&0xFF)<<16)|(c&0xFF00)|((c&0xFF0000)>>16)
    SendMessage, 0x2001, 0, c,, % "ahk_id " . C_[k]
    return
  }
  if (cmd="RepColor")
  {
    show[k]:=1, c:=(bg="" ? cors[k] : ascii[k]
      ? "Black":"White"), ft_Gui("SetColor")
    return
  }
  if (cmd="CutColor")
  {
    show[k]:=0, c:=WindowColor, ft_Gui("SetColor")
    return
  }
  if (cmd="RepL")
  {
    if (CutLeft<=cors.CutLeft)
    or (bg!="" and InStr(color,"**")
    and CutLeft=cors.CutLeft+1)
      return
    k:=CutLeft-nW, CutLeft--
    Loop, %nH%
      k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
        ? ft_Gui("RepColor") : "")
    return
  }
  if (cmd="CutL")
  {
    if (CutLeft+CutRight>=nW)
      return
    CutLeft++, k:=CutLeft-nW
    Loop, %nH%
      k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
        ? ft_Gui("CutColor") : "")
    return
  }
  if (cmd="CutL3")
  {
    Loop, 3
      ft_Gui("CutL")
    return
  }
  if (cmd="RepR")
  {
    if (CutRight<=cors.CutRight)
    or (bg!="" and InStr(color,"**")
    and CutRight=cors.CutRight+1)
      return
    k:=1-CutRight, CutRight--
    Loop, %nH%
      k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
        ? ft_Gui("RepColor") : "")
    return
  }
  if (cmd="CutR")
  {
    if (CutLeft+CutRight>=nW)
      return
    CutRight++, k:=1-CutRight
    Loop, %nH%
      k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
        ? ft_Gui("CutColor") : "")
    return
  }
  if (cmd="CutR3")
  {
    Loop, 3
      ft_Gui("CutR")
    return
  }
  if (cmd="RepU")
  {
    if (CutUp<=cors.CutUp)
    or (bg!="" and InStr(color,"**")
    and CutUp=cors.CutUp+1)
      return
    k:=(CutUp-1)*nW, CutUp--
    Loop, %nW%
      k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
        ? ft_Gui("RepColor") : "")
    return
  }
  if (cmd="CutU")
  {
    if (CutUp+CutDown>=nH)
      return
    CutUp++, k:=(CutUp-1)*nW
    Loop, %nW%
      k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
        ? ft_Gui("CutColor") : "")
    return
  }
  if (cmd="CutU3")
  {
    Loop, 3
      ft_Gui("CutU")
    return
  }
  if (cmd="RepD")
  {
    if (CutDown<=cors.CutDown)
    or (bg!="" and InStr(color,"**")
    and CutDown=cors.CutDown+1)
      return
    k:=(nH-CutDown)*nW, CutDown--
    Loop, %nW%
      k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
        ? ft_Gui("RepColor") : "")
    return
  }
  if (cmd="CutD")
  {
    if (CutUp+CutDown>=nH)
      return
    CutDown++, k:=(nH-CutDown)*nW
    Loop, %nW%
      k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
        ? ft_Gui("CutColor") : "")
    return
  }
  if (cmd="CutD3")
  {
    Loop, 3
      ft_Gui("CutD")
    return
  }
  if (cmd="Gray2Two")
  {
    Gui, ft_Capture:Default
    GuiControl, Focus, Threshold
    GuiControlGet, Threshold
    if (Threshold="")
    {
      pp:=[]
      Loop, 256
        pp[A_Index-1]:=0
      Loop, % nW*nH
        if (show[A_Index])
          pp[gray[A_Index]]++
      IP:=IS:=0
      Loop, 256
        k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
      Threshold:=Floor(IP/IS)
      Loop, 20
      {
        LastThreshold:=Threshold
        IP1:=IS1:=0
        Loop, % LastThreshold+1
          k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
        IP2:=IP-IP1, IS2:=IS-IS1
        if (IS1!=0 and IS2!=0)
          Threshold:=Floor((IP1/IS1+IP2/IS2)/2)
        if (Threshold=LastThreshold)
          Break
      }
      GuiControl,, Threshold, %Threshold%
    }
    Threshold:=Round(Threshold)
    color:="*" Threshold, k:=i:=0
    Loop, % nW*nH
    {
      ascii[++k]:=v:=(gray[k]<=Threshold)
      if (show[k])
        i:=(v?i+1:i-1), c:=(v?"Black":"White"), ft_Gui("SetColor")
    }
    bg:=i>0 ? "1":"0"
    return
  }
  if (cmd="GrayDiff2Two")
  {
    Gui, ft_Capture:Default
    GuiControlGet, GrayDiff
    if (GrayDiff="")
    {
      Gui, +OwnDialogs
      MsgBox, 4096, 提示, `n  请先设定灰度差值 !  `n, 1
      return
    }
    if (CutLeft=cors.CutLeft)
      ft_Gui("CutL")
    if (CutRight=cors.CutRight)
      ft_Gui("CutR")
    if (CutUp=cors.CutUp)
      ft_Gui("CutU")
    if (CutDown=cors.CutDown)
      ft_Gui("CutD")
    GrayDiff:=Round(GrayDiff)
    color:="**" GrayDiff, k:=i:=0
    Loop, % nW*nH
    {
      j:=gray[++k]+GrayDiff
      , ascii[k]:=v:=( gray[k-1]>j or gray[k+1]>j
      or gray[k-nW]>j or gray[k+nW]>j
      or gray[k-nW-1]>j or gray[k-nW+1]>j
      or gray[k+nW-1]>j or gray[k+nW+1]>j )
      if (show[k])
        i:=(v?i+1:i-1), c:=(v?"Black":"White"), ft_Gui("SetColor")
    }
    bg:=i>0 ? "1":"0"
    return
  }
  if (cmd="Color2Two") or (cmd="ColorPos2Two")
  {
    Gui, ft_Capture:Default
    GuiControlGet, c,, SelColor
    if (c="")
    {
      Gui, +OwnDialogs
      MsgBox, 4096, Tip, `n  请先选择核心颜色 !  `n, 1
      return
    }
    UsePos:=(cmd="ColorPos2Two") ? 1:0
    GuiControlGet, n,, Similar1
    n:=Round(n/100,2), color:=c "@" n
    , n:=Floor(9*255*255*(1-n)*(1-n)), k:=i:=0
    , rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
    Loop, % nW*nH
    {
      c:=cors[++k], r:=((c>>16)&0xFF)-rr
      , g:=((c>>8)&0xFF)-gg, b:=(c&0xFF)-bb
      , ascii[k]:=v:=(3*r*r+4*g*g+2*b*b<=n)
      if (show[k])
        i:=(v?i+1:i-1), c:=(v?"Black":"White"), ft_Gui("SetColor")
    }
    bg:=i>0 ? "1":"0"
    return
  }
  if (cmd="ColorDiff2Two")
  {
    Gui, ft_Capture:Default
    GuiControlGet, c,, SelColor
    if (c="")
    {
      Gui, +OwnDialogs
      MsgBox, 4096, Tip, `n 请先选择核心颜色 !  `n, 1
      return
    }
    GuiControlGet, dR
    GuiControlGet, dG
    GuiControlGet, dB
    rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
    , n:=Format("{:06X}",(dR<<16)|(dG<<8)|dB)
    , color:=StrReplace(c "-" n,"0x"), k:=i:=0
    Loop, % nW*nH
    {
      c:=cors[++k], r:=(c>>16)&0xFF, g:=(c>>8)&0xFF
      , b:=c&0xFF, ascii[k]:=v:=(Abs(r-rr)<=dR
      and Abs(g-gg)<=dG and Abs(b-bb)<=dB)
      if (show[k])
        i:=(v?i+1:i-1), c:=(v?"Black":"White"), ft_Gui("SetColor")
    }
    bg:=i>0 ? "1":"0"
    return
  }
  if (cmd="Modify")
  {
    GuiControlGet, Modify, ft_Capture:, Modify
    return
  }
  if (cmd="Similar1")
  {
    GuiControl, ft_Capture:, Similar2, %Similar1%
    return
  }
  if (cmd="Similar2")
  {
    GuiControl, ft_Capture:, Similar1, %Similar2%
    return
  }
  if (cmd="getwz")
  {
    wz:=""
    if (bg="")
      return
    k:=0
    Loop, %nH%
    {
      v:=""
      Loop, %nW%
        v.=!show[++k] ? "" : ascii[k] ? "1":"0"
      wz.=v="" ? "" : v "`n"
    }
    return
  }
  if (cmd="Auto")
  {
    ft_Gui("getwz")
    if (wz="")
    {
      Gui, ft_Capture:+OwnDialogs
      MsgBox, 4096, Tip, `n请先将图像二值化 !, 1
      return
    }
    While InStr(wz,bg)
    {
      if (wz~="^" bg "+\n")
        wz:=RegExReplace(wz,"^" bg "+\n"), ft_Gui("CutU")
      else if !(wz~="m`n)[^\n" bg "]$")
        wz:=RegExReplace(wz,"m`n)" bg "$"), ft_Gui("CutR")
      else if (wz~="\n" bg "+\n$")
        wz:=RegExReplace(wz,"\n\K" bg "+\n$"), ft_Gui("CutD")
      else if !(wz~="m`n)^[^\n" bg "]")
        wz:=RegExReplace(wz,"m`n)^" bg), ft_Gui("CutL")
      else Break
    }
    wz:=""
    return
  }
  if (cmd="ButtonOK") or (cmd="SplitAdd") or (cmd="AllAdd")
  {
    Gui, ft_Capture:Default
    Gui, +OwnDialogs
    ft_Gui("getwz")
    if (wz="")
    {
      MsgBox, 4096, Tip, `n请先将图像二值化 !, 1
      return
    }
    if InStr(color,"@") and (UsePos)
    {
      StringSplit, r, color, @
      k:=i:=j:=0
      Loop, % nW*nH
      {
        if (!show[++k])
          Continue
        i++
        if (k=cors.SelPos)
        {
          j:=i
          Break
        }
      }
      if (j=0)
      {
        MsgBox, 4096, 提示, 请再次选择核心颜色 !, 3
        return
      }
      color:="#" (j-1) "@" r2
    }
    GuiControlGet, Comment
    if (cmd="SplitAdd")
    {
      if InStr(color,"#")
      {
        MsgBox, 4096, 提示
          , % "不能用于颜色位置二值化模式, "
          . "因为分割后会导致位置错误", 3
        return
      }
      SetFormat, IntegerFast, d
      bg:=StrLen(StrReplace(wz,"0"))
        > StrLen(StrReplace(wz,"1")) ? "1":"0"
      s:="", i:=0, k:=nW*nH+1+CutLeft
      Loop, % w:=nW-CutLeft-CutRight
      {
        i++
        GuiControlGet, j,, % C_[k++]
        if (j=0 and A_Index<w)
          Continue
        v:=RegExReplace(wz,"m`n)^(.{" i "}).*","$1")
        wz:=RegExReplace(wz,"m`n)^.{" i "}"), i:=0
        While InStr(v,bg)
        {
          if (v~="^" bg "+\n")
            v:=RegExReplace(v,"^" bg "+\n")
          else if !(v~="m`n)[^\n" bg "]$")
            v:=RegExReplace(v,"m`n)" bg "$")
          else if (v~="\n" bg "+\n$")
            v:=RegExReplace(v,"\n\K" bg "+\n$")
          else if !(v~="m`n)^[^\n" bg "]")
            v:=RegExReplace(v,"m`n)^" bg)
          else Break
        }
        if (v!="")
        {
          v:=Format("{:d}",InStr(v,"`n")-1) "." bit2base64(v)
          s.="`nText.=""|<" SubStr(Comment,1,1) ">" color "$" v """`n"
          Comment:=SubStr(Comment, 2)
        }
      }
      Event:=cmd, Result:=s
      Gui, Hide
      return
    }
    wz:=Format("{:d}",InStr(wz,"`n")-1) "." bit2base64(wz)
    s:="`nText.=""|<" Comment ">" color "$" wz """`n"
    if (cmd="AllAdd")
    {
      Event:=cmd, Result:=s
      Gui, Hide
      return
    }
    x:=px-ww+CutLeft+(nW-CutLeft-CutRight)//2
    y:=py-hh+CutUp+(nH-CutUp-CutDown)//2
    s:=StrReplace(s, "Text.=", "Text:=")
    s=
    (
`; #Include <FindText>

t1:=A_TickCount
%s%
if (ok:=FindText(%x%-150000, %y%-150000, %x%+150000, %y%+150000, 0, 0, Text))
{
  CoordMode, Mouse
  X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
  ; Click, `%X`%, `%Y`%
}

MsgBox, 4096, 提示, `% "找到:``t" Round(ok.MaxIndex()) "``n``n"
  . "时间:``t" (A_TickCount-t1) " 毫秒``n``n"
  . "位置:``t" X ", " Y "``n``n"
  . "结果:``t" (ok ? "成功 ! " Comment : "失败 !")

for i,v in ok
  if (i<=2)
    MouseTip(ok[i].x, ok[i].y)

)
    Event:=cmd, Result:=s
    Gui, Hide
    return
  }
  if (cmd="ShowPic")
  {
    Critical
    ControlGet, i, CurrentLine,,, ahk_id %hscr%
    ControlGet, s, Line, %i%,, ahk_id %hscr%
    GuiControl, ft_Main:, MyPic, % Trim(ASCII(s),"`n")
    return
  }
  if (cmd="WM_LBUTTONDOWN")
  {
    Critical
    MouseGetPos,,,, j
    IfNotInString, j, progress
      return
    MouseGetPos,,,, j, 2
    Gui, ft_Capture:Default
    For k,v in C_
    {
      if (v!=j)
        Continue
      if (k>nW*nH)
      {
        GuiControlGet, i,, %v%
        GuiControl,, %v%, % i ? 0:100
      }
      else if (Modify and bg!="" and show[k])
      {
        ascii[k]:=!ascii[k]
        , c:=(ascii[k] ? "Black":"White")
        , ft_Gui("SetColor")
      }
      else
      {
        c:=cors[k], cors.SelPos:=k
        r:=(c>>16)&0xFF, g:=(c>>8)&0xFF, b:=c&0xFF
        GuiControl,, SelGray, % gray[k]
        GuiControl,, SelColor, %c%
        GuiControl,, SelR, %r%
        GuiControl,, SelG, %g%
        GuiControl,, SelB, %b%
      }
      Break
    }
    return
  }
  if (cmd="Apply")
  {
    if (!ft_FuncBind2)
      ft_FuncBind2:=Func("ft_Gui").Bind("ScreenShot")
    Gui, ft_Main:Default
    GuiControlGet, NowHotkey
    GuiControlGet, SetHotkey1
    GuiControlGet, SetHotkey2
    if (NowHotkey!="")
      Hotkey, *%NowHotkey%,, Off UseErrorLevel
    k:=SetHotkey1!="" ? SetHotkey1 : SetHotkey2
    if (k!="")
      Hotkey, *%k%, %ft_FuncBind2%, On UseErrorLevel
    GuiControl,, NowHotkey, %k%
    GuiControl,, SetHotkey1
    GuiControl, Choose, SetHotkey2, 0
    ;------------------------
    GuiControlGet, Myww
    GuiControlGet, Myhh
    if (Myww!=ww or Myhh!=hh)
    {
      Gui, Hide
      ww:=Myww, hh:=Myhh, ft_Gui("MakeSubPicWindow")
      Gui, ft_Main:Show, Center
    }
    return
  }
  if (cmd="ScreenShot")
  {
    Critical
    ScreenShot()
    Gui, ft_Tip:New
    ; WS_EX_NOACTIVATE:=0x08000000, WS_EX_TRANSPARENT:=0x20
    Gui, +LastFound +AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x08000020
    Gui, Color, Yellow
    Gui, Font, cRed s48 bold
    Gui, Add, Text,, 截屏成功
    WinSet, Transparent, 200
    Gui, Show, NA y0, 截屏提示
    Sleep, 1000
    Gui, Destroy
    return
  }
}

ft_Load_ToolTip_Text()
{
  s=
(LTrim
Myww       = 调整捕获范围的宽度
Myhh       = 调整捕获范围的高度
AddFunc    = 将 FindText() 函数代码一起复制
NowHotkey  = 当前的截屏热键
SetHotkey1 = 第一优先级的截屏热键
SetHotkey2 = 第二优先级的截屏热键
Apply      = 应用新的截屏热键和调整后的捕获范围值
TestClip   = 将文字代码复制到剪贴板然后测试
Capture    = 开始屏幕抓图
CaptureS   = 先恢复上一次的截屏到屏幕再开始抓图
Test       = 测试生成的代码是否可以找字成功
Copy       = 复制代码到剪贴板
Reset      = 重新读取原来的彩色图像
SplitAdd   = 使用黄色的标签来分割图像为单个的图像数据,添加到旧代码中
AllAdd     = 将文字数据整体添加到旧代码中
ButtonOK   = 生成全新的代码替换旧代码
Close      = 关闭窗口不做任何事
Gray2Two      = 灰度小于阈值的为黑色其余白色
GrayDiff2Two  = 某点与周围灰度之差大于差值的为黑色其余白色
Color2Two     = 指定颜色及相似色为黑色其余白色
ColorPos2Two  = 指定颜色及相似色为黑色其余白色,但是记录该色的位置
ColorDiff2Two = 指定颜色及颜色分量小于允许值的为黑色其余白色
SelGray    = 选定颜色的灰度值 (0-255)
SelColor   = 选定颜色的RGB颜色值
SelR       = 选定颜色的红色分量
SelG       = 选定颜色的绿色分量
SelB       = 选定颜色的蓝色分量
RepU       = 撤销裁剪上边缘1个像素
CutU       = 裁剪上边缘1个像素
CutU3      = 裁剪上边缘3个像素
RepL       = 撤销裁剪左边缘1个像素
CutL       = 裁剪左边缘1个像素
CutL3      = 裁剪左边缘3个像素
Auto       = 二值化之后自动裁剪空白边缘
RepR       = 撤销裁剪右边缘1个像素
CutR       = 裁剪右边缘1个像素
CutR3      = 裁剪右边缘3个像素
RepD       = 撤销裁剪下边缘1个像素
CutD       = 裁剪下边缘1个像素
CutD3      = 裁剪下边缘3个像素
Modify     = 二值化后允许修改黑白点
Comment    = 识别文本 (包含在<>中),分割添加时也会分解成单个文字
Threshold  = 灰度阈值 (0-255)
GrayDiff   = 灰度差值 (0-255)
Similar1   = 与选定颜色的相似度
Similar2   = 与选定颜色的相似度
DiffR      = 红色分量允许的偏差 (0-255)
DiffG      = 绿色分量允许的偏差 (0-255)
DiffB      = 蓝色分量允许的偏差 (0-255)
Bind1      = 绑定窗口从而可以后台查找这个窗口的图像
Bind2      = 先修改窗口使它支持透明属性再绑定窗口
)
  return, s
}

ft_EditEvents1()
{
  static ft_FuncBind3:=Func("ft_Gui").Bind("ShowPic")
  ListLines, Off
  if (A_Gui="ft_Main" && A_GuiControl="scr")
    SetTimer, %ft_FuncBind3%, -150
}

ft_EditEvents2()
{
  ListLines, Off
  if (A_Gui="ft_SubPic")
    ft_Gui("WM_LBUTTONDOWN")
  else
    ft_EditEvents1()
}

ft_ShowToolTip(cmd:="")
{
  static
  ListLines, Off
  if (!ToolTip_Text)
    ToolTip_Text:=ft_Load_ToolTip_Text()
  if (!ft_FuncBind4)
    ft_FuncBind4:=Func("ft_ShowToolTip").Bind("ToolTip")
  if (!ft_FuncBind5)
    ft_FuncBind5:=Func("ft_ShowToolTip").Bind("ToolTipOff")
  if (cmd="ToolTip")
  {
    MouseGetPos,,, _TT
    WinGetClass, _TT, ahk_id %_TT%
    if (_TT = "AutoHotkeyGUI")
      ToolTip, % RegExMatch(ToolTip_Text
      , "im`n)^" CurrControl "\K\s*=.*", _TT)
      ? StrReplace(Trim(_TT,"`t ="),"\n","`n") : ""
    return
  }
  if (cmd="ToolTipOff")
  {
    ToolTip
    return
  }
  CurrControl:=A_GuiControl
  if (CurrControl!=PrevControl)
  {
    PrevControl:=CurrControl, _TT:=(CurrControl!="")
    SetTimer, %ft_FuncBind4%, % _TT ? -500  : "Off"
    SetTimer, %ft_FuncBind5%, % _TT ? -5500 : "Off"
    ToolTip
  }
}

ft_getc(px, py, ww, hh, ScreenShot:=1)
{
  xywh2xywh(px-ww,py-hh,2*ww+1,2*hh+1,x,y,w,h)
  if (w<1 or h<1)
    return
  bch:=A_BatchLines
  SetBatchLines, -1
  if (ScreenShot)
    ScreenShot()
  cors:=[], k:=0
  lls:=A_ListLines=0 ? "Off" : "On"
  ListLines, Off
  Loop, % 2*hh+1
  {
    j:=py-hh+A_Index-1
    Loop, % 2*ww+1
      i:=px-ww+A_Index-1, cors[++k]:=ScreenShot_GetColor(i,j)
  }
  ListLines, %lls%
  cors.CutLeft:=Abs(px-ww-x)
  cors.CutRight:=Abs(px+ww-(x+w-1))
  cors.CutUp:=Abs(py-hh-y)
  cors.CutDown:=Abs(py+hh-(y+h-1))
  SetBatchLines, %bch%
  return, cors
}

ft_ShowScreenShot(Show:=1) {
  local  ; 避免超级全局变量的影响
  static hBM, Ptr:=A_PtrSize ? "UPtr" : "UInt"
  Gui, ft_ScreenShot:Destroy
  if (hBM)
    DllCall("DeleteObject",Ptr,hBM), hBM:=""
  bits:=GetBitsFromScreen(0,0,0,0,0,zx,zy,zw,zh)
  if (!Show or !bits.1 or zw<1 or zh<1)
    return
  ;---------------------
  VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
  NumPut(zw, bi, 4, "int"), NumPut(-zh, bi, 8, "int")
  NumPut(1, bi, 12, "short"), NumPut(bpp:=32, bi, 14, "short")
  if (hBM:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
  , "int",0, Ptr "*",ppvBits, Ptr,0, "int",0, Ptr))
    DllCall("RtlMoveMemory",Ptr,ppvBits,Ptr,bits.1,Ptr,bits.2*zh)
  ;-------------------------
  win:=DllCall("GetDesktopWindow", Ptr)
  hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
  mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
  oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
  hBrush:=DllCall("CreateSolidBrush", "uint",0xFFFFFF, Ptr)
  oBrush:=DllCall("SelectObject", Ptr,mDC, Ptr,hBrush, Ptr)
  DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",zw, "int",zh
    , Ptr,mDC, "int",0, "int",0, "uint",0xC000CA)
  DllCall("SelectObject", Ptr,mDC, Ptr,oBrush)
  DllCall("DeleteObject", Ptr,hBrush)
  DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
  DllCall("DeleteDC", Ptr,mDC)
  DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
  ;-------------------------
  Gui, ft_ScreenShot:+AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
  Gui, ft_ScreenShot:Margin, 0, 0
  Gui, ft_ScreenShot:Add, Picture, x0 y0 w%zw% h%zh% +HwndhPic +0xE
  SendMessage, 0x172, 0, hBM,, ahk_id %hPic%
  Gui, ft_ScreenShot:Show, NA x%zx% y%zy% w%zw% h%zh%, Show ScreenShot
}

ft_Exec(s)
{
  Ahk:=A_IsCompiled ? A_ScriptDir "\AutoHotkey.exe":A_AhkPath
  s:=RegExReplace(s, "\R", "`r`n")
  Try
  {
    shell:=ComObjCreate("WScript.Shell")
    oExec:=shell.Exec(Ahk " /f /ErrorStdOut *")
    oExec.StdIn.Write(s)
    oExec.StdIn.Close()
  }
  catch
  {
    f:=A_Temp "\~test1.tmp"
    s:="`r`n FileDelete, " f "`r`n" s
    FileDelete, %f%
    FileAppend, %s%, %f%
    Run, %Ahk% /f "%f%",, UseErrorLevel
  }
}

;

人已赞赏
AHKV1学习

TreeView+数组菜单示例

2020-3-12 8:39:16

AHKV1学习

Autohotkey字符串去重算法

2020-4-19 22:40:53

4 条回复 A文章作者 M管理员
  1. 上面的脚本源代码好像不太完整哦!!!

    • 源码显示有点bug每行的第一个反斜杠会被默认为转义符号

  2. https://blog.csdn.net/xshlong1981/article/details/103324372/

    ;/*
    ;===========================================
    ; FindText - 屏幕抓字生成字库工具与找字函数
    ;
    ; 脚本作者 : FeiYue
    ; 最新版本 : 7.3
    ; 更新时间 : 2019-12-21
    ;
    ; 用法:
    ; 1. 将本脚本保存为“FindText.ahk”并复制到AHK程序的Lib子目录中
    ; 2. 抓图并生成调用FindText()的代码
    ; 2.1 直接点击“抓图”按钮
    ; 2.2 先设定截屏热键,使用热键截屏,再点击“截屏抓图”按钮
    ; 3. 测试一下调用的代码是否成功:直接点击“测试”按钮
    ; 4. 复制调用的代码到自己的脚本中
    ; 4.1 直接点击“复制”按钮,然后粘贴到自己的脚本中
    ; 4.2 取消“附加FindText()函数”的选框,然后点击“复制”按钮,
    ; 然后粘贴到自己的脚本中,然后在自己的脚本开头加上一行:
    ; #Include ; Lib目录中必须有FindText.ahk
    ;
    ;===========================================
    ; 函数的参数和返回值:
    ;
    ; 返回变量 := FindText(
    ; X1 --> 查找范围的左上角X坐标
    ; , Y1 --> 查找范围的左上角Y坐标
    ; , X2 --> 查找范围的右下角X坐标
    ; , Y2 --> 查找范围的右下角Y坐标
    ; , err1 --> 文字的黑点容错百分率(0.1=10%)
    ; , err0 --> 背景的白点容错百分率(0.1=10%)
    ; , Text --> 由工具生成的查找图像的数据,可以一次查找多个,用“|”分隔
    ; , ScreenShot --> 是否截屏,为0则使用上一次的截屏数据
    ; , FindAll --> 是否搜索所有位置,为0则找到一个位置就返回
    ; , JoinText --> 是否组合图像,为1则多个数据组合为一幅图来查找
    ; , offsetX --> 组合图像的每个字和前一个字的最大横向间隔
    ; , offsetY --> 组合图像的每个字和第一个字的最大高低间隔
    ; )
    ; 返回变量 --> 如果没找到结果会返回0。否则返回一个二级数组,
    ; 第一级是每个结果对象,第二级是结果对象的具体信息数组:
    ; { 1:左上角X, 2:左上角Y, 3:图像宽度W, 4:图像高度H
    ; , x:中心点X, y:中心点Y, id:图像识别文本 }
    ;
    ; 坐标都是相对于屏幕,颜色使用RGB格式,组合查找必须使用统一的颜色模式
    ;===========================================
    ;*/

    if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
    ft_Gui("Show")

    ft_Gui(cmd)
    {
    static
    if (cmd="Show")
    {
    Gui, ft_Main:+LastFoundExist
    IfWinExist
    {
    Gui, ft_Main:Show, Center
    return
    }
    if (!ft_FuncBind1)
    ft_FuncBind1:=Func("ft_Gui").Bind("Show")
    #NoEnv
    Menu, Tray, Add
    Menu, Tray, Add, 查找文字工具, %ft_FuncBind1%
    if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
    {
    Menu, Tray, Default, 查找文字工具
    Menu, Tray, Click, 1
    Menu, Tray, Icon, Shell32.dll, 23
    }
    ft_BatchLines:=A_BatchLines
    ft_IsCritical:=A_IsCritical
    Critical
    ww:=35, hh:=12, WindowColor:="0xDDEEFF"
    ft_Gui("MakeCaptureWindow")
    ft_Gui("MakeSubPicWindow")
    ft_Gui("MakeMainWindow")
    OnMessage(0x100, Func("ft_EditEvents1")) ; WM_KEYDOWN
    OnMessage(0x201, Func("ft_EditEvents2")) ; WM_LBUTTONDOWN
    OnMessage(0x200, Func("ft_ShowToolTip")) ; WM_MOUSEMOVE
    Gui, ft_Main:Show, Center
    GuiControl, ft_Main:Focus, scr
    Critical, %ft_IsCritical%
    SetBatchLines, %ft_BatchLines%
    return
    ;-------------------
    ft_Run:
    Critical
    ft_Gui(Trim(A_GuiControl))
    return
    }
    if (cmd="MakeCaptureWindow")
    {
    Gui, ft_Capture:New
    Gui, +AlwaysOnTop -DPIScale
    Gui, Margin, 15, 15
    Gui, Color, %WindowColor%
    Gui, Font, s12, Verdana
    Gui, Add, Text, xm w855 h315 +HwndhPic
    Gui, Add, Slider, ym h315 vMySlider2 gft_Run
    +Center Page20 Line20 NoTicks AltSubmit +Vertical
    Gui, Add, Slider, xm w855 vMySlider1 gft_Run
    +Center Page20 Line20 NoTicks AltSubmit
    GuiControlGet, Pic, Pos, %hPic%
    PicW:=Round(PicW), PicH:=Round(PicH), MySlider1:=MySlider2:=0
    Gui, Add, Button, xm+125 w50 vRepU gft_Run, -上
    Gui, Add, Button, x+0 wp vCutU gft_Run, 上
    Gui, Add, Button, x+0 wp vCutU3 gft_Run, 上3
    ;--------------
    Gui, Add, Text, x+50 yp+3 Section, 灰度
    Gui, Add, Edit, x+3 yp-3 w60 vSelGray ReadOnly
    Gui, Add, Text, x+15 ys, 颜色
    Gui, Add, Edit, x+3 yp-3 w120 vSelColor ReadOnly
    Gui, Add, Text, x+15 ys, 红
    Gui, Add, Edit, x+3 yp-3 w60 vSelR ReadOnly
    Gui, Add, Text, x+5 ys, 绿
    Gui, Add, Edit, x+3 yp-3 w60 vSelG ReadOnly
    Gui, Add, Text, x+5 ys, 蓝
    Gui, Add, Edit, x+3 yp-3 w60 vSelB ReadOnly
    ;--------------
    Gui, Add, Button, xm w50 vRepL gft_Run, -左
    Gui, Add, Button, x+0 wp vCutL gft_Run, 左
    Gui, Add, Button, x+0 wp vCutL3 gft_Run, 左3
    Gui, Add, Button, x+15 w70 vAuto gft_Run, 自动
    Gui, Add, Button, x+15 w50 vRepR gft_Run, -右
    Gui, Add, Button, x+0 wp vCutR gft_Run, 右
    Gui, Add, Button, x+0 wp vCutR3 gft_Run Section, 右3
    Gui, Add, Button, xm+125 w50 vRepD gft_Run, -下
    Gui, Add, Button, x+0 wp vCutD gft_Run, 下
    Gui, Add, Button, x+0 wp vCutD3 gft_Run, 下3
    ;--------------
    Gui, Add, Tab3, ys-8 -Wrap, 灰度阈值|灰度差值|颜色相似|颜色位置|颜色分量
    Gui, Tab, 1
    Gui, Add, Text, x+15 y+15, 灰度阈值
    Gui, Add, Edit, x+15 w100 vThreshold
    Gui, Add, Button, x+15 yp-3 vGray2Two gft_Run, 灰度阈值二值化
    Gui, Tab, 2
    Gui, Add, Text, x+15 y+15, 灰度差值
    Gui, Add, Edit, x+15 w100 vGrayDiff, 50
    Gui, Add, Button, x+15 yp-3 vGrayDiff2Two gft_Run, 灰度差值二值化
    Gui, Tab, 3
    Gui, Add, Text, x+15 y+15, 相似度 0
    Gui, Add, Slider, x+0 w100 vSimilar1 gft_Run
    +Center Page1 NoTicks ToolTip, 100
    Gui, Add, Text, x+0, 100
    Gui, Add, Button, x+15 yp-3 vColor2Two gft_Run, 颜色相似二值化
    Gui, Tab, 4
    Gui, Add, Text, x+15 y+15, 相似度 0
    Gui, Add, Slider, x+0 w100 vSimilar2 gft_Run
    +Center Page1 NoTicks ToolTip, 100
    Gui, Add, Text, x+0, 100
    Gui, Add, Button, x+15 yp-3 vColorPos2Two gft_Run, 颜色位置二值化
    Gui, Tab, 5
    Gui, Add, Text, x+10 y+15, 红
    Gui, Add, Edit, x+2 w70 vDiffR Limit3
    Gui, Add, UpDown, vdR Range0-255
    Gui, Add, Text, x+5, 绿
    Gui, Add, Edit, x+2 w70 vDiffG Limit3
    Gui, Add, UpDown, vdG Range0-255
    Gui, Add, Text, x+5, 蓝
    Gui, Add, Edit, x+2 w70 vDiffB Limit3
    Gui, Add, UpDown, vdB Range0-255
    Gui, Add, Button, x+5 yp-3 vColorDiff2Two gft_Run, 颜色分量二值化
    Gui, Tab
    ;--------------
    Gui, Add, Button, xm vReset gft_Run, 重读
    Gui, Add, Checkbox, x+15 yp+5 vModify gft_Run, 修改
    Gui, Add, Text, x+30, 识别文字
    Gui, Add, Edit, x+5 yp-2 w150 vComment
    Gui, Add, Button, x+30 yp-3 vSplitAdd gft_Run, 分割添加
    Gui, Add, Button, x+10 vAllAdd gft_Run, 整体添加
    Gui, Add, Button, x+10 w80 vButtonOK gft_Run, 确定
    Gui, Add, Button, x+10 wp vClose gCancel, 关闭
    Gui, Add, Button, xm vBind1 gft_Run, 绑定窗口
    Gui, Add, Button, x+15 vBind2 gft_Run, 绑定窗口+
    Gui, Show, Hide, 图像二值化及分割
    return
    }
    if (cmd="MakeSubPicWindow")
    {
    Gui, ft_SubPic:New
    Gui, +AlwaysOnTop -Caption +ToolWindow -DPIScale +Parent%hPic%
    Gui, Margin, 0, 0
    Gui, Color, %WindowColor%
    Gui, -Theme
    nW:=2*ww+1, nH:=2*hh+1, C_:=[], w:=11
    Loop, % nW*(nH+1)
    {
    i:=A_Index, j:=i=1 ? "x0 y0" : Mod(i,nW)=1 ? "x0 y+1" : "x+1"
    j.=i>nW*nH ? " cRed BackgroundFFFFAA" : ""
    Gui, Add, Progress, w%w% h%w% %j% +Hwndid
    Control, ExStyle, -0x20000,, ahk_id %id%
    C_[i]:=id
    }
    Gui, +Theme
    GuiControlGet, SubPic, Pos, %id%
    SubPicW:=Round(SubPicX+SubPicW), SubPicH:=Round(SubPicY+SubPicH)
    Gui, Show, NA x0 y0 w%SubPicW% h%SubPicH%, SubPic
    i:=(SubPicW>PicW), j:=(SubPicH>PicH)
    Gui, ft_Capture:Default
    GuiControl, Enable%i%, MySlider1
    GuiControl, Enable%j%, MySlider2
    GuiControl,, MySlider1, % MySlider1:=0
    GuiControl,, MySlider2, % MySlider2:=0
    return
    }
    if (cmd="MakeMainWindow")
    {
    Gui, ft_Main:New
    Gui, +AlwaysOnTop -DPIScale
    Gui, Margin, 15, 15
    Gui, Color, %WindowColor%
    Gui, Font, s12 cBlack, Verdana
    Gui, Add, GroupBox, xm y10 w250 h45 vMyGroup
    Gui, Add, Text, xp+10 yp+18 Section, % "宽度: "
    Gui, Add, Text, x+0 w50, %ww%
    Gui, Add, UpDown, vMyww Range1-50, %ww%
    Gui, Add, Text, x+15 ys, % "高度: "
    Gui, Add, Text, x+0 w50, %hh%
    Gui, Add, UpDown, vMyhh Range1-40, %hh%
    GuiControlGet, p, Pos, Myhh
    GuiControl, Move, MyGroup, % "w" px+pw " h" py+ph
    Gui, Add, Checkbox, x+30 ys Checked vAddFunc, 附加 FindText()
    GuiControlGet, p, Pos, AddFunc
    w:=720+15-(px+pw)-15
    Gui, Add, Button, x+15 ys-8 w%w% vTestClip gft_Run, 复制后测试
    Gui, Add, Text, xm, 截屏热键
    Gui, Add, Edit, x+5 w150 vNowHotkey ReadOnly
    Gui, Add, Hotkey, x+5 w180 vSetHotkey1
    Gui, Add, DDL, x+5 w150 vSetHotkey2
    , % "||F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|MButton"
    . "|ScrollLock|CapsLock|Ins|Esc|BS|Del|Tab|Home|End|PgUp|PgDn"
    . "|NumpadDot|NumpadSub|NumpadAdd|NumpadDiv|NumpadMult"
    GuiControlGet, p, Pos, SetHotkey2
    w:=720+15-(px+pw)-5
    Gui, Add, Button, x+5 yp-3 w%w% vApply gft_Run, 应用
    Gui, Font, s6 bold, Verdana
    Gui, Add, Edit, xm w720 r25 vMyPic -Wrap
    Gui, Font, s12 norm, Verdana
    Gui, Add, Button, w180 vCapture gft_Run, 抓图
    Gui, Add, Button, x+0 wp vCaptureS gft_Run, 截屏抓图
    Gui, Add, Button, x+0 wp vTest gft_Run, 测试
    Gui, Add, Button, x+0 wp vCopy gft_Run Section, 复制
    Gui, Font, s12 cBlue, Verdana
    Gui, Add, Edit, xm w720 h350 vscr Hwndhscr -Wrap HScroll
    Gui, Show, Hide, 抓图生成字库及找字代码
    return
    }
    if (cmd="Capture") or (cmd="CaptureS")
    {
    Gui, ft_Main:Default
    Gui, +LastFound
    WinMinimize
    Gui, Hide
    ShowScreenShot:=(cmd="CaptureS")
    if (ShowScreenShot)
    ft_ShowScreenShot(1)
    ;----------------------
    Gui, ft_Mini:New
    Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
    Gui, Color, Red
    d:=2, w:=nW+2*d, h:=nH+2*d, i:=w-d, j:=h-d
    Gui, Show, Hide w%w% h%h%
    s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
    s=%s% %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
    WinSet, Region, %s%
    ;------------------------------
    Hotkey, $*RButton, ft_RButton_Off, On
    lls:=A_ListLines=0 ? "Off" : "On"
    ListLines, Off
    CoordMode, Mouse
    KeyWait, RButton
    KeyWait, Ctrl
    oldx:=oldy:=""
    Loop
    {
    Sleep, 50
    MouseGetPos, x, y, Bind_ID
    if (oldx=x and oldy=y)
    Continue
    oldx:=x, oldy:=y
    ;---------------
    Gui, Show, % "NA x" (x-w//2) " y" (y-h//2)
    ToolTip, % "鼠标位置 : " x "," y
    . "`n先点击右键一次确定选框"
    . "`n再移开鼠标避免鼠标影响"
    . "`n再点击右键一次完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    px:=x, py:=y, oldx:=oldy:=""
    Loop
    {
    Sleep, 50
    MouseGetPos, x, y
    if (oldx=x and oldy=y)
    Continue
    oldx:=x, oldy:=y
    ;---------------
    ToolTip, % "选框位置 : " px "," py
    . "`n先点击右键一次确定选框"
    . "`n再移开鼠标避免鼠标影响"
    . "`n再点击右键一次完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    ToolTip
    ListLines, %lls%
    Gui, Destroy
    WinWaitClose,,, 10
    cors:=ft_getc(px,py,ww,hh,!ShowScreenShot)
    Hotkey, $*RButton, ft_RButton_Off, Off
    if (ShowScreenShot)
    ft_ShowScreenShot(0)
    ;--------------------------------
    Gui, ft_Capture:Default
    k:=nW*nH+1
    Loop, % nW
    GuiControl,, % C_[k++], 0
    Loop, 6
    GuiControl,, Edit%A_Index%
    GuiControl,, Modify, % Modify:=0
    GuiControl,, GrayDiff, 50
    GuiControl, Focus, Gray2Two
    GuiControl, +Default, Gray2Two
    ft_Gui("Reset")
    Gui, Show, Center
    Event:=Result:=""
    DetectHiddenWindows, Off
    Gui, +LastFound
    Critical, Off
    WinWaitClose, % "ahk_id " WinExist()
    Gui, ft_Main:Default
    ;--------------------------------
    if (cors.bind!="")
    {
    WinGetTitle, tt, ahk_id %Bind_ID%
    WinGetClass, tc, ahk_id %Bind_ID%
    tt:=Trim(SubStr(tt,1,30) (tc ? " ahk_class " tc:""))
    tt:=StrReplace(RegExReplace(tt,"[;``]","``$0"),"""","""""")
    Result:="`nSetTitleMatchMode, 2`nid:=WinExist(""" tt """)"
    . "`nBindWindow(id" (cors.bind ? ",1":"")
    . ") `; 解绑窗口使用 Bindwindow(0)`n`n" Result
    }
    if (Event="ButtonOK")
    {
    if (!A_IsCompiled)
    {
    FileRead, s, %A_LineFile%
    s:=SubStr(s, s~="i)n[;=]+ Copy The")
    }
    else s:=""
    GuiControl,, scr, % Result "`n" s
    GuiControl,, MyPic, % Trim(ASCII(Result),"`n")
    Result:=s:=""
    }
    else if (Event="SplitAdd") or (Event="AllAdd")
    {
    GuiControlGet, s,, scr
    i:=j:=0, r:="|n]*>[^$n]+$d+.[w+/]+"
    While j:=RegExMatch(s,r,"",j+1)
    i:=InStr(s,"`n",0,j)
    GuiControl,, scr, % SubStr(s,1,i-1) . Result . SubStr(s,i+1)
    GuiControl,, MyPic, % Trim(ASCII(Result),"`n")
    Result:=s:=""
    }
    ;----------------------
    Gui, Show
    GuiControl, Focus, scr
    ft_RButton_Off:
    return
    }
    if (cmd="Bind1") or (cmd="Bind2")
    {
    BindWindow(Bind_ID, (cmd="Bind2"))
    Hotkey, $*RButton, ft_RButton_Off, On
    lls:=A_ListLines=0 ? "Off" : "On"
    ListLines, Off
    CoordMode, Mouse
    KeyWait, RButton
    KeyWait, Ctrl
    oldx:=oldy:=""
    Loop
    {
    Sleep, 50
    MouseGetPos, x, y
    if (oldx=x and oldy=y)
    Continue
    oldx:=x, oldy:=y
    ;---------------
    cors:=ft_getc(px:=x,py:=y,ww,hh)
    ft_Gui("Reset")
    ToolTip, % "鼠标位置 : " x "," y
    . "`n穿透显示绑定窗口"
    . "`n点击右键完成抓图"
    }
    Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
    KeyWait, RButton
    KeyWait, Ctrl
    ToolTip
    ListLines, %lls%
    Hotkey, $*RButton, ft_RButton_Off, Off
    BindWindow(0), cors.bind:=(cmd="Bind2")
    return
    }
    if (cmd="Test") or (cmd="TestClip")
    {
    Critical, Off
    Gui, ft_Main:Default
    Gui, +LastFound
    WinMinimize
    Gui, Hide
    DetectHiddenWindows, Off
    WinWaitClose, % "ahk_id " WinExist()
    Sleep, 100
    ;----------------------
    if (cmd="Test")
    GuiControlGet, s,, scr
    else
    s:=Clipboard
    if (!A_IsCompiled) and InStr(s,"MCode(") and (cmd="Test")
    {
    s:="`n#NoEnv`nMenu, Tray, Click, 1`n"
    . "Gui, ft_ok_:Show, Hide, ft_ok_`n"
    . s "`nExitApp`n"
    ft_Exec(s)
    DetectHiddenWindows, On
    WinWait, ft_ok_ ahk_class AutoHotkeyGUI,, 3
    if (!ErrorLevel)
    WinWaitClose,,, 30
    }
    else
    {
    Gui, +OwnDialogs
    t:=A_TickCount, n:=150000
    , RegExMatch(s,"|n]*>[^$n]+$d+.[w+/]+",v)
    , ok:=FindText(-n, -n, n, n, 0, 0, v)
    , X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
    MsgBox, 4096, 提示, % "找到:`t" Round(ok.MaxIndex()) "`n`n"
    . "时间:`t" (A_TickCount-t) " 毫秒`n`n"
    . "位置:`t" X ", " Y "`n`n"
    . "结果:`t" (ok ? "成功 ! " Comment : "失败 !"), 3
    for i,v in ok
    if (iPicW ? -(SubPicW-PicW)*MySlider1//100 : 0
    y:=SubPicH>PicH ? -(SubPicH-PicH)*MySlider2//100 : 0
    Gui, ft_SubPic:Show, NA x%x% y%y%
    return
    }
    if (cmd="Reset")
    {
    if !IsObject(ascii)
    ascii:=[], gray:=[], show:=[]
    CutLeft:=CutRight:=CutUp:=CutDown:=k:=0, bg:=""
    Loop, % nW*nH
    {
    show[++k]:=1, c:=cors[k]
    gray[k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
    ft_Gui("SetColor")
    }
    Loop, % cors.CutLeft
    ft_Gui("CutL")
    Loop, % cors.CutRight
    ft_Gui("CutR")
    Loop, % cors.CutUp
    ft_Gui("CutU")
    Loop, % cors.CutDown
    ft_Gui("CutD")
    return
    }
    if (cmd="SetColor")
    {
    c:=c="Black" ? 0x000000 : c="White" ? 0xFFFFFF
    : ((c&0xFF)<>16)
    SendMessage, 0x2001, 0, c,, % "ahk_id " . C_[k]
    return
    }
    if (cmd="RepColor")
    {
    show[k]:=1, c:=(bg="" ? cors[k] : ascii[k]
    ? "Black":"White"), ft_Gui("SetColor")
    return
    }
    if (cmd="CutColor")
    {
    show[k]:=0, c:=WindowColor, ft_Gui("SetColor")
    return
    }
    if (cmd="RepL")
    {
    if (CutLeftCutUp and A_Index=nW)
    return
    CutLeft++, k:=CutLeft-nW
    Loop, %nH%
    k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
    ? ft_Gui("CutColor") : "")
    return
    }
    if (cmd="CutL3")
    {
    Loop, 3
    ft_Gui("CutL")
    return
    }
    if (cmd="RepR")
    {
    if (CutRightCutUp and A_Index=nW)
    return
    CutRight++, k:=1-CutRight
    Loop, %nH%
    k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
    ? ft_Gui("CutColor") : "")
    return
    }
    if (cmd="CutR3")
    {
    Loop, 3
    ft_Gui("CutR")
    return
    }
    if (cmd="RepU")
    {
    if (CutUpCutLeft and A_Index=nH)
    return
    CutUp++, k:=(CutUp-1)*nW
    Loop, %nW%
    k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
    ? ft_Gui("CutColor") : "")
    return
    }
    if (cmd="CutU3")
    {
    Loop, 3
    ft_Gui("CutU")
    return
    }
    if (cmd="RepD")
    {
    if (CutDownCutLeft and A_Index=nH)
    return
    CutDown++, k:=(nH-CutDown)*nW
    Loop, %nW%
    k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
    ? ft_Gui("CutColor") : "")
    return
    }
    if (cmd="CutD3")
    {
    Loop, 3
    ft_Gui("CutD")
    return
    }
    if (cmd="Gray2Two")
    {
    Gui, ft_Capture:Default
    GuiControl, Focus, Threshold
    GuiControlGet, Threshold
    if (Threshold="")
    {
    pp:=[]
    Loop, 256
    pp[A_Index-1]:=0
    Loop, % nW*nH
    if (show[A_Index])
    pp[gray[A_Index]]++
    IP:=IS:=0
    Loop, 256
    k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
    Threshold:=Floor(IP/IS)
    Loop, 20
    {
    LastThreshold:=Threshold
    IP1:=IS1:=0
    Loop, % LastThreshold+1
    k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
    IP2:=IP-IP1, IS2:=IS-IS1
    if (IS1!=0 and IS2!=0)
    Threshold:=Floor((IP1/IS1+IP2/IS2)/2)
    if (Threshold=LastThreshold)
    Break
    }
    GuiControl,, Threshold, %Threshold%
    }
    Threshold:=Round(Threshold)
    color:="*" Threshold, k:=i:=0
    Loop, % nW*nH
    {
    ascii[++k]:=v:=(gray[k]0 ? "1":"0"
    return
    }
    if (cmd="GrayDiff2Two")
    {
    Gui, ft_Capture:Default
    GuiControlGet, GrayDiff
    if (GrayDiff="")
    {
    Gui, +OwnDialogs
    MsgBox, 4096, 提示, `n 请先设定灰度差值 ! `n, 1
    return
    }
    if (CutLeft=cors.CutLeft)
    ft_Gui("CutL")
    if (CutRight=cors.CutRight)
    ft_Gui("CutR")
    if (CutUp=cors.CutUp)
    ft_Gui("CutU")
    if (CutDown=cors.CutDown)
    ft_Gui("CutD")
    GrayDiff:=Round(GrayDiff)
    color:="**" GrayDiff, k:=i:=0
    Loop, % nW*nH
    {
    j:=gray[++k]+GrayDiff
    , ascii[k]:=v:=( gray[k-1]>j or gray[k+1]>j
    or gray[k-nW]>j or gray[k+nW]>j
    or gray[k-nW-1]>j or gray[k-nW+1]>j
    or gray[k+nW-1]>j or gray[k+nW+1]>j )
    if (show[k])
    i:=(v?i+1:i-1), c:=(v?"Black":"White"), ft_Gui("SetColor")
    }
    bg:=i>0 ? "1":"0"
    return
    }
    if (cmd="Color2Two") or (cmd="ColorPos2Two")
    {
    Gui, ft_Capture:Default
    GuiControlGet, c,, SelColor
    if (c="")
    {
    Gui, +OwnDialogs
    MsgBox, 4096, Tip, `n 请先选择核心颜色 ! `n, 1
    return
    }
    UsePos:=(cmd="ColorPos2Two") ? 1:0
    GuiControlGet, n,, Similar1
    n:=Round(n/100,2), color:=c "@" n
    , n:=Floor(9*255*255*(1-n)*(1-n)), k:=i:=0
    , rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
    Loop, % nW*nH
    {
    c:=cors[++k], r:=((c>>16)&0xFF)-rr
    , g:=((c>>8)&0xFF)-gg, b:=(c&0xFF)-bb
    , ascii[k]:=v:=(3*r*r+4*g*g+2*b*b0 ? "1":"0"
    return
    }
    if (cmd="ColorDiff2Two")
    {
    Gui, ft_Capture:Default
    GuiControlGet, c,, SelColor
    if (c="")
    {
    Gui, +OwnDialogs
    MsgBox, 4096, Tip, `n 请先选择核心颜色 ! `n, 1
    return
    }
    GuiControlGet, dR
    GuiControlGet, dG
    GuiControlGet, dB
    rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
    , n:=Format("{:06X}",(dR<<16)|(dG<>16)&0xFF, g:=(c>>8)&0xFF
    , b:=c&0xFF, ascii[k]:=v:=(Abs(r-rr)<=dR
    and Abs(g-gg)<=dG and Abs(b-bb)0 ? "1":"0"
    return
    }
    if (cmd="Modify")
    {
    GuiControlGet, Modify, ft_Capture:, Modify
    return
    }
    if (cmd="Similar1")
    {
    GuiControl, ft_Capture:, Similar2, %Similar1%
    return
    }
    if (cmd="Similar2")
    {
    GuiControl, ft_Capture:, Similar1, %Similar2%
    return
    }
    if (cmd="getwz")
    {
    wz:=""
    if (bg="")
    return
    k:=0
    Loop, %nH%
    {
    v:=""
    Loop, %nW%
    v.=!show[++k] ? "" : ascii[k] ? "1":"0"
    wz.=v="" ? "" : v "`n"
    }
    return
    }
    if (cmd="Auto")
    {
    ft_Gui("getwz")
    if (wz="")
    {
    Gui, ft_Capture:+OwnDialogs
    MsgBox, 4096, Tip, `n请先将图像二值化 !, 1
    return
    }
    While InStr(wz,bg)
    {
    if (wz~="^" bg "+n")
    wz:=RegExReplace(wz,"^" bg "+n"), ft_Gui("CutU")
    else if !(wz~="m`n)[^n" bg "]$")
    wz:=RegExReplace(wz,"m`n)" bg "$"), ft_Gui("CutR")
    else if (wz~="n" bg "+n$")
    wz:=RegExReplace(wz,"nK" bg "+n$"), ft_Gui("CutD")
    else if !(wz~="m`n)^[^n" bg "]")
    wz:=RegExReplace(wz,"m`n)^" bg), ft_Gui("CutL")
    else Break
    }
    wz:=""
    return
    }
    if (cmd="ButtonOK") or (cmd="SplitAdd") or (cmd="AllAdd")
    {
    Gui, ft_Capture:Default
    Gui, +OwnDialogs
    ft_Gui("getwz")
    if (wz="")
    {
    MsgBox, 4096, Tip, `n请先将图像二值化 !, 1
    return
    }
    if InStr(color,"@") and (UsePos)
    {
    StringSplit, r, color, @
    k:=i:=j:=0
    Loop, % nW*nH
    {
    if (!show[++k])
    Continue
    i++
    if (k=cors.SelPos)
    {
    j:=i
    Break
    }
    }
    if (j=0)
    {
    MsgBox, 4096, 提示, 请再次选择核心颜色 !, 3
    return
    }
    color:="#" (j-1) "@" r2
    }
    GuiControlGet, Comment
    if (cmd="SplitAdd")
    {
    if InStr(color,"#")
    {
    MsgBox, 4096, 提示
    , % "不能用于颜色位置二值化模式, "
    . "因为分割后会导致位置错误", 3
    return
    }
    SetFormat, IntegerFast, d
    bg:=StrLen(StrReplace(wz,"0"))
    > StrLen(StrReplace(wz,"1")) ? "1":"0"
    s:="", i:=0, k:=nW*nH+1+CutLeft
    Loop, % w:=nW-CutLeft-CutRight
    {
    i++
    GuiControlGet, j,, % C_[k++]
    if (j=0 and A_Index<w)
    Continue
    v:=RegExReplace(wz,"m`n)^(.{" i "}).*","$1")
    wz:=RegExReplace(wz,"m`n)^.{" i "}"), i:=0
    While InStr(v,bg)
    {
    if (v~="^" bg "+n")
    v:=RegExReplace(v,"^" bg "+n")
    else if !(v~="m`n)[^n" bg "]$")
    v:=RegExReplace(v,"m`n)" bg "$")
    else if (v~="n" bg "+n$")
    v:=RegExReplace(v,"nK" bg "+n$")
    else if !(v~="m`n)^[^n" bg "]")
    v:=RegExReplace(v,"m`n)^" bg)
    else Break
    }
    if (v!="")
    {
    v:=Format("{:d}",InStr(v,"`n")-1) "." bit2base64(v)
    s.="`nText.=""|" color "$" v """`n"
    Comment:=SubStr(Comment, 2)
    }
    }
    Event:=cmd, Result:=s
    Gui, Hide
    return
    }
    wz:=Format("{:d}",InStr(wz,"`n")-1) "." bit2base64(wz)
    s:="`nText.=""|" color "$" wz """`n"
    if (cmd="AllAdd")
    {
    Event:=cmd, Result:=s
    Gui, Hide
    return
    }
    x:=px-ww+CutLeft+(nW-CutLeft-CutRight)//2
    y:=py-hh+CutUp+(nH-CutUp-CutDown)//2
    s:=StrReplace(s, "Text.=", "Text:=")
    s=
    (
    `; #Include

    t1:=A_TickCount
    %s%
    if (ok:=FindText(%x%-150000, %y%-150000, %x%+150000, %y%+150000, 0, 0, Text))
    {
    CoordMode, Mouse
    X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
    ; Click, `%X`%, `%Y`%
    }

    MsgBox, 4096, 提示, `% "找到:``t" Round(ok.MaxIndex()) "``n``n"
    . "时间:``t" (A_TickCount-t1) " 毫秒``n``n"
    . "位置:``t" X ", " Y "``n``n"
    . "结果:``t" (ok ? "成功 ! " Comment : "失败 !")

    for i,v in ok
    if (inW*nH)
    {
    GuiControlGet, i,, %v%
    GuiControl,, %v%, % i ? 0:100
    }
    else if (Modify and bg!="" and show[k])
    {
    ascii[k]:=!ascii[k]
    , c:=(ascii[k] ? "Black":"White")
    , ft_Gui("SetColor")
    }
    else
    {
    c:=cors[k], cors.SelPos:=k
    r:=(c>>16)&0xFF, g:=(c>>8)&0xFF, b:=c&0xFF
    GuiControl,, SelGray, % gray[k]
    GuiControl,, SelColor, %c%
    GuiControl,, SelR, %r%
    GuiControl,, SelG, %g%
    GuiControl,, SelB, %b%
    }
    Break
    }
    return
    }
    if (cmd="Apply")
    {
    if (!ft_FuncBind2)
    ft_FuncBind2:=Func("ft_Gui").Bind("ScreenShot")
    Gui, ft_Main:Default
    GuiControlGet, NowHotkey
    GuiControlGet, SetHotkey1
    GuiControlGet, SetHotkey2
    if (NowHotkey!="")
    Hotkey, *%NowHotkey%,, Off UseErrorLevel
    k:=SetHotkey1!="" ? SetHotkey1 : SetHotkey2
    if (k!="")
    Hotkey, *%k%, %ft_FuncBind2%, On UseErrorLevel
    GuiControl,, NowHotkey, %k%
    GuiControl,, SetHotkey1
    GuiControl, Choose, SetHotkey2, 0
    ;------------------------
    GuiControlGet, Myww
    GuiControlGet, Myhh
    if (Myww!=ww or Myhh!=hh)
    {
    Gui, Hide
    ww:=Myww, hh:=Myhh, ft_Gui("MakeSubPicWindow")
    Gui, ft_Main:Show, Center
    }
    return
    }
    if (cmd="ScreenShot")
    {
    Critical
    ScreenShot()
    Gui, ft_Tip:New
    ; WS_EX_NOACTIVATE:=0x08000000, WS_EX_TRANSPARENT:=0x20
    Gui, +LastFound +AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x08000020
    Gui, Color, Yellow
    Gui, Font, cRed s48 bold
    Gui, Add, Text,, 截屏成功
    WinSet, Transparent, 200
    Gui, Show, NA y0, 截屏提示
    Sleep, 1000
    Gui, Destroy
    return
    }
    }

    ft_Load_ToolTip_Text()
    {
    s=
    (LTrim
    Myww = 调整捕获范围的宽度
    Myhh = 调整捕获范围的高度
    AddFunc = 将 FindText() 函数代码一起复制
    NowHotkey = 当前的截屏热键
    SetHotkey1 = 第一优先级的截屏热键
    SetHotkey2 = 第二优先级的截屏热键
    Apply = 应用新的截屏热键和调整后的捕获范围值
    TestClip = 将文字代码复制到剪贴板然后测试
    Capture = 开始屏幕抓图
    CaptureS = 先恢复上一次的截屏到屏幕再开始抓图
    Test = 测试生成的代码是否可以找字成功
    Copy = 复制代码到剪贴板
    Reset = 重新读取原来的彩色图像
    SplitAdd = 使用黄色的标签来分割图像为单个的图像数据,添加到旧代码中
    AllAdd = 将文字数据整体添加到旧代码中
    ButtonOK = 生成全新的代码替换旧代码
    Close = 关闭窗口不做任何事
    Gray2Two = 灰度小于阈值的为黑色其余白色
    GrayDiff2Two = 某点与周围灰度之差大于差值的为黑色其余白色
    Color2Two = 指定颜色及相似色为黑色其余白色
    ColorPos2Two = 指定颜色及相似色为黑色其余白色,但是记录该色的位置
    ColorDiff2Two = 指定颜色及颜色分量小于允许值的为黑色其余白色
    SelGray = 选定颜色的灰度值 (0-255)
    SelColor = 选定颜色的RGB颜色值
    SelR = 选定颜色的红色分量
    SelG = 选定颜色的绿色分量
    SelB = 选定颜色的蓝色分量
    RepU = 撤销裁剪上边缘1个像素
    CutU = 裁剪上边缘1个像素
    CutU3 = 裁剪上边缘3个像素
    RepL = 撤销裁剪左边缘1个像素
    CutL = 裁剪左边缘1个像素
    CutL3 = 裁剪左边缘3个像素
    Auto = 二值化之后自动裁剪空白边缘
    RepR = 撤销裁剪右边缘1个像素
    CutR = 裁剪右边缘1个像素
    CutR3 = 裁剪右边缘3个像素
    RepD = 撤销裁剪下边缘1个像素
    CutD = 裁剪下边缘1个像素
    CutD3 = 裁剪下边缘3个像素
    Modify = 二值化后允许修改黑白点
    Comment = 识别文本 (包含在中),分割添加时也会分解成单个文字
    Threshold = 灰度阈值 (0-255)
    GrayDiff = 灰度差值 (0-255)
    Similar1 = 与选定颜色的相似度
    Similar2 = 与选定颜色的相似度
    DiffR = 红色分量允许的偏差 (0-255)
    DiffG = 绿色分量允许的偏差 (0-255)
    DiffB = 蓝色分量允许的偏差 (0-255)
    Bind1 = 绑定窗口从而可以后台查找这个窗口的图像
    Bind2 = 先修改窗口使它支持透明属性再绑定窗口
    )
    return, s
    }

    ft_EditEvents1()
    {
    static ft_FuncBind3:=Func("ft_Gui").Bind("ShowPic")
    ListLines, Off
    if (A_Gui="ft_Main" && A_GuiControl="scr")
    SetTimer, %ft_FuncBind3%, -150
    }

    ft_EditEvents2()
    {
    ListLines, Off
    if (A_Gui="ft_SubPic")
    ft_Gui("WM_LBUTTONDOWN")
    else
    ft_EditEvents1()
    }

    ft_ShowToolTip(cmd:="")
    {
    static
    ListLines, Off
    if (!ToolTip_Text)
    ToolTip_Text:=ft_Load_ToolTip_Text()
    if (!ft_FuncBind4)
    ft_FuncBind4:=Func("ft_ShowToolTip").Bind("ToolTip")
    if (!ft_FuncBind5)
    ft_FuncBind5:=Func("ft_ShowToolTip").Bind("ToolTipOff")
    if (cmd="ToolTip")
    {
    MouseGetPos,,, _TT
    WinGetClass, _TT, ahk_id %_TT%
    if (_TT = "AutoHotkeyGUI")
    ToolTip, % RegExMatch(ToolTip_Text
    , "im`n)^" CurrControl "Ks*=.*", _TT)
    ? StrReplace(Trim(_TT,"`t ="),"n","`n") : ""
    return
    }
    if (cmd="ToolTipOff")
    {
    ToolTip
    return
    }
    CurrControl:=A_GuiControl
    if (CurrControl!=PrevControl)
    {
    PrevControl:=CurrControl, _TT:=(CurrControl!="")
    SetTimer, %ft_FuncBind4%, % _TT ? -500 : "Off"
    SetTimer, %ft_FuncBind5%, % _TT ? -5500 : "Off"
    ToolTip
    }
    }

    ft_getc(px, py, ww, hh, ScreenShot:=1)
    {
    xywh2xywh(px-ww,py-hh,2*ww+1,2*hh+1,x,y,w,h)
    if (w<1 or h<1)
    return
    bch:=A_BatchLines
    SetBatchLines, -1
    if (ScreenShot)
    ScreenShot()
    cors:=[], k:=0
    lls:=A_ListLines=0 ? "Off" : "On"
    ListLines, Off
    Loop, % 2*hh+1
    {
    j:=py-hh+A_Index-1
    Loop, % 2*ww+1
    i:=px-ww+A_Index-1, cors[++k]:=ScreenShot_GetColor(i,j)
    }
    ListLines, %lls%
    cors.CutLeft:=Abs(px-ww-x)
    cors.CutRight:=Abs(px+ww-(x+w-1))
    cors.CutUp:=Abs(py-hh-y)
    cors.CutDown:=Abs(py+hh-(y+h-1))
    SetBatchLines, %bch%
    return, cors
    }

    ft_ShowScreenShot(Show:=1) {
    local ; 避免超级全局变量的影响
    static hBM, Ptr:=A_PtrSize ? "UPtr" : "UInt"
    Gui, ft_ScreenShot:Destroy
    if (hBM)
    DllCall("DeleteObject",Ptr,hBM), hBM:=""
    bits:=GetBitsFromScreen(0,0,0,0,0,zx,zy,zw,zh)
    if (!Show or !bits.1 or zw<1 or zh<1)
    return
    ;---------------------
    VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
    NumPut(zw, bi, 4, "int"), NumPut(-zh, bi, 8, "int")
    NumPut(1, bi, 12, "short"), NumPut(bpp:=32, bi, 14, "short")
    if (hBM:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
    , "int",0, Ptr "*",ppvBits, Ptr,0, "int",0, Ptr))
    DllCall("RtlMoveMemory",Ptr,ppvBits,Ptr,bits.1,Ptr,bits.2*zh)
    ;-------------------------
    win:=DllCall("GetDesktopWindow", Ptr)
    hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
    mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
    oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
    hBrush:=DllCall("CreateSolidBrush", "uint",0xFFFFFF, Ptr)
    oBrush:=DllCall("SelectObject", Ptr,mDC, Ptr,hBrush, Ptr)
    DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",zw, "int",zh
    , Ptr,mDC, "int",0, "int",0, "uint",0xC000CA)
    DllCall("SelectObject", Ptr,mDC, Ptr,oBrush)
    DllCall("DeleteObject", Ptr,hBrush)
    DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
    DllCall("DeleteDC", Ptr,mDC)
    DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
    ;-------------------------
    Gui, ft_ScreenShot:+AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
    Gui, ft_ScreenShot:Margin, 0, 0
    Gui, ft_ScreenShot:Add, Picture, x0 y0 w%zw% h%zh% +HwndhPic +0xE
    SendMessage, 0x172, 0, hBM,, ahk_id %hPic%
    Gui, ft_ScreenShot:Show, NA x%zx% y%zy% w%zw% h%zh%, Show ScreenShot
    }

    ft_Exec(s)
    {
    Ahk:=A_IsCompiled ? A_ScriptDir "AutoHotkey.exe":A_AhkPath
    s:=RegExReplace(s, "R", "`r`n")
    Try
    {
    shell:=ComObjCreate("WScript.Shell")
    oExec:=shell.Exec(Ahk " /f /ErrorStdOut *")
    oExec.StdIn.Write(s)
    oExec.StdIn.Close()
    }
    catch
    {
    f:=A_Temp "~test1.tmp"
    s:="`r`n FileDelete, " f "`r`n" s
    FileDelete, %f%
    FileAppend, %s%, %f%
    Run, %Ahk% /f "%f%",, UseErrorLevel
    }
    }

  3. 我认为的最好的源代码网页管理:

    ( 个人观点,有可能错误或者不可行 )

    特点1:实时保存和备份( 当保存失败时会在10秒钟以内显示失败原因提示框 )。

    特点2:支持源代码文件夹的批量操作
    (批量下载源代码、批量上传源代码、批量权限管理、批量删除、批量收藏、批量备注)

    特点3:源代码显示正确并且优美(显示优美就是看上去身心愉悦,建议采用微软的代码显示风格)

    特点4:具有其他编程源代码托管和研发协作平台官方网站的优点
    (

    https://code.google.com

    https://code.opensource.huaweicloud.com/
    https://code.aliyun.com/
    http://xiaolvyun.baidu.com/
    https://dev.tencent.com/
    https://github.com/
    https://gitee.com/
    https://coding.net/
    https://coding.net/
    https://bitbucket.org/product/
    https://www.codeproject.com/
    https://sourceforge.net/
    https://www.csdn.net/
    )

    特点5:云上(在线)远程新建源代码、编辑、调试、开发、备份,
    所有编程过程都联网在网页中实时进行,线上开发。
    本地电脑中只有硬件、操作系统和浏览器,所有IDE相关资源都在遥远的服务器集群上。

个人中心
今日签到
有新私信 私信列表
搜索