在 Claunahk小工具——ahk用户的quicker平替,简单但不简陋 中,我介绍了通过claunch来进行快捷操作的可行性。
本贴分享一些个人实用脚本,搭配claunahk食用更佳。
runany有好多脚本,略做修改,可用到你这。
做个记号,很喜欢这个方式
点击按钮后,左键画个区域,即可将该窗口这一区域置顶显示
注意,需要用到v2版uia库,下载地址:GitHub - Descolada/UIA-v2: UIAutomation library for AHK v2, based on thqby's UIA library
#Requires AutoHotkey v2
#include <UIA>
#Warn All, Off
#SingleInstance force
; Select Screen Region with Mouse
LButton:: ;Mouse to select with Red
{
global titileH:=0
Area := SelectScreenRegion("LButton", "Red", 30)
WinGetPosEx(Area.id, &winX, &winY, &WinW, &winH, &Offset_X, &Offset_Y)
;msgbox " " Offset_X " " Offset_Y
;WinGetClientPos &winX, &winY, &WinW, &winH, "ahk_id " Area.id
h:=0
try
{
El := UIA.ElementFromHandle("ahk_id " Area.id)
loc:=El.ElementFromPath("c").BoundingRectangle
x:=loc.l, y:=loc.t, w:=(loc.r-loc.l), h:=(loc.b-loc.t)
;msgbox(h)
}
tooltip h
Run '"G:\Program Files (x86)\OnTopReplica\OnTopReplica\OnTopReplica.exe" --windowId=' Area.id ' --size=' Area.W ',' Area.H ' --position=' Area.X-2 ',' Area.Y-2 ' --opacity=200 --chromeOff --region=' Area.X-winX-1 ',' Area.Y-winY-h-2 ',' Area.W+2 ',' Area.H+2
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.
*/
;------------------------------
;
; Function: WinGetPosEx
;
; Description:
;
; Gets the position, size, and offset of a window. See the *Remarks* section
; for more information.
;
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3392
;
; Parameters:
;
; hWindow - Handle to the window.
;
; X, Y, Width, Height - Output variables. [Optional] If defined, these
; variables contain the coordinates of the window relative to the
; upper-left corner of the screen (X and Y), and the Width and Height of
; the window.
;
; Offset_X, Offset_Y - Output variables. [Optional] Offset, in pixels, of the
; actual position of the window versus the position of the window as
; reported by GetWindowRect. If moving the window to specific
; coordinates, add these offset values to the appropriate coordinate
; (X and/or Y) to reflect the true size of the window.
;
; Returns:
;
; If successful, a RECTPlus buffer object is returned.
; The first 16 bytes contains a RECT structure that contains the dimensions of the
; bounding rectangle of the specified window.
; The dimensions are given in screen coordinates that are relative to the upper-left
; corner of the screen.
; The next 8 bytes contain the X and Y offsets (4-byte integer for X and
; 4-byte integer for Y).
;
; Also if successful (and if defined), the output variables (X, Y, Width,
; Height, Offset_X, and Offset_Y) are updated. See the *Parameters* section
; for more more information.
;
; If not successful, FALSE is returned.
;
; Requirement:
;
; Windows 2000+
;
; Remarks, Observations, and Changes:
;
; * Starting with Windows Vista, Microsoft includes the Desktop Window Manager
; (DWM) along with Aero-based themes that use DWM. Aero themes provide new
; features like a translucent glass design with subtle window animations.
; Unfortunately, the DWM doesn't always conform to the OS rules for size and
; positioning of windows. If using an Aero theme, many of the windows are
; actually larger than reported by Windows when using standard commands (Ex:
; WinGetPos, GetWindowRect, etc.) and because of that, are not positioned
; correctly when using standard commands (Ex: gui Show, WinMove, etc.). This
; function was created to 1) identify the true position and size of all
; windows regardless of the window attributes, desktop theme, or version of
; Windows and to 2) identify the appropriate offset that is needed to position
; the window if the window is a different size than reported.
;
; * The true size, position, and offset of a window cannot be determined until
; the window has been rendered. See the example script for an example of how
; to use this function to position a new window.
;
; * 20150906: The "dwmapi\DwmGetWindowAttribute" function can return odd errors
; if DWM is not enabled. One error I've discovered is a return code of
; 0x80070006 with a last error code of 6, i.e. ERROR_INVALID_HANDLE or "The
; handle is invalid." To keep the function operational during this types of
; conditions, the function has been modified to assume that all unexpected
; return codes mean that DWM is not available and continue to process without
; it. When DWM is a possibility (i.e. Vista+), a developer-friendly messsage
; will be dumped to the debugger when these errors occur.
;
; Credit:
;
; Idea and some code from *KaFu* (AutoIt forum)
;
;-------------------------------------------------------------------------------
WinGetPosEx(hWindow, &X := "", &Y := "", &Width := "", &Height := "", &Offset_X := "", &Offset_Y := "") {
Static S_OK := 0x0,
DWMWA_EXTENDED_FRAME_BOUNDS := 9
;-- Get the window's dimensions
; Note: Only the first 16 bytes of the RECTPlus structure are used by the
; DwmGetWindowAttribute and GetWindowRect functions.
RECTPlus := Buffer(24,0)
Try {
DWMRC := DllCall("dwmapi\DwmGetWindowAttribute",
"Ptr", hWindow, ;-- hwnd
"UInt", DWMWA_EXTENDED_FRAME_BOUNDS, ;-- dwAttribute
"Ptr", RECTPlus, ;-- pvAttribute
"UInt", 16, ;-- cbAttribute
"UInt")
}
Catch {
Return False
}
;-- Populate the output variables
X := NumGet(RECTPlus, 0, "Int") ; left
Y := NumGet(RECTPlus, 4, "Int") ; top
R := NumGet(RECTPlus, 8, "Int") ; right
B := NumGet(RECTPlus, 12, "Int") ; bottom
Width := R - X ; right - left
Height := B - Y ; bottom - top
OffSet_X := 0
OffSet_Y := 0
;-- Collect dimensions via GetWindowRect
RECT := Buffer(16, 0)
DllCall("GetWindowRect", "Ptr", hWindow,"Ptr", RECT)
;-- Right minus Left
GWR_Width := NumGet(RECT, 8, "Int") - NumGet(RECT, 0, "Int")
;-- Bottom minus Top
GWR_Height:= NumGet(RECT, 12, "Int") - NumGet(RECT, 4, "Int")
;-- Calculate offsets and update output variables
NumPut("Int", Offset_X := (Width - GWR_Width) // 2, RECTPlus, 16)
NumPut("Int", Offset_Y := (Height - GWR_Height) // 2, RECTPlus, 20)
Return RECTPlus
}
OnTopReplica 是个 DWM 缩略图工具,用 AutoHotkey 实现也用不了百行
ontopclip可以进一步设置点击转移 点击穿透 保存选区等 比较方便
适合不知道这个文件夹下面都装了些啥时侯使用。
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")
}
更便捷(最便捷?)地移动文件。
#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
}
先更新一些调用现成软件的功能(把自己的windows开始菜单磁贴清理一波)
V1 V2 夹着用。
这个文件移动专家思路很好!就是右键菜单不太适合键盘党,能不能转成增量搜索(incremental search)的列表呢。
想象不出来会有人用键盘进行文件移动。。。
不管怎样,选择要移动的文件时,都是要用鼠标的吧。。。
既然支持 Total Commander 已打开列表的展示,但却不支持在 Total Commander 中调用,这就有点尴尬了。
我不认为会有人开着 Total Commander,但却用默认的资源管理器去管理文件。
微改的这个,其实我不用total commandar
去掉上层目录的代码部分,就可以用了,但在 Total Commander 中,食之无味,弃之可惜。
使用默认的资源管理器还是很有用的。
ahk tools 我也有一个可以分享 自用的
这个帖子要是可以像小青蛙那样弄楼中楼评论就好了,, 现在插楼会打断楼主分享
个人经常遇到的一个场景:在下载目录下总会临时存一些文件,定期整理时,就需要把下载目录下的文件移动到不同目录下。
选中文件,按下快捷键,弹出菜单,选中某个目录,直接剪切过去。
现在的问题是,弹出菜单里的目录,可能有10来个,不能快速通过按首字母定位。
我写的曹操快切了解一下:
给菜单前面加上1 2 3 4 5 a s d f等等就好了。
还挺支持的,AHK 一直很方便~