You still around buddy?
I made a few changes to your original script that may be of interest to you if the project is still alive.
1. I switched from running a new explorer window for a selected file/folder, to using the one that's open with Sean's COM Library and a variation of his ShellNavigate/ShellFolder functions.
2. I dropped the use of clipboard. (I use ControlGetText to retrieve active window path).
3. Fixes a bug involving extra "\" from root folder paths (C:\, D:\...), and added Explorer and Cabinet to their own group.
Dependencies: Requires Sean's COM library in the Lib folder, maybe CoHelper too.
link: http://www.autohotkey.com/forum/viewtop ... sc&start=0
Code:
Code:
;---------------------------------------------------------------------------
;
; A simple auto-search utility for the WinExplorer
; created by Buddy 03/2009
; disclaimer: this version has undergone non-Buddy edits
;
;---------------------------------------------------------------------------
#SingleInstance
SetBatchLines,-1
Menu, tray, NoStandard
Menu, tray, Add, Reload, Reload
Menu, tray, Add, Exit, Exit
Menu, Tray, Icon, shell32.dll, 23
;---------------------------------------------------------------------------
; Define SPACE as Windows Explorer auto-search hotkey
;---------------------------------------------------------------------------
GroupAdd, Explorer, ahk_class CabinetWClass
GroupAdd, Explorer, ahk_class ExploreWClass
;GroupAdd, Explorer, ahk_class #32770 ;for future? browse 'Open File' windows, etc.
#IfWinActive, ahk_group Explorer
Space::
searchInExplorer()
Return
#IfWinActive
;---------------------------------------------------------------------------
; Shift-ESC terminates the script
;---------------------------------------------------------------------------
#IfWinActive, myGui
~+Esc::ExitApp
#IfWinActive
Exit:
ExitApp
Return
Reload:
Reload
Return
;---------------------------------------------------------------------------
; Search function
;---------------------------------------------------------------------------
searchInExplorer() {
;---------------------------------------------------------------------------
; Control variables must be global
;---------------------------------------------------------------------------
global Input, List
;---------------------------------------------------------------------------
; Store current directory name [to clipboard - use global Dir instead]
;---------------------------------------------------------------------------
ControlGetText, Dir, Edit1, A
;---------------------------------------------------------------------------
; Define and show minimal GUI with controls
;---------------------------------------------------------------------------
Gui, 3:Font, S10 CDefault Bold, Letter Gothic
Gui, 3:Margin,0,0
Gui, 3:+Owner -Caption AlwaysOnTop
Gui, 3:Add, Edit, x0 y0 h25 w600 vInput gInputEvent hwndhInput
Gui, 3:Add, ListView, x0 y+0 w600 vList gListEvent hwndhList Hide -Hdr AltSubmit,%A_Space%
Gui, 3:Show, Center, myGui
WinGet, hGui, ID, myGui
WaitForKey:
;---------------------------------------------------------------------------
; Retrieve the control, which currently has the focus
; (according ControlGetFocus page in AHK manual)
;---------------------------------------------------------------------------
VarSetCapacity(hInputDec, 65, 0)
DllCall("msvcrt\_i64toa", Int64, hInput, Str, hInputDec, Int, 10)
GuiThreadInfoSize = 48
VarSetCapacity(GuiThreadInfo, GuiThreadInfoSize)
NumPut(GuiThreadInfoSize, GuiThreadInfo, 0)
If DllCall("GetGUIThreadInfo", uint, 0, str, GuiThreadInfo)
hFocused := NumGet(GuiThreadInfo, 12)
Else
hFocused = 0
;---------------------------------------------------------------------------
; Wait until user pressed ENTER, ESC or DOWN key
;---------------------------------------------------------------------------
Input, key,V, {Enter}{Esc}{Down}
;---------------------------------------------------------------------------
; For DOWN the cursor jumps down into the search list
;---------------------------------------------------------------------------
If (ErrorLevel = "EndKey:Down")
{
If (hFocused = hInputDec)
SendInput {Tab}{Down}
;---------------------------------------------------------------------------
; Go wait for the next key if DOWN is pressed
;---------------------------------------------------------------------------
Goto,WaitForKey
}
;---------------------------------------------------------------------------
; ENTER & ESC closes the GUI
;---------------------------------------------------------------------------
Gui, 3:Destroy
;---------------------------------------------------------------------------
; ENTER also shows the selected file in another explorer window
;---------------------------------------------------------------------------
If (ErrorLevel = "EndKey:Enter") AND SelectedFile
{
If StrLen(Dir) = 3 ; Extra "\" from C:\, D:\,...
StringTrimRight,Dir,Dir,1
If InStr( FileExist( Dir . "\" . SelectedFile ), "D" )
ShellNavSelect3( Dir . "\" . SelectedFile )
Else ShellNavSelect3( Dir, False, 0, SelectedFile )
}
Return
;---------------------------------------------------------------------------
; Routine executed for each keystroke in the input field
;---------------------------------------------------------------------------
InputEvent:
;---------------------------------------------------------------------------
; Retrieve actual user input
;---------------------------------------------------------------------------
GuiControlGet, Input
;---------------------------------------------------------------------------
; Show list control
;---------------------------------------------------------------------------
GuiControl, Show, List
;---------------------------------------------------------------------------
; Search files based on specified prefix and list them
;---------------------------------------------------------------------------
LV_Delete()
Loop, %Dir%\%Input%*, 1
LV_Add("", A_LoopFileName)
;---------------------------------------------------------------------------
; Resize list control height according to the number of found files
;---------------------------------------------------------------------------
LV_ModifyCol(1,"AutoHdr")
h1 := LV_GetCount() * 25
h2 := h1 + 25
GuiControl, Move, List, h%h1%
Gui, 3:Show, Center h%h2%
Return
;---------------------------------------------------------------------------
; Routine executed for each keystroke in the search list
;---------------------------------------------------------------------------
ListEvent:
;---------------------------------------------------------------------------
; Retrieve file name for selected row
;---------------------------------------------------------------------------
LV_GetText(SelectedFile, LV_GetNext(0))
Return
}
/*
Modified to accept file path and select files
Added sMode (selection mode):
0 Deselect the item.
1 Select the item.
3 Put the item in edit mode.
4 Deselect all (--but the specified item).
8 Ensure the item is displayed in the view.
16 Give the item the focus.
*/
;based on ShellNavigate\ShellFolder by Sean
ShellNavSelect3(sPath, bExplore=False, hWnd=0, sSelect="")
{
COM_Init()
psh:= COM_CreateObject("Shell.Application")
hWnd:=WinExist("ahk_group Explorer")
psw := COM_Invoke(psh, "Windows")
Loop, % COM_Invoke(psw, "Count")
If COM_Invoke(pwb:=COM_Invoke(psw, "Item", A_Index-1), "hWnd") <> hWnd
COM_Release(pwb)
Else Break
If sSelect <>
{
pfv := COM_Invoke(pwb,"Document")
COM_Invoke(pfv,"SelectItem","+" pfi:=COM_Invoke(pfv,"Folder.ParseName",sSelect),16) ;focus
COM_Invoke(pfv,"SelectItem","+" pfi,8) ;scroll to file
COM_Invoke(pfv,"SelectItem","+" pfi,4) ;deselect others
COM_Invoke(pfv,"SelectItem","+" pfi,1) ;select file
COM_Release(pfi)
COM_Release(pfv)
}
Else
{
COM_Invoke(pwb, "Navigate2", sPath)
COM_Release(pwb)
}
COM_Release(psw)
COM_Release(psh)
COM_Term()
}
Disclaimer: I don't understand the COM stuff very well, so there may be bugs or redundant pieces of code in there.
Bugs or problems:
--Gui search window scrolls out of view if more hits that screen height (try it in Windows\System32 foder) - but this is important to fix folders like System32 are when scripts like this are useful.
--"My Computer" folder (and Desktop, My Documents(?)): A handful of special folders don't have a proper path in address bar and the script cannot handle them at the moment. Not sure this is worth adding code, maybe just enough to exclude these.
--Background programs may steal focus: Rare, but a few times my antivirus popped up with an update notice, and I lost focus of 'active' window.
Suggestions: (if easy to add...)
--Add left-mouse button/clicks to hotkeys for choosing search results.
--Allow user to go back to text entry box by pressing backspace anywhere, or up arrow when at top of list.
--Send {LEFT} to newly opened folder so first row is selected automatically. (or use COM - I just didn't have time to test this so left it out).
--ExitApp is only available when Gui is active, so to exit you really have to press Space followed by Shift+Esc. Why not make Shift+Esc available to exit all the time?
--Might be complicated, but it would be nice to be able to extend this app to Open File/Save File/... type windows since you need to browse the same folders on them. (Actually, I'd like to be able to use all my explorer hotkeys with those windows).
Well, I suppose that's enough. Let me know if you've kept this project alive.