这个脚本可以对标准控件进行移动位置浏览效果
例如下图,就是按照Alt+鼠标左键,移动窗口里的控件效果展示
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=175 #SingleInstance Force CoordMode Mouse SetControlDelay -1 ; 热键: ; 1. Alt + LButton = 移动控件 ; 2. Alt + Shift + LButton = 仅沿 X 轴移动控件 ; 3. Alt + Ctrl + LButton = 仅沿 Y 轴移动控件 ; 4. Alt + RButton = 调整大小 ; 5. Alt + Shift + RButton = 仅调整控件宽度 ; 6. Alt + Ctrl + RButton = 仅调整控件高度 ; 7. Alt + MButton 或 Alt + Win + C = 更改控件内的文本 ; 8. Alt + Shift + C:将控件坐标复制到剪贴板 ; 9. Win + LButton = 启用/禁用控制 Menu, Tray, NoStandard Menu, Tray, MainWindow ; 对于已编译的脚本 Menu, Tray, Add, &Reload, Reload Menu, Tray, Add, E&xit, Exit MsgBox 0x40, 把鼠标移动到控件上可对标准控件进行操作【包括此对话框】, 1. Alt + LButton = 移动控件`n2. Alt + Shift + LButton = 仅沿 X 轴移动控件`n3. Alt + Ctrl + LButton = 仅沿 Y 轴移动控件`n4. Alt + RButton = 调整大小`n5. Alt + Shift + RButton = 仅调整控件宽度`n6. Alt + Ctrl + RButton = 仅调整控件高度`n7. Alt + MButton 或 Alt + Win + C = 更改控件内的文本`n8. Alt + Shift + C:将控件坐标复制到剪贴板`n9. Win + LButton = 启用/禁用控制 ; ExitApp ; 已经改成 点击对话框的 "确定" 后,直接退出脚本。避免长期挂着影响全局日常操作 return Reload: Reload Exit: ExitApp #!c::GoSub ChangeControlLabel ; 不能使用像 ~Alt & ~Button 这样的简单热键,因为这不会禁用窗口内的点击 Shift & ~Alt:: Ctrl & ~Alt:: ~Alt:: Hotkey, *LButton, Alt_And_LButton, On Hotkey, *RButton, Alt_And_RButton, On Hotkey, *MButton, ChangeControlLabel, On KeyWait, Alt Hotkey, *LButton, Off Hotkey, *RButton, Off Hotkey, *MButton, Off if (A_ThisHotkey = "*LButton") GoSub Alt_And_LButton else if (A_ThisHotkey = "*RButton") GoSub Alt_And_RButton else if (A_ThisHotkey = "*MButton") GoSub ChangeControlLabel return Alt_And_LButton: iPrevMouseX := iPrevMouseY := A_Blank MouseGetPos,,,, hCtrl, 2 while (GetKeyState("Alt", "P") && GetKeyState("LButton", "P")) { bIgnoreX := GetKeyState("Ctrl", "P") bIgnoreY := GetKeyState("Shift", "P") MouseGetPos, iMouseX, iMouseY iMouseX := iMouseX iMouseY := iMouseY ControlGetPos, iX, iY,,,, ahk_id %hCtrl% iXDelta := bIgnoreX ? 0 : iMouseX - (iPrevMouseX == A_Blank ? iMouseX : iPrevMouseX) iYDelta := bIgnoreY ? 0 : iMouseY - (iPrevMouseY == A_Blank ? iMouseY : iPrevMouseY) if (iXDelta <> 0 || iYDelta <> 0) { ControlMove,, iX + iXDelta, iY + iYDelta,,, ahk_id %hCtrl% DllCall("RedrawWindow", "Ptr", hCtrl, "Ptr", 0, "Ptr", 0, "UInt", RDW_INVALIDATE := 1 | RDW_ERASENOW := 0x200 | RDW_ERASE := 4) } iPrevMouseX := iMouseX iPrevMouseY := iMouseY } return Alt_And_RButton: iPrevMouseX := iPrevMouseY := A_Blank MouseGetPos,,,, hCtrl, 2 while (GetKeyState("Alt", "P") && GetKeyState("RButton", "P")) { bIgnoreW := GetKeyState("Ctrl", "P") bIgnoreH := GetKeyState("Shift", "P") MouseGetPos, iMouseX, iMouseY iMouseX := iMouseX iMouseY := iMouseY ControlGetPos,,, iW, iH,, ahk_id %hCtrl% iWDelta := bIgnoreW ? 0 : iMouseX - (iPrevMouseX == A_Blank ? iMouseX : iPrevMouseX) iHDelta := bIgnoreH ? 0 : iMouseY - (iPrevMouseY == A_Blank ? iMouseY : iPrevMouseY) if (iWDelta <> 0 || iHDelta <> 0) { ControlMove,,,, iW + iWDelta, iH + iHDelta, ahk_id %hCtrl% DllCall("RedrawWindow", "Ptr", hCtrl, "Ptr", 0, "Ptr", 0, "UInt", RDW_INVALIDATE:=1 | RDW_ERASENOW:=0x200 | RDW_ERASE:=4) } iPrevMouseX := iMouseX iPrevMouseY := iMouseY } return ChangeControlLabel: ; 关闭热键,使 LButton 无响应 Hotkey, *LButton, Off Hotkey, *RButton, Off Hotkey, *MButton, Off ; 这个热键好像每次激活都会触发两次,所以使用g_iTimeAtThisExecution来防止双重执行 g_iTimeAtThisExecution := SubStr(A_Now, StrLen(A_Now) - 3, 4) if (A_ThisHotkey = "*MButton" && g_iTimeAtLastExecution != A_Blank && g_iTimeAtThisExecution - g_iTimeAtLastExecution < 1) return MouseGetPos,,,, hCtrl, 2 ControlGetText, sExistingText,, ahk_id %hCtrl% InputBox, sText, 设置修改目标文本,,,,,,,,, %sExistingText% g_iTimeAtLastExecution := SubStr(A_Now, StrLen(A_Now) - 3, 4) if (ErrorLevel) return ControlSetText,, %sText%, ahk_id %hCtrl% return #LButton:: MouseGetPos,,,, hCtrl, 2 ControlGet, bEnabled, Enabled,,, ahk_id %hCtrl% Control, % bEnabled ? "Disable" : "Enable",,, ahk_id %hCtrl% return !+C:: MouseGetPos,,,, hCtrl, 2 ControlGetText, sCtrlTxt,, ahk_id %hCtrl% ControlGetPos, iX, iY, iW, iH,, ahk_id %hCtrl% if !((iX == A_Blank || iY == A_Blank || iW == A_Blank || iH == A_Blank)) clipboard := "Control:`t" sCtrlTxt "`nLeft:`t" iX "`nTop:`t" iY "`nRight:`t" iW "`nBottom:`t" iH return
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)