吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2792|回复: 26
上一主题 下一主题
收起左侧

[其他原创] 用AutoHotKey编写的应用启动器

[复制链接]
跳转到指定楼层
楼主
CharlesCTy 发表于 2025-7-8 22:38 回帖奖励
本帖最后由 CharlesCTy 于 2025-7-8 23:02 编辑

主要功能是帮你快速打开你需要的软件,所以叫做启动器(launcher),相当于简易版的Listary

下载方法:

  1. 确保你的电脑上安装了AutoHotKey这个软件,可以从官网链接下载安装包
  2. 把源代码保存为一个叫做 Launcher.ahk 的文件
  3. 双击运行(注意,不会显示窗口,只会产生托盘图标,等你按下快捷键才会出现窗口)

使用方法:

  1. 按快捷键 Ctrl + Alt + L,会弹出一个搜索框。
  2. 打字搜索:比如你想开 EmEditor,就直接打 emed 就行,大小写无所谓,甚至打 em 就能看到了。它会把名称匹配的程序都列出来。
  3. 选择启动:选中你想开的那个,用鼠标双击就行。

实现非常简单,每次你按快捷键,它都会把你电脑的开始菜单、Program Files这些地方的软件和快捷方式都扫一遍,你打字的时候,它就在这些记录里帮你找。没做什么优化,响应速度还行,能用。

完整代码如下:

#NoEnv  ; Recommended for performance and compatibility
#SingleInstance Force  ; Ensures only one instance runs
SetWorkingDir %A_ScriptDir%  ; Consistent starting directory


; Global variables
global programList := []
global maxResults := 15
; GUI control variables are automatically global within their GUI's context,
; but explicitly declaring them can sometimes aid clarity.
global SearchBox
global ResultList


; Main hotkey (Ctrl+Alt+L)
^!L::ShowLauncher()


; ==================== FUNCTIONS ====================


InitializePrograms() {
    global programList ; Ensure we are modifying the global variable
    programList := []
    
    ; Scan common program locations
    ScanDirectory(A_StartMenu, 2)
    ScanDirectory(A_StartMenuCommon, 2)
    ScanDirectory("C:\Program Files", 1)
    ScanDirectory("C:\Program Files (x86)", 1)
    ScanDirectory("C:\Programs", 2)
}


ScanDirectory(directory, maxDepth, currentDepth := 0) {
    global programList
    if !FileExist(directory)
        return
    
    ; Find shortcuts and executables
    Loop, Files, %directory%\*.lnk, F
    {
        program := {}
        program.name := RegExReplace(A_LoopFileName, "\.lnk$")
        program.path := A_LoopFileFullPath
        program.type := "shortcut"
        programList.Push(program)
    }
    
    Loop, Files, %directory%\*.exe, F
    {
        program := {}
        program.name := RegExReplace(A_LoopFileName, "\.exe$")
        program.path := A_LoopFileFullPath
        program.type := "executable"
        programList.Push(program)
    }
    
    ; Recurse through subdirectories up to max depth
    if (currentDepth < maxDepth) {
        Loop, Files, %directory%\*, D
        {
            ScanDirectory(A_LoopFileFullPath, maxDepth, currentDepth + 1)
        }
    }
}


ShowLauncher() {
    InitializePrograms()
    
    ; Create GUI with a name
    Gui, Launcher:New, +AlwaysOnTop +ToolWindow, Quick Launcher
    Gui, Launcher:Color, FFFFFF
    Gui, Launcher:Font, s11, Segoe UI
    Gui, Launcher:Add, Edit, w500 h30 vSearchBox gUpdateSearch
    Gui, Launcher:Add, ListView, r%maxResults% w500 NoSort -Multi vResultList gResultListClick, Name|Path
    LV_ModifyCol(1, "400") ; Adjust column widths
    LV_ModifyCol(2, "AutoHdr")
    
    ; Position in center-top of screen
    Gui, Launcher:Show, Center y200
    
    ; Focus on search box
    GuiControl, Launcher:Focus, SearchBox
}


UpdateSearch() {
    ; _FIX_: Set the default GUI for this thread
    Gui, Launcher:Default
    
    Gui, Submit, NoHide
    GuiControlGet, query, , SearchBox
    
    ; Clear previous results
    LV_Delete()
    
    if (Trim(query) = "")
        return
    
    ; Search through program list
    matches := []
    query := Format("{:L}", query) ; Convert to lowercase
    
    for _, program in programList {
        programName := Format("{:L}", program.name)
        if (InStr(programName, query)) {
            matches.Push(program)
        }
    }
    
    ; Display results
    for i, match in matches {
        if (i > maxResults)
            break
        LV_Add("", match.name, match.path)
    }
    
    ; Select first result
    if (LV_GetCount() > 0)
        LV_Modify(1, "Select Focus")
}


ResultListClick() {
    ; This function is called by a GUI event, so context is already set.
    if (A_GuiEvent = "DoubleClick") {
        LaunchSelectedProgram()
    }
}


LaunchSelectedProgram() {
    ; _FIX_: Set the default GUI for this thread
    Gui, Launcher:Default


    row := LV_GetNext()
    if (row > 0) {
        LV_GetText(name, row, 1)
        LV_GetText(path, row, 2)
        Gui, Destroy
        Run, %path%
    }
}


; ==================== CONTROLS ====================
#IfWinActive Quick Launcher
    ; _FIX_: Use $ prefix to hook the keypress before the Edit control gets it.
    $Up::
        ; _FIX_: Set the default GUI context for this hotkey thread.
        Gui, Launcher:Default
        
        if (LV_GetCount() = 0)
            return
        row := LV_GetNext()
        if (row = 0)
            LV_Modify(LV_GetCount(), "Select Focus") ; Select last if nothing is selected
        else if (row > 1)
            LV_Modify(row - 1, "Select Focus")
        else
            LV_Modify(LV_GetCount(), "Select Focus") ; Wrap to bottom
    return


    $Down::
        ; _FIX_: Set the default GUI context for this hotkey thread.
        Gui, Launcher:Default


        if (LV_GetCount() = 0)
            return
        row := LV_GetNext()
        if (row = 0)
            LV_Modify(1, "Select Focus") ; Select first if nothing is selected
        else if (row < LV_GetCount())
            LV_Modify(row + 1, "Select Focus")
        else
            LV_Modify(1, "Select Focus") ; Wrap to top
    return


    $Enter::
        LaunchSelectedProgram()
    return


    Escape::
        Gui, Launcher:Destroy
    return
#IfWinActive

免费评分

参与人数 7吾爱币 +12 热心值 +6 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
WXJYXLWMH + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
hiahia + 1 + 1 我很赞同!
xuxian20160401 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
wapjsx + 1 + 1 学过,但已经忘记得差不多了!
sakura485586 + 1 用心讨论,共获提升!
puyuancheng + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
冥界3大法王 发表于 2025-7-9 11:04
@CharlesCTy
或许 这样更进一步
1.搞个简单的设置界面用于记录用户热键的按键(譬如鼠标、键盘)保存成INI
2.将快速启动啊,热字符串啊,识别为邮件链接啊,鼠标手势啊作为预定义项

不过感觉除了热键优势外,还是不地PowerPro这类的工具
不过脚本随时修改确实方便些。
推荐
amouer 发表于 2025-7-9 09:27
建议楼主再增加一个自定义扫描目录,增加扫描目录的深度,现在电脑用了许多绿软,更多的用这里的工具。

我自己实在没有精力开发了,十分赞赏楼主的钻研精神!!谢谢
3#
Lcbery 发表于 2025-7-9 06:35
4#
CheungKong 发表于 2025-7-9 08:28
支持一下。
5#
husay 发表于 2025-7-9 08:43
越来越自动化了
6#
clearup9 发表于 2025-7-9 08:50
学习了,不错,几年前用过这个软件,但是没搂住研究的这么深入!
7#
gyzhangqm 发表于 2025-7-9 08:57
ahk是好软件,只是没有linux版本
8#
joblee 发表于 2025-7-9 09:10
如果有张软件运行截图就好了
9#
ysjd22 发表于 2025-7-9 09:45
如果能做成轮盘式的最好。
10#
chenghua0322 发表于 2025-7-9 10:13
如果能做成轮盘式的就很好
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-4-17 06:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表