Autohotkey和Windows 10:如何获取当前资源管理器路径 [英] Autohotkey and Windows 10: How to get current explorer path

查看:329
本文介绍了Autohotkey和Windows 10:如何获取当前资源管理器路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自动热键版本:1.0.48.05(因为我坚​​持使用activeaid). 读取当前路径的脚本如下(并一直运行到Win 7).

I use autohotkey version: 1.0.48.05 (because I stick with activeaid). The script to read the current path is as follows (and worked until Win 7).

; Get full path from open Explorer window
WinGetText, FullPath, A

; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")

我如何怀疑在切换到Win10时似乎也切换了语言. 如果我使用MsgBox清除%FullPath%,然后再使用 WinGetText,FullPath,A MsgBox%FullPath% 我看到其他字符串(以CR分隔): 地址:V:\ Vertrieb \ Prospects \ MyFile

How I suspect that while switching to Win10 it seems that I also switched the language. If I MsgBox out the %FullPath% before cleaning with WinGetText, FullPath, A MsgBox %FullPath% I see amongst other strings (obvoíously separated by CR): Adresse: V:\Vertrieb\Prospects\MyFile

所以我该如何调整正则表达式以提取字符串呢?

so how do I need to adjust the regexp to extract that very string!

最诚挚的问候 汉尼斯

推荐答案

#If WinActive("ahk_class CabinetWClass") ; explorer

    F1:: MsgBox, % GetActiveExplorerPath()

    ; or
    F2:: 
        ActiveExplorerPath := GetActiveExplorerPath()
        MsgBox, % ActiveExplorerPath
    return

#If

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925

GetActiveExplorerPath() {
    explorerHwnd := WinActive("ahk_class CabinetWClass")
    if (explorerHwnd)
    {
        for window in ComObjCreate("Shell.Application").Windows
        {
            if (window.hwnd==explorerHwnd)
                return window.Document.Folder.Self.Path
        }
    }
}

这篇关于Autohotkey和Windows 10:如何获取当前资源管理器路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆