autohotkey switching within applications

class QdirManager {
    ppid := -1
    ppath := ""
    __New(pathIn) {
        this.ppath := pathIn
    }
    __Delete() {
    }
    init() {
        Run(this.ppath, , , &ppidTmp)
        this.ppid := ppidTmp
        ; waiting window initialization
        Loop 20 {
            Sleep(50)
            if (WinExist("ahk_pid " this.ppid) > 0) {
                break
            }
        }
        WinActivate("ahk_pid " this.ppid)
    }
    bringFront() {
        ; ; MsgBox(WinExist("ahk_pid " this.ppid))
        ; if (WinExist("ahk_pid " this.ppid)) {
        ;     WinActivate("ahk_pid " this.ppid)
        ; }
        oList := WinGetList("ahk_exe" this.ppath, , ,)    ; ahk_id
        if (oList.Length >= 1) {
            this.ppid := WinGetPID("ahk_id " oList[1])
            WinActivate("ahk_pid " this.ppid)
        }
        else {
            this.init()
        }

        ; flash across
        myGui := Gui("+AlwaysOnTop -Caption +LastFound -SysMenu +ToolWindow -DPIScale +E0x20", "myGui")
        WinSetTransparent(100, myGui)
        myGui.BackColor := "EEAA99"
        myGui.Show("x0 y0 w" . A_ScreenWidth - 300 . " h" . A_ScreenHeight - 300)
        Sleep(100)
        myGui.Destroy()
    }
}

global glb_qdirManager1 := QdirManager("D:\tool\Q-Dir-AA\Q-Dir_x64.exe")
global glb_qdirManager2 := QdirManager("D:\tool\Q-Dir-AB\Q-Dir_x64.exe")
global glb_qdirManager3 := QdirManager("C:\Program Files (x86)\UltraExplorer\UltraExplorer.exe")
#q:: {
    glb_qdirManager1.bringFront()
}
#w:: {
    glb_qdirManager2.bringFront()
}
#e:: {
    glb_qdirManager3.bringFront()
}


win_No(pp) {
    ; pp := "D:\Program Files\Notepad++\notepad++.exe"
    winlist := WinGetList("ahk_exe " . pp)
    if (winlist.Length = 0) {
        Run(pp, , , &ppidTmp)
        ; waiting window initialization
        Loop 20 {
            Sleep(50)
            if (WinExist("ahk_pid " ppidTmp) > 0) {
                break
            }
        }
        WinActivate("ahk_pid " ppidTmp)
    }
    else {
        WinActivate("ahk_exe " . pp)
    }

    ; flash across
    myGui := Gui("+AlwaysOnTop -Caption +LastFound -SysMenu +ToolWindow -DPIScale +E0x20", "myGui")
    WinSetTransparent(100, myGui)
    myGui.BackColor := "EEAA99"
    myGui.Show("x0 y0 w" . A_ScreenWidth - 300 . " h" . A_ScreenHeight - 300)
    Sleep(100)
    myGui.Destroy()
}
#1:: win_No("C:\Program Files\Google\Chrome\Application\chrome.exe")
#2:: win_No("D:\Programs\Microsoft VS Code\Code.exe")
#3:: win_No("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")

; F4:: ExitApp 3333

in q-dir, press F3 to search with everything

F3:: {
    if (WinActive("ahk_exe Q-Dir_x64.exe")) {
        Send("{CtrlDown}{ShiftDown}c{ShiftUp}{CtrlUp}")
        ss := Trim(A_Clipboard, "`\")
        cmd := "D:\Program` Files\Everything\Everything.exe -path " . ss
        Run(cmd)    ; MsgBox(cmd)
    }
    else {
        Send("F3")
    }
    return
}

posted on 2023-01-05 21:56  yusisc  阅读(24)  评论(0编辑  收藏  举报

导航