ahk快速宏工具

作为一名ahk半新不老手,不怎么会搞dll和message什么的,经常用到点击和按键,所以宏工具真的很舒服,但是宏工具录制的时候总是根据鼠标移动生成无用代码,就很烦,所以考虑到又得简单,也不能要垃圾代码,还是得用生成代码的方式来做一些简单的宏.

如果有老哥知道怎么录制宏的时候不记录鼠标的轨迹一定要告诉我哈哈,之前用个po那个录ahk宏的软件

另一方面,宏工具还有个问题就是录制的过程中必须真的点击真的按键,比如我做个报印花税的宏,真的点下去可能会带来一些报错的风险,用我这个工具可以只找点生成代码但是不实际点下去

目前第一个测试版没有加入按键的功能,也没有加入一些快速输入循环之类的快捷方式

后期准备加入一个快速生成三元表达式的的功能

使用方法,具体的看后期更新的help

在工具生成代码,简单修改一下,按一下copy就自动跳编辑器,也可以自动保存一个ahk文件

ahk快速宏工具

里面用到的函数有一些是我自己用的,如果有需求的话我单独放上来,主要是提供一个工具的思路,生成的格式化代码还是改成自己顺手的好

c:=s:=a:=0
Gui +E0x08000000 +AlwaysOnTop
Gui Destroy
Gui Add, Text, w-2 h-2 section
Gui add, DropDownList,x+5 w120 vwhat ,复制类和进程名|Waitact|ControlClick||Click|winact|#IfWinActive|GroupAdd|截图找点|复制选中|复制滚动
Gui add, DropDownList, x+5 w60 vWhich ,SciTE|code||

For k,v in ["Help","Copy","找点依次点击","gui模板","保存"]
    Gui Add, Button, x+5 w50 g%v%,%v%

; Gui Add, Text, section
Gui Add, Edit ,xs-4 w500 h300 Hwndhedit vedit1,
Gui submit, NoHide
Gui Show, ,快速宏工具
return

#g::
    Gui submit, NoHide
    Gosub GetCode
return

SwitchEditor(Which){
    switch Which
    {
    case "SciTE":
        WinActivate ahk_class SciTEWindow
    case "code":
        WinActivate ahk_exe code.exe
    return
}
}

GetCode:
    Content:=""
    MouseGetPos, xpos, ypos
    WinGetTitle, Title, A
    WinGet,ProcessName,ProcessName ,A
    WinGetClass, class, A
    switch what
    {
    case "复制类和进程名":
        Clipboard=
        (
            ahk_exe %ProcessName% ahk_class %class%

        )

    case "ClickPosition":
        Content=
        (
            ClickPosition(%xpos%, %ypos%, 1, 0, "Screen", true)
        )
    case "Waitact":
        Content=
        (
            Waitact("%Title%")
        )
    case "ControlClick":
        Content=
        (
            ControlClick,x%xpos% y%ypos%,%Title% ahk_exe %ProcessName%
        )
    case "Click":
        Content=
        (
            Click,%xpos%,%ypos%
        )
    case "winact":
        Content=
        (
            winact("%Title%")
        )
    case "#IfWinActive":
        Content=
        (
            #IfWinActive, %Title% ahk_exe %ProcessName%

        #IfWinActive
    )
case "GroupAdd":
    Content=
    (
        GroupAdd, ,ahk_exe %ProcessName%
    )

case "截图找点":
    c+=1
    if (c=1)
    {
        x1:=xpos
        y1:=ypos
        MsgBox,,Select the Second point,The First point is %x1% `, %y1%,1
    }
    if (c=2)
    {
        x2:=xpos
        y2:=ypos
        w:=x2-x1
        h:=y2-y1
        c:=0
        Content=
        (
            ImagePutClipboard([ %x1%,%y1%,%w%,%h%])	
        )
        ; ScreenCapture(%x1% "|" %y1% "|" %w% "|" %h%, 1, , "Clipboard")
        MsgBox,,Paste,The Second point is %x2% `, %y2% and w is %w% `, h is %h%,1
    }

case "复制选中":
    s+=1
    if (s=1)
    {
        x1:=xpos
        y1:=ypos
        MsgBox,,Select the Second point,The First point is %x1% `, %y1%,1
    }
    if (s=2)
    {
        x2:=xpos
        y2:=ypos
        s:=0
        Content=
        (
            CopySelect(%x1%,%y1%,%x2%,%y2%,OutputVar)
        )
        MsgBox,,Paste,The Second point is %x2% `, %y2%,1
    }

case "复制滚动":	
    a+=1
    if (a=1)
    {
        x1:=xpos
        y1:=ypos
        MsgBox,,Select the Second point,The First point is %x1% `, %y1%,1
    }

    if (a=2)
    {
        x2:=xpos
        y2:=ypos
        MsgBox,,Select the Third point,The Second point is %x2% `, %y2%,1
    }
    if (a=3)
    {
        x3:=xpos
        y3:=ypos
        a:=0
        Content=
        (
            CopyScrollArea(%x1%,%y1%,%x2%,%x3%,%y3%)
        )
        MsgBox,,Paste,The Third point is %x3% `, %y3%,1
    }
}
AppendEdit(hedit, Content)
Return

Copy:
    GuiControlGet,test,,edit1
    Clipboard:=test
    ClipWait,1,1
    SwitchEditor("code")
Return

Help:
    MsgBox,
    (
        先选择要用的模式,然后比如找点就是对着点按win+g,比如要找窗口也是到哪个窗口按就行,然后自动生成代码,
        比如你想做一个自动报印花税零申报的,就是找每个需要点击的坐标按下win+g生成代码,
        全部搞完后按复制即可复制到你需要的编辑器去在边上的可以选择复制后切换的编辑器
        说一下三个功能复杂的功能,分别是
        1.截图找点,找好开始和结束两个点,生成截图代码
        2.两个点生成复制选中区域代码
        3.三个点生成复制一个需要滚轮区域的代码
    )

Return

gui模板:
Content=
(
    Gui Add, Text, w-2 h-2 section
    Gui Add, Text, section, Test
    Gui Add, Edit, ys-4
    Gui Add, Button, ys-4, Text
    Gui Add, Text, w-2 h-2 xs
    For k,v in ["a",]
        Gui Add, Button, x+5 w50 g`%v`%,`%v`%
)
AppendEdit(hedit, Content)
Return

找点依次点击:
    Content=
    (
        t1:=A_TickCount, X:=Y:=""
        Text:=
        ok:=FindText("wait",3, 0,0,0,0,0,0,Text) ; 等待3秒等图像出现
        if (ok:=FindText(X, Y, 1700-150000, 311-150000, 1700+150000, 311+150000, 0, 0, Text))
        {
            FindText().Click(X, Y, "L")
        }

        for i,v in ok
        {		
            FindText().Click(ok[i].x, ok[i].y, "L")
        )
        AppendEdit(hedit, Content)
        Return

        保存:
            GuiControlGet,test,,edit1
            Clipboard:=test
            ClipWait,1,1
            FileSelectFolder, OutputVar,, 3
            FileAppend,%Clipboard%,%OutputVar%\%A_Now%.ahk,UTF-8-RAW
            ; MsgBox,%OutputVar% . "\test.txt"
        Return

ahk快速宏工具

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

用简短易记的用户名和密码连接群晖NAS的SFTP文件服务 2022.04.08

2022-4-8 16:39:20

其他案例

[第十七关]如何定时清理指定程序占用内存或键盘鼠标指定时间内无操作执行指定操作?

2022-4-9 11:09:38

6 条回复 A文章作者 M管理员
  1. dbgba

    少了AppendEdit()函数

    • 僵尸牌木乃伊

      AppendEdit(hEdit, text)
      {
      text .= “`r`n”
      SendMessage, 0xB1, -2, -1,, ahk_id %hEdit% ; EM_SETSEL
      SendMessage, 0xC2, 0, &text,, ahk_id %hEdit% ; EM_REPLACESEL
      SendMessage, 0x115, 7, 0,, ahk_id %hEdit% ; WM_VSCROLL
      }

    • 而今迈步从头越

      ?确实分享的时候没加,我自用就放在lib了,就是僵尸老哥发的那个

  2. AndImissyou

    牛掰

  3. 琪cc

    ? 想法很牛逼

个人中心
购物车
优惠劵
有新私信 私信列表
搜索