; ahk_group ExplorerGroup
GroupAdd, ExplorerGroup, ahk_class ExploreWClass
GroupAdd, ExplorerGroup, ahk_class CabinetWClass
; ahk_group DesktopGroup
GroupAdd, DesktopGroup, ahk_class Progman
GroupAdd, DesktopGroup, ahk_class WorkerW
; ahk_group ExplorerDesktopGroup
GroupAdd, ExplorerDesktopGroup, ahk_group ExplorerGroup
GroupAdd, ExplorerDesktopGroup, ahk_group DesktopGroup
RETURN ; === end of auto-execute section ===
#IfWinActive ahk_group ExplorerDesktopGroup
F1::
WinGet, active_id, ID, A
InputBox, name, Create a New Text Document, Enter a name:,, 300, 120
If !ErrorLevel
{
WinActivate, ahk_id %active_id%
IfWinActive ahk_group DesktopGroup ; desktop
{
FileAppend,, %A_Desktop%\%name%.txt
Run, %A_Desktop%\%name%.txt
}
else
IfWinActive ahk_group ExplorerGroup ; explorer
{
FolderPath := GetActiveExplorerPath()
FileAppend,, %FolderPath%\%name%.txt
Run, %FolderPath%\%name%.txt
}
}
return
#IfWinActive
;* ========= FUNCTION ===================
; 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
}
}
}
}