效果预览
; 第一行做名字
; ======================================================================================
; 选中大段文字后,双击 Ctrl c 弹出保存剪切板文本选项面板
; Edit框 ---- 输入作为文件名的文本,未输入文本用默认名【我就试试】
; 获取选中 ---- 弹出面板后,再次选中文字,此按钮将选中的文本提取到Edit
; 获取首行 ---- 从开始选取的大段文字中, 提取第一行的文字到Edit
; 收藏打开 ---- 以Edit文本为文件名,将文字保存到设置的路径下,并打开文件夹选中文件
; 存至桌面 ---- 以Edit文本为文件名,将文字保存到桌面
; 存至收藏 ---- 以Edit文本为文件名,将文字保存到设置的路径下
; 看下效果 ---- 新开一个进程运行刚才复制的代码
; 不想看了 ---- 如果刚才复制的代码是持续运行的,可以通过这个按钮结束
; 默认快捷键 ---- 第一行按钮 ALt + qwe 第二行按钮 Alt + asd
; ======================================================================================
收藏路径 := A_Desktop "\收藏测试"
~^c::DoublePress("MeunGui")
MeunGui(){
Global FileName, SaveEdit, Allstr
Allstr := Clipboard
CoordMode, Mouse, Screen
MouseGetPos, Mousex, Mousey
Gui, Destroy
Gui, +AlwaysOnTop -Caption +HwndSaveGui +E0x08000000
Gui, Font, s12
Gui, Add, Edit, x10 y10 w220 vFileName HwndSaveEdit
Gui, Font, s10
Gui, Add, Button, x10 w70 g_获取选中, 获取选中
Gui, Add, Button, x+5 w70 g_获取首行, 获取首行
Gui, Add, Button, x+5 w70 g_收藏打开, 收藏打开
Gui, Add, Button, x10 w70 g_存至桌面, 存至桌面
Gui, Add, Button, x+5 w70 g_存至收藏, 存至收藏
Gui, Add, Button, x+5 w70 g_关闭面板, 关闭面板
Gui, Add, Button, x10 w70 g_看下效果, 看下效果
Gui, Add, Button, x+5 w70 g_不想看了, 不想看了
Gui, Show, % "x" Mousex " y"Mousey
CoordMode, Mouse
ControlFocus, , ahk_id %SaveEdit%
OnMessage(0x201, "MoveGui")
OnMessage(0x200, "GuiTips")
创建快捷键()
}
MoveGui(){
PostMessage, 0xA1, 2
}
_存至桌面(){
Global FileName, SaveEdit, Allstr
ControlGetText, FileName, , ahk_id %SaveEdit%
ListName := (FileName = "") ? "我就试试" : FileName
FileAppend, % Allstr, % A_Desktop "\" ListName ".ahk", UTF-8
_关闭面板()
}
_获取选中(){
Global SaveEdit
Clipboard := ""
Send, ^c
ClipWait, 1
ControlSetText, , % Clipboard, ahk_id %SaveEdit%
}
_存至收藏(){
Global FileName, SaveEdit, Allstr, 收藏路径
ControlGetText, FileName, , ahk_id %SaveEdit%
ListName := (FileName = "") ? "我就试试" : FileName
FileAppend, % Allstr, % 收藏路径 "\" ListName ".ahk", UTF-8
_关闭面板()
}
_收藏打开(){
Global FileName, SaveEdit, Allstr, 收藏路径
ControlGetText, FileName, , ahk_id %SaveEdit%
ListName := (FileName = "") ? "我就试试" : FileName
FileAppend, % Allstr, % 收藏路径 "\" ListName ".ahk", UTF-8
Loop {
If FileExist(收藏路径 "\" ListName ".ahk")
Break
}
FilePlus.File_OpenAndSelect(收藏路径 "\" ListName ".ahk")
_关闭面板()
}
_关闭面板(){
Global Allstr
Gui, Destroy
Allstr := ""
}
_获取首行(){
Global SaveEdit, Allstr
Firstline := RegExReplace(RegExReplace(RegExReplace(Allstr, "[\r\n]+", "`n"), "^(.+?\n)(.+$)", "$1"), "[\\/:?*""|<>(){} \r;\n]")
ControlSetText, , % Firstline, ahk_id %SaveEdit%
}
创建快捷键(){
Global SaveEdit
#If WinExist("ahk_id" SaveEdit)
hotkey, !q, _获取选中
hotkey, !w, _获取首行
hotkey, !e, _收藏打开
hotkey, !a, _存至桌面
hotkey, !s, _存至收藏
hotkey, !d, _关闭面板
#If
}
DoublePress(GoFunc := ""){
static pressed1 = 0
if (pressed1 and A_TimeSincePriorHotkey <= 500){
pressed1 = 0
SetTimer, %GoFunc%, -10
}
else {
pressed1 = 1
}
}
_看下效果(){
Global Allstr
Exec(Allstr, 1)
return
}
_不想看了(){
Exec("", 1)
Gui, Destroy
return
}
;===============
;文件高级操作类-来之Autohotkey中文社区https://www.autoahk.com/archives/18616
;by 河许人
;===============
;方法 Explorer_GetPath(hwnd="")--获取当前管理器路径
;方法 Explorer_GetAll(hwnd="")--获取管理器目录
;方法 Explorer_GetSelected(hwnd="")--获取管理器已选择文件目录
;方法 Explorer_GetWindow(hwnd="")获取管理器窗口名字
;方法 Explorer_Get(hwnd="",selection=false)获取管理器目录获取
;方法 File_OpenAndSelect(path, selfilearr) --打开并选中文件
;方法 Files_OpenAndSelect(path, selfilearr) --打开并选中一个或多个文件
;历史
;2021-01-21 修复夹带16进制的bug
; ========================================================================================================================================================
/*
;示例
myfile:=New fileplus
F9::
path := myfile.Explorer_GetPath()
all := myfile.Explorer_GetAll()
sel := myfile.Explorer_GetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
myfile.File_OpenAndSelect("E:\lenovo\Pictures\随机选中的样例.png") ;更换为自己的路径
myfile.Files_OpenAndSelect("E:\lenovo\Pictures",["随机选中的样例.png","#ClipboardTimeout备注的解释.png"]) ;更换为自己的路径
return
*/
; ========================================================================================================================================================
Class FilePlus
{
;方法 Explorer_GetWindow(hwnd="")获取管理器窗口名字
;参数hwnd
Explorer_GetWindow(hwnd="")
{
; thanks to jethrow for some pointers here
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process!="explorer.exe")
return
if (class ~= "(Cabinet|Explore)WClass")
{
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window
}
else if (class ~= "Progman|WorkerW")
return "desktop" ; desktop found
}
;方法 Explorer_Get(hwnd="",selection=false)获取管理器目录获取
;参数hwnd
;参数selection 布尔类型
Explorer_Get(hwnd="",selection=false)
{
if !(window := this.Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
{
ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
if !hwWindow ; #D mode
ControlGet, hwWindow, HWND,, SysListView321, A
ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
base := SubStr(A_Desktop,0,1)=="" ? SubStr(A_Desktop,1,-1) : A_Desktop
Loop, Parse, files, `n, `r
{
path := base "\" A_LoopField
IfExist %path% ; ignore special icons like Computer (at least for now)
ret .= path "`n"
}
}
else
{
if selection
collection := window.document.SelectedItems
else
collection := window.document.Folder.Items
for item in collection
ret .= item.path "`n"
}
return Trim(ret,"`n")
}
;方法 Explorer_GetPath(hwnd="")--获取当前管理器路径
;参数hwnd
;示例path:=Explorer_GetPath()
Explorer_GetPath(hwnd="")
{
if !(window := this.Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
return A_Desktop
path := window.LocationURL
path := RegExReplace(path, "ftp://.*@","ftp://")
StringReplace, path, path, file:///
StringReplace, path, path, /,\, All
; thanks to polyethene、紧急制动(反馈)
Loop
If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, path, path,`%%hex%, % Chr("0x" . hex), All
Else Break
return path
}
;方法 Explorer_GetAll(hwnd="")--获取管理器目录
;参数hwnd
Explorer_GetAll(hwnd="")
{
return this.Explorer_Get(hwnd)
}
;方法 Explorer_GetSelected(hwnd="")--获取管理器已选择文件目录
;参数hwnd
Explorer_GetSelected(hwnd="")
{
return this.Explorer_Get(hwnd,true)
}
;方法 File_OpenAndSelect(sFullPath) --打开目录并选中文件
;参数sFullPath 类型字符串
;示例File_OpenAndSelect("E:\Documents\Desktop\ts1.ahk")
File_OpenAndSelect(sFullPath)
{
SplitPath sFullPath, , sPath
;MsgBox,% sPath
FolderPidl := DllCall("shell32\ILCreateFromPath", "Str", sPath)
;MsgBox,% FolderPidl
DllCall("shell32\SHParseDisplayName", "str", sFullPath, "Ptr", 0, "Ptr*", ItemPidl := 0, "Uint", 0, "Uint*", 0)
DllCall("shell32\SHOpenFolderAndSelectItems", "Ptr", FolderPidl, "UInt", 1, "Ptr*", ItemPidl, "Int", 0)
this.CoTaskMemFree(FolderPidl)
this.CoTaskMemFree(ItemPidl)
}
Files_OpenAndSelect(path,selfilearr)
{
FolderPidl := DllCall("shell32\ILCreateFromPath", "Str", path)
VarSetCapacity(plist,selfilearr.Length() * A_PtrSize)
pidls := []
Loop % selfilearr.Length()
{
ItemPidl := DllCall("shell32\ILCreateFromPath", "Str", InStr(selfilearr[A_Index], ":") ? selfilearr[A_Index] : path "\" selfilearr[A_Index])
if (ItemPidl)
{
pidls.Push(ItemPidl)
NumPut(ItemPidl, plist, (A_Index-1 ) * A_PtrSize,"ptr")
}
}
DllCall("shell32\SHOpenFolderAndSelectItems", "Ptr", FolderPidl, "UInt", pidls.Length(), "Ptr",&plist, "Int", 0)
this.CoTaskMemFree(FolderPidl)
Loop % pidls.Length()
{
this.CoTaskMemFree(pidls[A_Index])
}
}
CoTaskMemFree(pv)
{
Return DllCall("ole32\CoTaskMemFree", "Ptr", pv)
}
}
; ==================================================================================
; dbgba 的新建进程
; ==================================================================================
Exec(s, flag="Default") {
SetBatchLines, -1
SetWorkingDir %A_ScriptDir%
DetectHiddenWindows, On
WinGet, NewPID, PID, <<ExecNew%flag%>> ahk_class AutoHotkeyGUI
PostMessage, 0x111, 65307,,, %A_ScriptDir%\* ahk_pid %NewPID%
add=`nflag=<<ExecNew%flag%>>`n
(%
Gui, Gui_Flag_Gui: Show, Hide, %flag%
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "ShellHook"), "ShellEvent")
ShellEvent(wParam, lParam) {
DetectHiddenWindows, On
if !WinExist("HostProcessName")
ExitApp
}
)
s:=add "`n" s "`nExitApp"
s:=RegExReplace(s, "HostProcessName", "ahk_pid "DllCall("GetCurrentProcessId"))
exec := ComObjCreate("WScript.Shell").Exec(A_AhkPath " /ErrorStdOut /f *")
exec.StdIn.Write(s)
exec.StdIn.Close()
}
?僵尸来啦
请收下我的膝盖!
回复~