AutoHotkey: Backspace In Drive Root Opens My Computer: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
(updated ND variant for TC 7.5 (unicode panels))
(changes in TC7.5pb3 (no more UnicodeClass, but TPathPanel1/2))
 
Line 27: Line 27:
  #IfWinActive, ahk_class TTOTAL_CMD
  #IfWinActive, ahk_class TTOTAL_CMD
  $BS::
  $BS::
  WinGetActiveTitle, tcVersion  ; Total Commander x.yy - UserName
  tcVersion := SubStr( tcVersion, 17, 3 )
  If((  tcVersion is float  ) and (  tcVersion >= 7.5  ))
  {
    ControlGetText, tcPathR, TPathPanel1  ; new in TC 7.5
    ControlGetText, tcPathL, TPathPanel2
  }
  Else
  {
    ControlGetText, tcPathL, TMyPanel9
    ControlGetText, tcPathR, TMyPanel5
  }
   ControlGetFocus, tcFocus
   ControlGetFocus, tcFocus
  ControlGetText, tcStatus1, TMyPanel9
  ControlGetText, tcStatus2, TMyPanel5
  ControlGetText, tcStatus1u, TPathPanel.UnicodeClass1  ; new in TC 7.5
  ControlGetText, tcStatus2u, TPathPanel.UnicodeClass2
   SendInput, {BS}
   SendInput, {BS}
   
   
   ; only when the actual TC panels are active
   ; only when the actual TC panels are active
   If(  RegExMatch( tcFocus, "^TMyListBox1$" )  )
   If(  RegExMatch( tcFocus, "^TMyListBox1$" )  )
     tcStatus := tcStatus1
     tcStatus := tcPathL
   Else
   Else
   If(  RegExMatch( tcFocus, "^TMyListBox2$" )  )
   If(  RegExMatch( tcFocus, "^TMyListBox2$" )  )
     tcStatus := tcStatus2
     tcStatus := tcPathR
  Else
  If(  RegExMatch( tcFocus, "^TMyListBox\.UnicodeClass2$" )  )  ; new in TC 7.5
    tcStatus := tcStatus1u
  Else
  If(  RegExMatch( tcFocus, "^TMyListBox\.UnicodeClass1$" )  )
    tcStatus := tcStatus2u
   Else
   Else
     Return
     Return

Latest revision as of 07:28, 18 May 2009

Usually pressing Backspace in drive root does nothing, this is to prevent landing in My Computer by mistake, when holding down the key too long. Some people may prefer to reach the highest hierarchy level instead.

$BS::
IfWinActive, ahk_class TTOTAL_CMD
{
  WinGetText, PanelText, A
  IfInString, PanelText, :\>
    PostMessage 1075, 2122, , , ahk_class TTOTAL_CMD
  Else
    Send, {BS}
}
Else
  Send, {BS}
Return


Here's a variant by ND, which ensures that the script is only launched in TC and when one of the TC panels is active (tested in TC 5.50 and TC 7.01 on WinXP SP2, and TC 7.5 on WinXP SP3).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;! \brief  pressing BackSpace in drive root should land in My Computer
;
;  Assumes that the panel title-paths are accessible (TMyPanel5/TMyPanel9),
;  and that BackSpace is used for cm_GoToParent (going up to the parent dir)
;
;  Sends the cm_OpenDrives command when in a drive root
;
#IfWinActive, ahk_class TTOTAL_CMD
$BS::
  WinGetActiveTitle, tcVersion  ; Total Commander x.yy - UserName
  tcVersion := SubStr( tcVersion, 17, 3 )

  If((  tcVersion is float  ) and (  tcVersion >= 7.5  ))
  {
    ControlGetText, tcPathR, TPathPanel1  ; new in TC 7.5
    ControlGetText, tcPathL, TPathPanel2
  }
  Else
  {
    ControlGetText, tcPathL, TMyPanel9
    ControlGetText, tcPathR, TMyPanel5
  }

  ControlGetFocus, tcFocus
  SendInput, {BS}

  ; only when the actual TC panels are active
  If(  RegExMatch( tcFocus, "^TMyListBox1$" )  )
    tcStatus := tcPathL
  Else
  If(  RegExMatch( tcFocus, "^TMyListBox2$" )  )
    tcStatus := tcPathR
  Else
    Return

  If(  RegExMatch( tcStatus, "^.:\\\*\.\*$" )  )
    PostMessage, 1075, 2122  ; cm_OpenDrives
Return


Back to AutoHotkey