Autohotkey个人即用脚本分享(持续更新ing)

Claunahk小工具——ahk用户的quicker平替,简单但不简陋 中,我介绍了通过claunch来进行快捷操作的可行性。

3

本贴分享一些个人实用脚本,搭配claunahk食用更佳。


快速选取并调用OnTopReplica置顶窗口局部

调用spacesniffer,对当前路径进行透析查看

文件移动专家

文件移动专家2.0

7 个赞

runany有好多脚本,略做修改,可用到你这。

做个记号,很喜欢这个方式

本楼为通用脚本

1. 快速选取并调用OnTopReplica置顶窗口局部

点击按钮后,左键画个区域,即可将该窗口这一区域置顶显示

1

代码
#Requires AutoHotkey v2
;自行修改第八行OnTopReplica路径,以及透明度等参数

; Select Screen Region with Mouse
LButton:: ;Mouse to select with Red
{
	Area := SelectScreenRegion("LButton", "Red", 30)
	WinGetPos &winX, &winY, &WinW, &winH, "ahk_id " Area.id
  Run '"C:\Program Files (x86)\OnTopReplica\OnTopReplica\OnTopReplica.exe" --windowId=' Area.id ' --size=' Area.W ',' Area.H ' --position=' Area.X ',' Area.Y ' --opacity=200 --chromeOff --region=' Area.X-winX ',' Area.Y-winY ',' Area.W ',' Area.H 
  exitapp
}


SelectScreenRegion(Key, Color := "Lime", Transparent:= 80)
{
	CoordMode("Mouse", "Screen")
	MouseGetPos(&sX, &sY, &winid)
	ssrGui := Gui("+AlwaysOnTop -caption +Border +ToolWindow +LastFound -DPIScale")
	WinSetTransparent(Transparent)
	ssrGui.BackColor := Color
	Loop 
	{
		Sleep 10
		MouseGetPos(&eX, &eY)
		W := Abs(sX - eX), H := Abs(sY - eY)
		X := Min(sX, eX), Y := Min(sY, eY)
		ssrGui.Show("x" X " y" Y " w" W " h" H)
	} Until !GetKeyState(Key, "p")
	ssrGui.Destroy()
	Return { X: X, Y: Y, W: W, H: H, X2: X + W, Y2: Y + H ,id: winid}
}

/*OnTopReplica支持的所有参数
      --windowId=HWND        Window handle (HWND) to be cloned.
      --windowTitle=TITLE    Partial TITLE of the window to be cloned.
      --windowClass=CLASS    CLASS of the window to be cloned.
  -v, --visible              If set, only clones windows that are visible.
      --size=WIDTH,HEIGHT    Target WIDTH,HEIGHT of the cloned thumbnail, or
      --width=VALUE          Target WIDTH of cloned thumbnail, or
      --height=VALUE         Target HEIGHT of cloned thumbnail.
      --position=X,Y         Target X,Y of the OnTopReplica window.
      --screenPosition=TR|TL|C|BR|BL
                             Resolution independent window position on 
                               current screen, with locking. Values: 
                               TR|TL|C|BR|BL.
  -r, --region=X,Y,W,H       Region X,Y,W,H of the cloned window.
  -p, --padding=LEFT,TOP,RIGHT,BOTTOM
                             Region padding LEFT,TOP,RIGHT,BOTTOM of the 
                               clone.
  -o, --opacity=0-255        Opacity of the window: 0-255.
      --clickForwarding      Enables click forwarding.
      --clickThrough         Enables click through.
      --chromeOff            Disables the window's chrome (border).
      --fs, --fullscreen     Starts up in fullscreen mode.
  -h, --help, -?             Show command line help.
	*/
4 个赞

OnTopReplica 是个 DWM 缩略图工具,用 AutoHotkey 实现也用不了百行

ontopclip可以进一步设置点击转移 点击穿透 保存选区等 比较方便

本楼为文件管理器页面脚本

1. 调用spacesniffer,对当前路径进行透析查看

适合不知道这个文件夹下面都装了些啥时侯使用。

1

代码
activedir:=Explorer_GetPath(WinExist("A"))
Run %ComSpec% /c ""C:\miniapp\SpaceSniffer.exe" scan " %activedir%,,Hide

;以下是库
Explorer_GetPath(hwnd="")
{
    if !(window := Explorer_GetWindow(hwnd))
        return ErrorLevel := "ERROR"
    if (window="desktop")
        return A_Desktop
    path := window.LocationURL
    path := RegExReplace(path, "ftp://.*@","ftp://")
    path := RegExReplace(path, "%20"," ") ;替换空格,否则显示%20
    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="")
{
    return Explorer_Get(hwnd)
}
 
Explorer_GetSelected(hwnd="")
{
    return Explorer_Get(hwnd,true)
}
 
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)
{
    if !(window := 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")
}

2. 文件移动专家

更便捷(最便捷?)地移动文件。

1

image

代码
#Requires AutoHotkey v2.0
#SingleInstance Force
global allcopyed

;获取当前文件的两重父文件夹
{
activedir:=Explorer_GetPath()
SplitPath activedir , , &activedirpapa
SplitPath activedirpapa , , &activediryaya
}

;获取选中的文件、文件夹列表
{
A_Clipboard:=""
sendinput "^c"
allcopyed:=""
ClipWait(0.2)
ClipSaved := ClipboardAll()
A_Clipboard := ClipSaved 
ClipSaved := ""
allcopyed:=A_Clipboard
A_Clipboard:=""
;msgbox(allcopyed activedir activedirpapa activediryaya)
}

{
	global WinID := WinExist("A")
	ContextMenu := Menu()

	{
		ContextMenu.Add(activediryaya, MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
		ContextMenu.SetIcon(activediryaya, "shell32.dll", 147)
		ContextMenu.Add(activedirpapa, MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
		ContextMenu.SetIcon(activedirpapa, "shell32.dll", 147)
		ContextMenu.Add
	}

	;---------------资源管理器-------------------------
	For openedwindows in ComObject("shell.Application").windows
	{
		This := openedwindows.Document.Folder.Self.Path
		ContextMenu.Add(This, MenuHandler)
		ContextMenu.SetIcon(This, "shell32.dll", 5)
	}
	openedwindows := ""	;清空变量

	;---------------Total Commander-------------------
	if WinExist("ahk_class TTOTAL_CMD")
	{
		TCPath := WinGetProcessPath("ahk_class TTOTAL_CMD")
		cm_CopySrcPathToClip := 2029	;Total Commander 内部代码
		cm_CopyTrgPathToClip := 2030
		ClipSaved := ClipboardAll()
		A_Clipboard := ""

		SendMessage(1075, cm_CopySrcPathToClip, 0, , "ahk_class TTOTAL_CMD")
		ContextMenu.Add
		ContextMenu.Add(A_Clipboard, MenuHandler)
		ContextMenu.SetIcon(A_Clipboard, TCPath, 1)

		SendMessage(1075, cm_CopyTrgPathToClip, 0, , "ahk_class TTOTAL_CMD")
		ContextMenu.Add(A_Clipboard, MenuHandler)
		ContextMenu.SetIcon(A_Clipboard, TCPath, 1)

		A_Clipboard := ClipSaved
		ClipSaved := ""
	}
	;--------------常用文件夹-------
	ContextMenu.Add
	ContextMenu.Add("常用路径", MenuHandler)
	ContextMenu.Disable("常用路径")
	ContextMenu.Add("C:\miniapp", MenuHandler)	;如要添加自定义路径,可复制本行和下一行,只修改其中路径即可
	ContextMenu.SetIcon("C:\miniapp", "shell32.dll", 44)
	
	ContextMenu.Add("G:\代码库\自写软件\clauch增强\ahks", MenuHandler)	
	ContextMenu.SetIcon("G:\代码库\自写软件\clauch增强\ahks", "shell32.dll", 44)
	
	;ContextMenu.Add("%UserProfile%\", MenuHandler)	;用户文件夹
	;ContextMenu.SetIcon("%UserProfile%\", "shell32.dll", 44)
	;------------------------------
	ContextMenu.Show
	ContextMenu.Delete
} 

#HotIf	;关闭上下文相关性

MenuHandler(ItemName, ItemPos, MyMenu)
{
	global allcopyed
	WinActivate "ahk_id" WinID

errorfind:=0

	if allcopyed
{
	Loop parse, allcopyed, "`n", "`r"
{
	try
  {
	;msgbox A_LoopField
	if ! DirExist(A_LoopField)
	FileMove A_LoopField, ItemName , 0
	else
	{
		SplitPath A_LoopField , &OutFileName
		DirMove A_LoopField, ItemName "\" OutFileName, 0
	}
	}
	catch
		errorfind++
}
if errorfind
	msgbox errorfind "个文件未成功移动,大概是因为有重复文件"
}
	else
{
	try
	{
		if ControlGetEnabled("ToolbarWindow323", WinID) = 1 or ControlGetEnabled("ToolWindow324", WinID) = 1
		{
			Send "!d"
			Sleep 100	;等待获取焦点,如果设为 50 ,在 chrome 中另存为会出现焦点错误
			addressbar := ControlGetFocus("A")	; 按下 alt+D 之后的焦点为地址栏
			ControlSetText(ItemName, addressbar, "A")
			ControlSend("{Enter}", addressbar, "A")
			ControlFocus("Edit1", "A")	;焦点移回到 Edit1
		}
	}
	catch TargetError
	{
		FolderPath := ItemName
		OldText := ControlGetText("Edit1", "A")	;读取当前 Edit1 控件中的文件名
		ControlFocus "Edit1", "A"

		Loop 5
		{
			ControlSetText FolderPath, "Edit1", "ahk_id" WinID
			Sleep(50)
			CurControlText := ControlGetText("Edit1", "ahk_id" WinID)
			if (CurControlText = FolderPath)
				break
		}

		Sleep 50
		ControlSend "{Enter}", "Edit1", "A"
		Sleep 50

		If !OldText	;插入原始文件名
			return

		Loop 5
		{
			ControlSetText OldText, "Edit1", "A"
			Sleep 50
			CurControlText := ControlGetText("Edit1", "A")
			if (CurControlText = OldText)
				break
		}
	}
}
}

Explorer_GetPath() {
   winClass := WinGetClass(hWnd := WinExist("A"))
   if !(winClass ~= "(Cabinet|Explore)WClass")
      return
   for window in ComObject("Shell.Application").Windows
      if (hWnd = window.hWnd)
         return window.Document.Folder.Self.Path
}
4 个赞

先更新一些调用现成软件的功能(把自己的windows开始菜单磁贴清理一波)

:doge: V1 V2 夹着用。 :index_pointing_at_the_viewer:

这个文件移动专家思路很好!就是右键菜单不太适合键盘党,能不能转成增量搜索(incremental search)的列表呢。

想象不出来会有人用键盘进行文件移动。。。
不管怎样,选择要移动的文件时,都是要用鼠标的吧。。。

1 个赞

既然支持 Total Commander 已打开列表的展示,但却不支持在 Total Commander 中调用,这就有点尴尬了。 :rofl:
我不认为会有人开着 Total Commander,但却用默认的资源管理器去管理文件。 :smiling_face_with_tear:

1 个赞

微改的这个,其实我不用total commandar

去掉上层目录的代码部分,就可以用了,但在 Total Commander 中,食之无味,弃之可惜。
使用默认的资源管理器还是很有用的。

ahk tools 我也有一个可以分享 自用的

2 个赞

这个帖子要是可以像小青蛙那样弄楼中楼评论就好了,, 现在插楼会打断楼主分享

个人经常遇到的一个场景:在下载目录下总会临时存一些文件,定期整理时,就需要把下载目录下的文件移动到不同目录下。
选中文件,按下快捷键,弹出菜单,选中某个目录,直接剪切过去。
现在的问题是,弹出菜单里的目录,可能有10来个,不能快速通过按首字母定位。

我写的曹操快切了解一下:

image

给菜单前面加上1 2 3 4 5 a s d f等等就好了。

1 个赞

还挺支持的,AHK 一直很方便~

大家好像都忽略了 CLaunch 自带的这个功能。

1 个赞