? ? ? ?
我的AHK下载地址:https://github.com/dragon8github/Pandora/raw/master/pandora.exe
AutoHotKey 下载:https://autohotkey.com/download/
国内自制的ahk网站:https://www.autoahk.com/
推荐下载installer
官方网站:https://www.autohotkey.com/docs/AutoHotkey.htm
中文官网:https://wyagd001.github.io/zh-cn/docs/Tutorial.htm
AHK脚本编辑器推荐:http://fincs.ahk4.net/scite4ahk/ | https://wyagd001.github.io/zh-cn/docs/commands/Edit.htm#Editors
个人推荐使用sublime text作为autohotkey的编辑器,只需要安装aotuhotkey插件即可。
常量列表,十分实用:https://wyagd001.github.io/zh-cn/docs/Variables.htm#DD
优秀的脚本合集:https://www.autoahk.com/archives/1444
特殊键解决方案(实用):https://blog.csdn.net/liuyukuan/article/details/5924137 https://wyagd001.github.io/zh-cn/docs/KeyList.htm#SpecialKeys
GUI的一些布局API:https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm#PosSize
使用html做ahk界面:https://blog.csdn.net/liuyukuan/article/details/53504400
(重要)使用SciTE4AutoHotkey,出现中文怪异的问题。
左上角File--Encoding---UTF-8 with BOM
1、代码加入 #InstallKeybdHook,并且开启脚本
2、左键点击右下角的图标 -> View -> Key History
将ahk编译成exe:http://ahkcn.sourceforge.net/docs/Scripts.htm#ahk2exe
快捷键
Symbol | Description |
---|---|
# | Win (Windows logo key) |
! | Alt |
^ | Control / Ctrl |
+ | Shift |
& | An ampersand may be used between any two keys or mouse buttons to combine them into a custom hotkey. |
默认是左侧的,如果想要右侧的加入< >即可,譬如按下右侧的ctrl , 那就是 >^
更多热键请参考:
(重要,推荐)https://autohotkey.com/docs/Hotkeys.htm
https://autohotkey.com/docs/Hotkeys.htm
https://autohotkey.com/docs/commands/Send.htm
动态添加热键
__TIP__(a = 123) {MsgBox, % a }!z::HFN := Func("__TIP__")Hotstring(":*:fuck", HFN.bind("321")) return
GET请求,解决乱码问题
; 下载内容 ajax(url, q:=false, text:="正在为你下载代码,请保持网络顺畅") {whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")whr.Open("GET", url, true)whr.SetRequestHeader("Content-Type", "charset=GB2312")whr.Send()whr.WaitForResponse()if (q==false) {if (whr.ResponseText) {tip("下载成功")} else {tip("无内容返回")}}arr := whr.responseBodypData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)length := arr.MaxIndex() + 1text := StrGet(pData, length, "utf-8")return text; return whr.ResponseText }
AHK 解析JSON库
https://github.com/cocobelgica/AutoHotkey-JSON
#Include src/JSON.ahk ; JSON Script!z:: str = ( {"a": 123 } )data := JSON.Load(str)MsgBox, % data.a return
注意索引是从1开始的。所以如果是数组,第一个的索引是1
!z:: json_str := ajax("https://gitee.com/api/v5/gists?access_token=6ab92e291bbe59b4301191b6aef2bc85&page=1&per_page=20")data := JSON.Load(json_str)MsgBox, % data[1].url return
AHK 解析和使用JSON,依赖 ActiveScript.ahk
https://github.com/Lexikos/ActiveScript.ahk
#Include src/ActiveScript.ahkjsonstr := "{a: 123}"jsonParse = ( eval('(' + jsonstr + ')') )script := new ActiveScript("JScript") Result := script.Eval(jscontent) MsgBox, % Result.a
AHK GUI 布局工具 SmartGUI Creator
https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm#Position
两个关于索引的重要认知:
1、SubStr 字符串截取,如果你想从后面开始取,那么索引应该设置为0,比如SubStr("123", 0, 1);
2、数组的第一位,是从1开始的。恶心吧?
获取按钮的状态
; 左键是否按紧了 KeyIsDown := GetKeyState("LButton")
KeyIsDown := GetKeyState("Alt")
KeyIsDown := GetKeyState("Ctrl")
powershell.exe 与 ahk结合
!z:: ; zip名字 zipname := "vue3-template.zip" ; 文件夹名字 zippath := "./vue3-template" ; 下载文件的地址 url := "https://raw.githubusercontent.com/dragon8github/Pandora/master/template/vue3-template.zip" ; 由于要使用git命令,所以要将window格式转化为unix格式的路径 desk := StrReplace(A_Desktop, "\", "/") ; 文件夹的名字 name := desk . "/vue3_template_" . A_YYYY . A_MM . A_DD . A_Hour . A_Min . A_Sec ; 一系列命令 command = ( mkdir %name% ; cd %name% ; Invoke-WebRequest -uri "%url%" -OutFile "%zipname%" ; Expand-Archive -Path %zipname% -DestinationPath . ; rm %zipname% ) run, powershell.exe %command% return
热字符串定义一个很重要的技巧:
::.f:: Var = ( .forEach((val, key) => {}) ) code(Var) return::f:: Var = ( function () {} ) code(Var) return
我定义了.f 和 f ,但如果我输出 a.f , 我期待触发 .f , 但实际上是除非 f
其实这样这样设置 .f即可。 :?:.f::
:?:.f:: Var = ( .forEach((val, key) => {}) ) code(Var) return
关闭进程,其实特别实用
https://wyagd001.github.io/zh-cn/docs/commands/Process.htm#ex1
Run notepad.exe,,, NewPID Process, Priority, %NewPID%, High MsgBox The newly launched Notepad's PID is %NewPID%.
全局变量global,居然只能这样使用?
txtit() {; 全局变量真的只能这样用了,定义在外面没有办法生存。global pidary := pidary ? pidary : []pidary.push("110")return }!x:: txtit() txtit() txtit() MsgBox, % pidary.Length() return
强大的 Spy 探测检测窗口的信息。
只需要右键小图标,选中 spy window 即可,最好选中右上角的 Follow Mouse 方便选中。我们来实战一下如何查看搜狗输入法的窗口
我们得知输入法的窗口信息为: ‘ahk_class SoPY_Comp’。这样我就能搞很多事情了。
if (WinExist("ahk_class SoPY_Comp")) {MsgBox, 123}
后记:win10的输入法有问题,就算能获取,Send的时候也很多问题。最大的问题在于哪怕出现输入法了,还是会在UI中输出英文,最好的办法还是使用搜狗等第三方吧。
建议屏蔽win10输入法:https://jingyan.baidu.com/article/ed2a5d1f99277909f7be1753.html
Run,% "C:\Windows\notepad.exe",,, pidWinWait, ahk_pid %pid%WinMove, ahk_pid %pid%,, 0, 0, (A_ScreenWidth)/3, (A_ScreenHeight)Return
listview 点击事件(click,rightclick)
必须设置AltSubmit参数才行。
Gui, ISearch:Add, ListView, r7 w800 h600 gMyListView AltSubmit xs yp+40, Name|PathMyListView: if (A_GuiEvent = "Normal") {MsgBox, %A_EventInfo% }if (A_GuiEvent = "RightClick") {MsgBox, %A_EventInfo% } return
GUI的关闭事件
GuiEscape:
GuiClose:Gui, Hide