作者原话:文件多效率较低,并不建议实际使用……
;Author: fuwt ;date: 2017-01-25 ;2017-02-23 SetWorkingDir, %A_ScriptDir% global Items := [] tcmatch := "Tcmatch.dll" hModule := DllCall("LoadLibrary", "Str", tcmatch, "Ptr") ;注册热键 Hotkey, if, WinActive("ahk_class CabinetWClass") && A_CaretX = "" loop, 26 { thisHotkey := chr(A_Index + 96) ToolTip, % Hotkey Hotkey, %thisHotkey%, QuickSearch } Hotkey, %A_Space%, QuickSearch ;MsgBox, % MatchStr("档案管理办法","daglbf") Return #if WinActive("ahk_class CabinetWClass") && A_CaretX = "" ~Enter:: esc:: hotkeys := "" ToolTip Return Backspace:: hotkeys := SubStr(hotkeys, 1, StrLen(hotkeys) - 1) ToolTip, % hotkeys Return QuickSearch: Matched := "" hotkeys := hotkeys . A_ThisHotkey ToolTip, % hotkeys Path := getPath() folder := ComObjCreate("shell.Application").NameSpace(Path) items := folder.Items for item in items{ if (MatchStr(item.name, hotkeys)){ SelectItem(item.name) Break } } Return MatchStr(ChnStr, prase){ PraseLen := StrLen(prase) Loop, % StrLen(ChnStr) - StrLen(prase) + 1 { Pos := RegexMatch(prase, Str2Pinyin(SubStr(ChnStr, A_Index, PraseLen))) If (Pos = 1) Return A_Index } } getPath(){ thisHwnd := WinActive("A") WinGet, processName, processName, A WinGetClass, class, A if (processName!="explorer.exe") return for window in ComObjCreate("Shell.Application").Windows { if (window.name = "文件资源管理器" && window.hwnd == thisHwnd) path := StrReplace(window.LocationURL, "file:///", "") path := StrReplace(path, "/", "\") path := StrReplace(path, "`%20"," ") } Return path } SelectItem(argv){ hwnd := WinActive("a") Windows := ComObjCreate("shell.Application").Windows for window in Windows{ if window.hwnd == hwnd thisWindow := window } folder := thisWindow.document.folder for item in folder.items if item.name == argv thisWindow.document.SelectItem(item, 13) } Str2Pinyin(str) { Loop, Parse, str { SetFormat, Integer, HEX ChrCode := Asc(A_LoopField) SetFormat, Integer, D If ChrCode between 0x3007 and 0x9FA5 { ;MsgBox, % A_LoopField IniRead, OutputVar, dic.ini, pinyin, %A_LoopField% ;MsgBox, % OutputVar if (OutputVar = "ERROR") PinyinStr .= A_LoopField if InStr(OutputVar, A_Tab) { pinyinArr := StrSplit(OutputVar, A_Tab) loop % pinyinArr.MaxIndex() - 1 { PinyinStr .= pinyinArr[A_Index] . "|" } PinyinStr .= pinyinArr[pinyinArr.MaxIndex()] } else PinyinStr .= OutputVar } else { PinyinStr .= A_LoopField ; 一些特殊字符可能需要保持原义(这里未作处理)。 } } Return, PinyinStr }