#Persistent
#SingleInstance force
;作者:Quant
;时间:2017年1月6日15:44:27
;功能:在资源管理器中,按热键 win+1/2/3获取目录/文件名/全路径
#1::
clipboard :=GetFolder(GetPath())
return
#2::
clipboard :=GetFilename(GetPath())
return
#3::
clipboard :=GetPath()
return
GetFolder(txt)
{
SplitPath, txt,, o
return o
}
GetFilename(txt)
{
SplitPath, txt, o
return o
}
;在当前资源管理器窗口中,获取选中文件路径
GetPath(hwnd="")
{
ComObjError(false)
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process != "explorer.exe")
return
if (class ~= "Progman|WorkerW") {
ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
Loop, Parse, files, `n, `r
ToReturn .= A_Desktop "\" A_LoopField "`n"
}
else if (class ~= "(Cabinet|Explore)WClass")
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
;~ MsgBox % window.LocationURL
}
for item in sel
ToReturn .= item.path "`n"
}
return Trim(ToReturn,"`n")
}
如果只是获取当前打开的文件夹窗口的路径,其实还有更好的办法,最简单的其实是 获取标题的方式

WinGetActiveTitle, Title
MsgBox, The active window is "%Title%".
PS. 长文件名可能被截断,但基本够用。

#z::
MsgBox % getExplorer()
return
getExplorer()
{
Loop,9
{
ControlGetText, folder, ToolbarWindow32%A_Index%, ahk_class CabinetWClass
} until (InStr(folder,"地址"))
folder:=StrReplace(folder,"地址: ","")
if (folder="计算机" )
folder:="c:\"
return folder
}
http://bbs.deepin.org/thread-1785189-1-1.html TC 的强大让我离不开它,不过我还是不能抛弃 Explorer ,于是就有了以下这个脚本。 |