Window 平台里最经典和常用的自动化工具。使用脚本语言,具备图灵完备性,但其语法相当难用。
常用自动化操作
点击 window 里控件
#WinActivateForce
!F11:: ; alt + F11
while true {
Sleep, 1000 ; miliseconds
WinActivate, ahk_class WindowClassName ; activate window
Sleep, 1000
ControlClick, X100 Y250, ahk_class WindowClassName ; click
Sleep, 300000
}
- WinActivate
- ControlClick
- ControlClick , Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText
- Control-or-Pos: 坐标默认是相对于 window 左上角。
- WinTitle。建议用 ahk 自带的 Window Spy 工具查看。
ahk in rdp
测试发现,WinActivate 和 ControlClick 等很多命令对 rdp 会话局限性很大,如果 rdp 断开(disconnected) 甚至只要 rdp 窗口最小化,那么 WinActivate / ControlClick / Send 等都无法触发(rdp 窗口不在前台显示时可以,只要没有最小化),坑。
尝试的 workaround 是:
- rdp in vnc. 弄一台 Linux 服务器跑 rdp client 连接目标 Windows。 用 VNC 远程连接这台 Linux。测试可。VNC 窗口关闭时也可以触发 rdp。
- rdp in rdp. 弄一台 Windows 服务器 rdp 连接目标 windows (这个内层的 rdp 窗口不要最小化). 外层的 rdp 可以最小化,不影响目标 windows 上的 ahk。但外层 rdp disconnected 后内层 rdp 里的 ahk 仍然无法运行。
- 傻逼 rdp 就是坑货。
常用脚本
volumn_control.ahk
; ctrl + alt + [: mute
^![::Send {Volume_Mute}
; alt + [: volume down
![::Send {Volume_Down 1}
; alt + ]: volume up
!]::Send {Volume_Up 1}
按 "Alt + [" 和 "Alt + ]" 分别降低 / 增加音量。
take_screenshot.ahk
#persistent
; take screenshot and save to png file
; key: PrintScreen to capture full screen; Alt + PrintScreen or Alt + F12 to capture current window
; Require IrfanView (x64) https://www.irfanview.com/
screenshot1=%A_programfiles%\IrfanView\i_view64.exe ;- program
screenshots=D:\files\Drive\data\Screenshots ;- save folder
;-- button printscreen
;-- fullscreen
*~$printscreen::
SetTitleMatchMode, 2
ifexist,%screenshot1%
{
runwait, "%screenshot1%" "/capture=0 /convert=%screenshots%\screenshot_%A_now%.png"
;ifexist, %screenshots%
; run,%screenshots%
return
}
return
~$!printscreen::
!F12::
SetTitleMatchMode, 2
ifexist,%screenshot1%
{
runwait, "%screenshot1%" "/capture=1 /convert=%screenshots%\screenshot_%A_now%.png"
;ifexist, %screenshots%
; run,%screenshots%
return
}
return
;--------------
按 PrintScreen / Alt + PrintScreen 或 F12 / Alt + F12 截图并自动保存到某个文件夹。
需要安装 IrfanView。
IrfanView 默认设置下截图时包含鼠标光标。去除方式:运行一次 IrfanView 程序,点击 Options - Capture/Screenshot, 取消 Options 区域的 "include mouse cursor" 选项,点击 Start,然后再退出。