AutoHotKey 常用脚本
1 ; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a 2 ; semicolon, such as this one, are comments. They are not executed. 3 4 ; This script has a special filename and path because it is automatically 5 ; launched when you run the program directly. Also, any text file whose 6 ; name ends in .ahk is associated with the program, which means that it 7 ; can be launched simply by double-clicking it. You can have as many .ahk 8 ; files as you want, located in any folder. You can also run more than 9 ; one .ahk file simultaneously and each will get its own tray icon. 10 11 ; SAMPLE HOTKEYS: Below are two sample hotkeys. The first is Win+Z and it 12 ; launches a web site in the default browser. The second is Control+Alt+N 13 ; and it launches a new Notepad window (or activates an existing one). To 14 ; try out these hotkeys, run AutoHotkey again, which will load this file. 15 16 ;让脚本持久运行 (即直到用户关闭或遇到 ExitApp). 17 ;#Persistent 18 19 ;强制加载新的脚本 20 #SingleInstance force 21 22 ;尝试加载图标 23 IfExist, icon.ico ;花括号“{”不能和 IfExist 写在同一行 24 { 25 Menu TRAY, Icon, icon.ico ;这句会把 icon.ico 作为图标 26 } 27 28 ;定时器 输入为分钟数 29 #t:: 30 ; 弹出一个输入框,标题 内容 31 InputBox ,time,定时器,请输入一个时间(单位是分钟),,200,100 ;InputBox, time, 计时器, 请输入一个时间(单位是分钟) 32 time := time*1000*60 ; 变量赋值,多一个冒号,乘以 1000*60 变time为分钟数 33 Sleep,%time% 34 MsgBox,,提示信息, 打卡啦 35 return 36 37 /* 38 ;打开ie浏览器 39 #1:: 40 run C:\Program Files\Internet Explorer\iexplore.exe 41 return 42 43 ;打开firefox浏览器 44 #2:: 45 ;run D:\Program Files\Mozilla Firefox\firefox.exe 46 run C:\Documents and Settings\koujincheng\Local Settings\Application Data\Google\Chrome\Application\chrome.exe 47 return 48 */ 49 50 ;打开everything 51 ^!e:: 52 Run D:\Program Files\everything\Everything.exe 53 return 54 55 ;打开任务管理器 56 ^!K:: 57 Run taskmgr 58 return 59 60 ;打开远程连接 61 ^!m:: 62 Run mstsc 63 return 64 65 ;新建或激活记事本窗口 66 ^!n:: 67 IfWinExist ahk_class Notepad 68 WinActivate 69 else 70 Run Notepad 71 return 72 73 ;UltraEdit32 74 ^!u:: 75 Run D:\Program Files\UltraEdit\Uedit32.exe 76 return 77 78 ;截图工具 FSCapture 79 ^!c:: 80 Run D:\Program Files (x86)\FScapture\FSCapture.exe 81 return 82 83 ; Foxmail 84 ^!f:: 85 Run D:\Program Files (x86)\Foxmail7.2\Foxmail.exe 86 return 87 88 ; P2PSearcher 89 ^!p:: 90 Run D:\Program Files (x86)\P2PSearchers\P2PSearcher.exe 91 return 92 93 ;重新加载脚本 94 ^!r::Reload ; Assign Ctrl-Alt-R as a hotkey to restart the script. 95 96 ;##################################################window script############################################################# 97 ;###################################################窗口操作################################################################# 98 99 ;最大化或还原(取消最大化)窗口 100 ~LAlt:: 101 Keywait, LAlt, , t0.3 102 if errorlevel = 1 103 return 104 else 105 Keywait, LAlt, d, t0.3 106 if errorlevel = 0 107 { 108 WinGet, DAXIAO , MinMax, A 109 if (DAXIAO = "1") 110 { 111 PostMessage, 0x112, 0xF120,,, A ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE 112 } 113 else 114 { 115 PostMessage, 0x112, 0xF030,,, A ; 0x112 = WM_SYSCOMMAND, 0xF030 = SC_MAXIMIZE 116 } 117 } 118 return 119 120 ;最小化窗口 记录最后三个最小化的窗口 121 ~RAlt:: 122 Keywait, RAlt, , t0.3 123 if errorlevel = 1 124 return 125 else 126 Keywait, RAlt, d, t0.3 127 if errorlevel = 0 128 { 129 If (WinActive("ahk_class Progman") or WinActive("ahk_class WorkerW")) 130 { 131 } 132 else 133 { 134 Last_Max_Id=0 135 WinGet, Last_Min_Id, ID, A 136 if (MinMemo1 = "0") 137 MinMemo1=%Last_Min_Id% 138 else if(MinMemo2 = "0") 139 { 140 MinMemo2=%MinMemo1% 141 MinMemo1=%Last_Min_Id% 142 } 143 else 144 { 145 MinMemo3=%MinMemo2% 146 MinMemo2=%MinMemo1% 147 MinMemo1=%Last_Min_Id% 148 } 149 IfWinNotActive ahk_class TXGuiFoundation 150 WinMinimize, A 151 else ;qq窗口使用ctrl+alt+z 最小化 152 { 153 WinGetTitle, Temp0 , A 154 If Temp0 contains QQ20 155 { 156 sleep,100 157 Send, {CTRLDOWN}{ALTDOWN}z{ALTUP}{CTRLUP} 158 } 159 else 160 WinMinimize, A 161 } 162 } 163 } ;end if errorlevel = 0 164 return 165 ;恢复最小化的窗口,最多三个(只能识别通过脚本最小化的窗口) 166 >!Space:: 167 if (MinMemo1 = "0") ;不存在通过脚本最小化的窗口 168 { 169 WinRestore, A 170 WinActivate,A 171 } 172 else if (MinMemo2 = "0") ;只有一个 173 { 174 WinRestore, ahk_id %MinMemo1% 175 WinActivate, ahk_id %MinMemo1% 176 MinMemo1=0 177 } 178 else if (MinMemo3 = "0") 179 { 180 WinRestore, ahk_id %MinMemo1% 181 WinActivate, ahk_id %MinMemo1% 182 MinMemo1=%MinMemo2% 183 MinMemo2=0 184 } 185 else 186 { 187 WinRestore, ahk_id %MinMemo1% 188 WinActivate, ahk_id %MinMemo1% 189 MinMemo1=%MinMemo2% 190 MinMemo2=%MinMemo3% 191 MinMemo3=0 192 } 193 return 194 195 ;关闭窗口,在浏览器中为关闭标签页 196 ~Esc:: 197 Keywait, Esc, , t0.5 198 if errorlevel = 1 199 return 200 else 201 Keywait, Esc, d, t0.2 202 if errorlevel = 0 203 { 204 IfWinActive ahk_class ahk_class IEFrame ;识别IE浏览器 205 Send {ctrldown}w{ctrlup} 206 else IfWinActive ahk_class MozillaWindowClass ;识别firfox 浏览器 207 Send {ctrldown}w{ctrlup} 208 else 209 send !{F4} 210 } 211 return 212 213 ;##################################################other script############################################################# 214 ;###################################################其它脚本################################################################ 215 216 217 ;快速按下两次Ctrl 快速粘贴 218 /* 219 ~LCtrl:: 220 Keywait, LCtrl, , t0.5 221 if errorlevel = 1 222 return 223 else 224 Keywait, LCtrl, d, t0.3 225 if errorlevel = 0 226 { 227 Send,^v 228 } 229 return 230 */ 231 232 233 ;win+shift+f 在桌面上建立一个以当前日期命名的文件夹 234 #+f:: 235 Click right ;在桌面当前鼠标所在位置点击鼠标右键 236 Send, wf ;快捷键新建文件夹 237 Sleep, 125 ; 把暂停时间改小 238 clipboard = %A_MM%-%A_DD%-%A_YYYY% ;%A_Hour%-%A_Min%-%A_Sec%-%A_MSec%;把当前的系统日期发送到剪贴板 239 Send, ^v{Enter} ;发送 Ctrl + v 和回车确认修改文件夹名称 240 return 241 242 ;ctrl+win+c 得到当前选中文件的路径,保存到剪贴板中 243 ^#c:: 244 send ^c 245 sleep,200 246 clipboard=%clipboard% ;解释:windows复制的时候,剪贴板保存的是“路径”.只是路径而不是字符串,只要转换成字符串就可以粘贴出来了 247 tooltip,%clipboard% ;提示文本 248 sleep,2000 249 tooltip, ;置空 250 return 251 252 ; Win+O 关闭显示器 253 #o:: 254 Sleep 1000 ; 让用户有机会释放按键 (以防释放它们时再次唤醒显视器). 255 SendMessage, 0x112, 0xF170, 2,, Program Manager ; 关闭显示器: 0x112 为 WM_SYSCOMMAND, 0xF170 为 SC_MONITORPOWER. ; 可使用 -1 代替 2 打开显示器,1 代替 2 激活显示器的节能模式 256 return 257 258 ;获取当前系统日期 259 ::ddd:: 260 ;获得系统时间比如今天的时间:2013-07-17。如果需要“年”的话请替换上面的“-”。 261 d = %A_YYYY%-%A_MM%-%A_DD% 262 ;把 d 的值发送到剪贴板,变量不用声明,引用变量的值时在变量的前后加“%”。clipboard是 AHK 自带的变量:剪切板 263 clipboard = %d% 264 Send ^v 265 return 266 267 ;获取当前系统时间 268 ::/time:: 269 d = %A_Hour%:%A_Min%:%A_sec% 270 clipboard = %d% 271 Send ^v 272 return 273 274 ;获取系统日期和时间 275 ::/all:: 276 d = %A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_sec% 277 clipboard = %d% 278 Send ^v 279 return 280 281 ::/kou:: 282 Send , koujincheng{Shift}{Tab}1234.abcdd{Enter} 283 return 284 285 ;选中路径,快速打开 286 #j:: 287 send ^c ; 复制选中的文字 288 clipwait ; 等待复制动作的完成 289 Clipboard := Trim(clipboard,A_Space) ;去除空格 290 Run %clipboard% 291 return 292 293 294 ; Note: From now on whenever you run AutoHotkey directly, this script 295 ; will be loaded. So feel free to customize it to suit your needs. 296 297 ; Please read the QUICK-START TUTORIAL near the top of the help file. 298 ; It explains how to perform common automation tasks such as sending 299 ; keystrokes and mouse clicks. It also explains more about hotkeys.