using windows key+e to open total commander

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
mrchrister
Junior Member
Junior Member
Posts: 8
Joined: 2009-04-14, 16:45 UTC

using windows key+e to open total commander

Post by *mrchrister »

hey guys,
I want to use the winkey-e shortcut to launch total commander. I'm so used to this shortcut, it would be great to get it working this way.

I already started a discussion about this over here: http://www.gameex.info/forums/index.php?showtopic=7268&st=0
but we didnt come to a conclusion.

Is there a good ahk scripter to help me out with this problem?
I'm using the following script:

Code: Select all

#e::
Run C:\totalcmd\TOTALCMD.EXE,,, NewPid
WinActivate, ahk_pid%NewPid%
Return
but the total commander window always hides behind the active window. this only happens with winkey-e not with winkey-q for example. so it seems to be a conflict with the windows explorer shortcut.

Did anybody try yet to use winkey-e with tc?
User avatar
Stance
Power Member
Power Member
Posts: 1079
Joined: 2005-03-29, 06:26 UTC

Post by *Stance »

mrchrister wrote:Did anybody try yet to use winkey-e with tc?
Source: zu ordner navigieren durch direkte eingabe
mrchrister wrote:

Code: Select all

#Persistent

SetTimer subTimer, 250

subTimer:
	if WinActive( "ahk_class TTOTAL_CMD" )
	{
		ControlGetText sPath, TMyPanel2
		StringMid sPath, sPath, 1, StrLen(sPath) -1
		WinGetTitle sWindowTitle
		if ( sWindowTitle != sPath )
			WinSetTitle %sPath%
	}
	Return
#e::Run %comspec% /c ""C:\Program files\totalcmd\TOTALCMD.lnk"
mrchrister
Junior Member
Junior Member
Posts: 8
Joined: 2009-04-14, 16:45 UTC

Post by *mrchrister »

lol, thanks for linking me back to my own topic!
the method i posted in th german thread works.
But you see the cmd window open for a second because of the comspec command.
If I try to run it without comspec the new instance of total commander hides behind the active window...
I'm trying to find a way to activate total commander through winkey-e without the need of the black cmd window appear
User avatar
Stance
Power Member
Power Member
Posts: 1079
Joined: 2005-03-29, 06:26 UTC

Post by *Stance »

Sorry, mrchrister. Beta-release of Version 7.5...
Let's take a look at the bright side: Redundancy is worth to be copied :P
User avatar
mhe
Junior Member
Junior Member
Posts: 70
Joined: 2003-02-16, 15:09 UTC

Post by *mhe »

Im no master of autohotkey, but i think your winactivate command gets sent before there is any window to activate.

I put a winwait command into it and it seems to work, at least for me.

Code: Select all

#e:: 
Run C:\totalcmd\TOTALCMD.EXE,,, NewPid
winwait, ahk_pid %newpid%
WinActivate, ahk_pid%NewPid%
Return
mrchrister
Junior Member
Junior Member
Posts: 8
Joined: 2009-04-14, 16:45 UTC

Post by *mrchrister »

stance: redundancy is very important for people like me! i need to read things at least twice to pay attention to them...
mhe: thanks, wonderful!
thats what was missing. your assumptions were correct ;)
now it works as it is supposed to!
xnappo
New Member
New Member
Posts: 1
Joined: 2021-11-03, 13:10 UTC

Re: using windows key+e to open total commander

Post by *xnappo »

Replying to a 12 year old thread, but another way to do this is to use Microsoft Powertoys 'Keyboard Manager' to remap a shortcut.

I have my TC in taskbar slot 1, so I remapped Win-E to Win-1, but you could also make a shortcut with a hotkey like 'Ctrl-Alt-E' and remap Win-E to that.

xnappo
pplupo
Member
Member
Posts: 102
Joined: 2019-12-02, 16:26 UTC
Location: Canada
Contact:

Re: using windows key+e to open total commander

Post by *pplupo »

I wrote one today, unaware of this thread. Then I came here to share it but decided to search for one first. Ended up sticking with mine, though. Why?
Because if you hit Win+E while on a Windows Explorer window, it closes the Windows Explorer window and opens TC with the same directory open on a tab.
Here goes the code:

Code: Select all

#NoTrayIcon
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
#SingleInstance Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#e::

; Windows 7
#IfWinActive ahk_class ExploreWClass
; Windows 10
#IfWinActive ahk_class CabinetWClass
; Alt+E open current Explorer in Total Commander
WinGet, winid
Path := uriDecode(WindowsExplorerLocationByCOM(%winid%))
Run, "C:\totalcmd\TOTALCMD64.EXE" /O /T "%Path%"
if Path {
   WinClose, %winid%
}
Return

;[Detect current windows explorer location - Ask for Help - AutoHotkey Community](https://www.autohotkey.com/board/topic/70960-detect-current-windows-explorer-location/)
WindowsExplorerLocationByCOM(HWnd="")
{
   If ( HWnd = "" )
      HWnd := WinExist("A")
   WinGet Process, ProcessName, ahk_id %HWnd%
   If ( Process = "explorer.exe" )
   {
      WinGetClass Class, ahk_id %HWnd%
      If ( Class ~= "Progman|WorkerW" )
         Location := A_Desktop
      Else If ( Class ~= "(Cabinet|Explore)WClass" )
      {
         For Window In ComObjCreate("Shell.Application").Windows
            If ( Window.HWnd == HWnd )
            {
               URL := Window.LocationURL
               Break
            }
         StringTrimLeft, Location, URL, 8 ; remove "file:///"
         StringReplace Location, Location, /, \, All
      }
   }
   Return Location
}

;[Great AutoHotkey script to URL Encode/Decode and parse URL parameters : AutoHotkey](https://www.reddit.com/r/AutoHotkey/comments/4py9e7/great_autohotkey_script_to_url_encodedecode_and/)
;***********https://autohotkey.com/board/topic/17367-url-encoding-and-decoding-of-special-characters/******************* 
uriDecode(str) {
    Loop
 If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
    StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
    Else Break
 Return, str
}
Rykari
Junior Member
Junior Member
Posts: 10
Joined: 2019-05-24, 13:43 UTC

Re: using windows key+e to open total commander

Post by *Rykari »

pplupo wrote: 2023-02-01, 03:52 UTC I wrote one today, unaware of this thread. Then I came here to share it but decided to search for one first. Ended up sticking with mine, though. Why?
Because if you hit Win+E while on a Windows Explorer window, it closes the Windows Explorer window and opens TC with the same directory open on a tab.
Here goes the code:

Code: Select all

#NoTrayIcon
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
#SingleInstance Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#e::

; Windows 7
#IfWinActive ahk_class ExploreWClass
; Windows 10
#IfWinActive ahk_class CabinetWClass
; Alt+E open current Explorer in Total Commander
WinGet, winid
Path := uriDecode(WindowsExplorerLocationByCOM(%winid%))
Run, "C:\totalcmd\TOTALCMD64.EXE" /O /T "%Path%"
if Path {
   WinClose, %winid%
}
Return

;[Detect current windows explorer location - Ask for Help - AutoHotkey Community](https://www.autohotkey.com/board/topic/70960-detect-current-windows-explorer-location/)
WindowsExplorerLocationByCOM(HWnd="")
{
   If ( HWnd = "" )
      HWnd := WinExist("A")
   WinGet Process, ProcessName, ahk_id %HWnd%
   If ( Process = "explorer.exe" )
   {
      WinGetClass Class, ahk_id %HWnd%
      If ( Class ~= "Progman|WorkerW" )
         Location := A_Desktop
      Else If ( Class ~= "(Cabinet|Explore)WClass" )
      {
         For Window In ComObjCreate("Shell.Application").Windows
            If ( Window.HWnd == HWnd )
            {
               URL := Window.LocationURL
               Break
            }
         StringTrimLeft, Location, URL, 8 ; remove "file:///"
         StringReplace Location, Location, /, \, All
      }
   }
   Return Location
}

;[Great AutoHotkey script to URL Encode/Decode and parse URL parameters : AutoHotkey](https://www.reddit.com/r/AutoHotkey/comments/4py9e7/great_autohotkey_script_to_url_encodedecode_and/)
;***********https://autohotkey.com/board/topic/17367-url-encoding-and-decoding-of-special-characters/******************* 
uriDecode(str) {
    Loop
 If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
    StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
    Else Break
 Return, str
}
I've built upon this logic & updated for v2

First, we need to schedule a task in windows task scheduler so that the script is available on launch:
  • Click Task Scheduler (Local) > On the right click Create Task
  • Tick Run when user is logged on
  • [Optional] [Required for startup_task.ahk to run properly] Tick Run with Highest permissions
  • Navigate to actions tab > add startup_task.ahk
  • Navigate to triggers add new > click dropdown box > at logon > for all users or your own

startup_task.ahk:

Code: Select all

; #NoTrayIcon ; personal preference. You can enable this if you wanna but I like knowing what's running
Persistent true
#SingleInstance Force
TrayTip("The script is now active.","Script Running")
#ErrorStdOut
DetectHiddenWindows True

#Include src/ids.ahk ; Variables, Constants, ids etc
#Include src/general_functions.ahk ; general functions / helper functions etc
#Include src/win_e_key_for_tc.ahk ; Now you can add as many specialised functions as you want


#e::WindowsKeyForTC(TC_PATH) ; TC_PATH in ids.ahk
^!+9::ExitApp
^!+8::Reload
^!+7::OpenScriptLocationInTC(TC_PATH)
^!+6:: MsgBox get_ahk_class_of_currently_active_window()
^!+5::OpenWindowSpy(WINSPY_PATH)
src/ids.ahk is self explanatory. Just add your variables, IE TC_PATH := "C:\PATH\TO\TC.EXE"

src/general_functions.ahk:

Code: Select all

; Open the running script in TC
OpenScriptLocationInTC(path) {
    TC_EXE := GetFileNameFromPath(path)
    scriptDir := SubStr(A_ScriptDir, 1)
    Run(path . " /O /T " . scriptDir)
    WinWait("ahk_exe " . TC_EXE)
    WinActivate("ahk_exe " . TC_EXE)
}

OpenWindowSpy(path) {
    Run(path)
}

get_ahk_class_of_currently_active_window()
{
    ; Get the class of the active window
    activeClass := WinGetClass("A")
    return activeClass
} 

GetFileNameFromPath(path) {
    SplitPath(path, &name)
    return name
}
finally your specialised functions:

src:/win_e_key_for_tc.ahk

Code: Select all

; For this to work as intended, set MinimizeOnClose=3, TrayIcon=1 and onlyonce=1 in the wincmd.ini

WindowsExplorerLocationByCOM(HWnd := "") {
    if (HWnd = "") {
        HWnd := WinExist("A")
    }
    Process := WinGetProcessName("ahk_id " . HWnd)
    if (Process = "explorer.exe") {
        Class := WinGetClass("ahk_id " . HWnd)
        if (Class ~= "Progman|WorkerW") {
            Location := A_Desktop
        } else if (Class ~= "(Cabinet|Explore)WClass") {
            shellApp := ComObject("Shell.Application")
            for Window in shellApp.Windows() {
                if (Window.HWnd = HWnd) {
                    URL := Window.LocationURL
                    break
                }
            }
            Location := StrReplace(StrReplace(URL, "file:///", ""), "/", "\")
        }
    }
    return Location
}

uriDecode(str) {
    Loop {
        match := RegExMatch(str, "i)(?<=%)[\da-f]{1,2}")
        if (match) {
            hex := match.Value
            str := StrReplace(str, "%" . hex, Chr("0x" . hex))
        } else {
            break
        }
    }
    return str
}


WindowsKeyForTC(path) {
    {
        TC_EXE := GetFileNameFromPath(path)
        ; If valid explorer window is open: close it and open TC at that location
        if (WinActive("ahk_class ExploreWClass") or WinActive("ahk_class CabinetWClass")) 
        {   
            winid := WinGetID("A")
            Path := uriDecode(WindowsExplorerLocationByCOM(winid))
            if (Path != "") {
                Run(path . " /O /T " . Path)
                ; WinWait("ahk_exe " . TC_EXE); This causes laggy artefacts, left as comment to explain
                WinActivate("ahk_exe " . TC_EXE)    
                WinClose("ahk_id " . winid)
            } else { ; Handles cases like "This PC" etc
                Run(path)
                WinActivate("ahk_exe " . TC_EXE)    
                WinClose("ahk_id " . winid)
            }
        }
        ; If TC is currently active: minimize it
        else if (WinGetProcessName("A") == TC_EXE)
        {
            winid := WinGetID("A")
            WinMinimize("ahk_id " . winid)
        }
        ; Otherwise just open TC :)
        else
        {
            Run(path)
            WinActivate("ahk_exe " . TC_EXE)
        }
    }
}
Hope this helps some of you :)
Post Reply