博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Autohotkey window 下宏键盘、宏命令开发入门
阅读量:7220 次
发布时间:2019-06-29

本文共 21456 字,大约阅读时间需要 71 分钟。

? ? ? ?

我的AHK下载地址:

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

特殊键解决方案(实用):   

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

 

 

SendLevel 控制热键和热字串是否忽略模拟的键盘和鼠标事件.

SendLevel 1Send, canvas.game{tab}

 

GuiControlGet 如果有GUI,那么需要这样用,譬如我的GUI是Pandora

GuiControlGet, OutputVar, Pandora:, ClipHistory, Text

 

获取当前是否为中文输入法

!x::CoordMode PixelImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *25 static/icon/cn.pngImageSearch, FoundX2, FoundY2, 0, 0, A_ScreenWidth, A_ScreenHeight, *25 static/icon/cn2.pngif (FoundX != "" || FoundX2 != "") {    MsgBox, 目前是中文输入法}return

 

标题和聚焦相关

# 获取当前活跃窗口标题WinGetTitle, title, A# 根据title获取当前的ahk_classWinGetClass, outval, 标题名# 获取当前活跃窗口ahk_classWinGetClass, outval, A

 

 无限循环和停止。

ISSTOP := falseF5::Loop {    Click    Sleep, 10        if (ISSTOP) {        break    }}    returnF6::ISSTOP := truereturn

 

 

用IE打开网站示例

run, iexplore.exe http://120.196.128.45:801/ExitApp

官方有批量定义快捷键的方法,但却没有批量定义热字符串的办法,文档又非常不友好,只能艰难的摸索出来。
- 替换热字符串
- 替换label
- 替换函数方法

 

// 1、替换热字符串Loop, 1000 {Hotstring("::h" . A_Index, "height: " . A_Index . "px;") }// 2、替换为labelLoop, 1000 {Hotstring(":X:h" . A_Index, "HEIGHT_HANDLE_LABEL")}HEIGHT_HANDLE_LABEL() {MsgBox, % A_ThisHotkey}// 3、替换函数方法HEIGHT_HANDLE_LABEL() {MsgBox, % A_ThisHotkey}Loop, 1000 {HFN := Func("HEIGHT_HANDLE_LABEL")Hotstring(":X:h" . A_Index, HFN)}

 

 

 

 

如何输出双引号? 其实就是两个双引号即可

Var := "我的名字是 "" Lee "" "MsgBox, % Var

 

正则表达式获取子匹配,请注意下面的 OutputVar4 变量

强烈推荐看看:https://autohotkey.com/boards/viewtopic.php?f=27&t=7888&hilit=%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F

Var := "
"RegExMatch(Var, "im)class(\s*)=(\s*)('|""){1}(.+?)('|""){1}", OutputVar)MsgBox, % OutputVar ; class = 'departmental'MsgBox, % OutputVar4 ; departmental

 

 

换行符和循环输出数组Array

https://wyagd001.github.io/zh-cn/docs/Objects.htm#Usage_Simple_Arrays

https://wyagd001.github.io/zh-cn/docs/misc/Arrays.htm

^!r::    tmp := Clipboard    if (StrLen(tmp)) {        array := StrSplit(tmp, "`n")        For key, value in array            MsgBox %key% = %value%    }return

 

 

执行已定义好的热字符串,Gosub 或者 

https://wyagd001.github.io/zh-cn/docs/Hotstrings.htm

::ff::  MsgBox, 123return::test:: Gosub ::ffreturn

 

 

发送纯文本,这对代码很友好,而且不受输入法的影响,缺点是一旦使用{text},就无法使用#!+这些了

https://wyagd001.github.io/zh-cn/docs/commands/Send.htm#blind

Send, {text} console.log('')Send, {left 2}

 

 

ahk调用cmd示例(暂时不知道如何调用bash)

https://wyagd001.github.io/zh-cn/docs/commands/Run.htm

RunWaitOne(command) {    ; WshShell 对象: http://msdn.microsoft.com/en-us/library/aew9yb99    shell := ComObjCreate("WScript.Shell")    ; 通过 cmd.exe 执行单条命令    exec := shell.Exec(ComSpec " /C " command)    ; 读取并返回命令的输出    return exec.StdOut.ReadAll()}a := RunWaitOne("node -v")MsgBox, % a

 

 

GUI Submit, NoHide 的作用

https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm#ex2

Gui, Add, Text,, First name:Gui, Add, Text,, Last name:Gui, Add, Edit, vFirstName ym  ; ym 选项开始一个新的控件列.Gui, Add, Edit, vLastNameGui, Add, Button, default, OK  ; ButtonOK(如果存在)会在此按钮被按下时运行.Gui, Show,, Simple Input Examplereturn  ; 自动运行段结束. 在用户进行操作前脚本会一直保持空闲状态.GuiClose:ButtonOK:Gui, Submit, NoHide   ; 保存用户的输入到每个控件的关联变量中.MsgBox You entered "%FirstName% %LastName%".ExitApp

 

 

 GUI 的BUTTON的事件绑定

Gui, Add, Button, w740 h30 Default, FUCKButtonFUCK:    ; 保存用户的输入到每个控件的关联变量中.    Gui, Submit, NoHide     MsgBox, 123return

 

 

AHK GUI 布局重点教程

核心API:

  • ys:新列
  • xs:新行,通常结合sction一起使用
  • section:形成一个新的块,通常结合xs一起使用

 

Gui, Add, Text, gAllSearchA W120 yp+10, 搜索引擎类:Gui, Add, Checkbox, gMySubroutine Checked HwndMyEditHwnd vbd, 百度Gui, Add, Checkbox, vgoogle, GoogleGui, Add, Checkbox, vgithub, GithubGui, Add, Checkbox, vso, Stack OverflowGui, Add, Checkbox, vsegmentfault, SegmentFaultGui, Add, Checkbox, vcylee, 博客园Gui, Add, Text, gAllSearchB W120 ys, 翻译类:Gui, Add, Checkbox, vbdfy, 百度翻译   Gui, Add, Checkbox, vyoudaofy, 有道翻译Gui, Add, Checkbox, vgooglefanyi, Google翻译Gui, Add, Text, gAllSearchC W120 ys, 音乐类:Gui, Add, Checkbox, vwy, 网易云音乐   Gui, Add, Checkbox, vqq, QQ音乐Gui, Add, Checkbox, vdog, 酷狗音乐Gui, Add, Checkbox, vxiami, 虾米音乐Gui, Add, Text, gAllSearchD W120 ys, 社区类:Gui, Add, Checkbox, vjuejin, 掘金Gui, Add, Checkbox, vjianshu, 简书Gui, Add, Checkbox, vcsdn, CSDNGui, Add, Checkbox, vzhihu, 知乎Gui, Add, Text, gAllSearchE W120 ys, 购物类:Gui, Add, Checkbox, vtaobao, 淘宝Gui, Add, Checkbox, vjingdong, 京东Gui, Add, Checkbox, vdangdang, 当当Gui, Add, Checkbox, vamazon, 亚马逊Gui, Add, Checkbox, vsuning, 苏宁易购Gui, Add, Text,  W120 Section xs yp+50, 常用导航:Gui, Add, Link,, githubGui, Add, Link,, gitbookGui, Add, Link,, 博客园Gui, Add, Text,  W120 ys, 其他:Gui, Add, Link,, notjQueryGui, Add, Link,, 安卓调试Gui, Add, Link,, AHK官网Gui, Add, Text,  W120 ys, 娱乐:Gui, Add, Link,, 哔哩哔哩Gui, Add, Link,, 嘀哩嘀哩Gui, Add, Link,, Ted魔兽Gui, Add, Link,, 掘金前端Gui, Add, Text,  W120 ys, 代理:Gui, Add, Link,, 西刺Gui, Add, Link,, l337Gui, Add, Link,, 66ipGui, Add, Text, W120 ys, 站长工具:Gui, Add, Link,, 代码格式化Gui, Add, Link,, 代码美化Gui, Add, Link,, jsbeautifierGui, Add, Link,, Urlencode/UnicodeGui, Add, Text,  W120 Section xs yp+40, layer/layui:Gui, Add, Link,, layerGui, Add, Link,, layui文档Gui, Add, Link,, layer示例Gui, Add, Link,, layui-githubGui, Add, Text,  W120 ys, Vue:Gui, Add, Link,, vueGui, Add, Link,, vuexGui, Add, Link,, vue-routerGui, Add, Link,, vue-awesomeGui, Add, Text,  W120 ys, ElementUI:Gui, Add, Link,, ElementUIGui, Add, Link,, Element-githubGui, Add, Text, W120 ys, mint-ui:Gui, Add, Link,, mint-uiGui, Add, Link,, mint-ui-githubGui, Add, Text,  W120 ys, 最近浏览:Gui, Add, Link,, gussGui, Add, Link,, 易码Gui, Add, Link,, 满币网

 

 

获取控件GUI控件的对象

再进一步根据API操作就简单了

Gui, Add, Checkbox, vsuning, 苏宁易购 ; 设置为选中GuiControl,, suning, 1

 

 

设置GUI控件的事件

Gui, Add, Text, gAllSearchD W120 ym, 社区类:AllSearchD:    MsgBox, 123return

 

 

(hack) 在ahk中使用JavaScript

https://autohotkey.com/boards/viewtopic.php?f=6&t=4555

https://github.com/Lexikos/ActiveScript.ahk

#Include 
script := new ActiveScript("JScript")Result := script.Eval("parseInt(Math.random() * 10 + 1)")MsgBox, % Result

 

 

最大化当前窗口和还原当前窗口

!enter::    WinGet, OutputVar, MinMax, A    if (OutputVar == 1) {        WinRestore, A    } else {        WinMaximize, A    }return

 

 

 

获取当前桌面路径:MsgBox, %A_Desktop%

 

GUI的语法

官方demo:https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm#Examples

官方文档:https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm

控件列表:https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm#Add

详细demo:https://www.cnblogs.com/CyLee/p/9198059.html

Gui, Add, Text, W120, 搜索引擎类:Gui, Add, Checkbox, gMySubroutine vbd Checked HwndMyEditHwnd, 百度Gui, Add, Checkbox, vgoogle, GoogleGui, Add, Checkbox, vgithub, GithubGui, Add, Checkbox, vso, Stack OverflowGui, Add, Text, W120 ym, 翻译类:Gui, Add, Checkbox, vbdfy, 百度翻译   Gui, Add, Checkbox, vyoudaofy, 有道翻译Gui, Add, Checkbox, vgooglefanyi, Google翻译Gui, Add, Text, W120 ym, 音乐类:Gui, Add, Checkbox, vwy, 网易云音乐   Gui, Add, Checkbox, vqq, QQ音乐Gui, Add, Checkbox, vdog, 酷狗音乐Gui, Add, Checkbox, vxiami, 虾米音乐Gui, Add, Text, W120 ym, 社区类:Gui, Add, Checkbox, vjuejin, 掘金Gui, Add, Checkbox, vjianshu, 简书Gui, Add, Checkbox, vcsdn, CSDNGui, Add, Checkbox, vzhihu, 知乎Gui, Add, Checkbox, vsegmentfault, SegmentFault; ym 可以 y轴换列,有点类似float:left ,而 xm可以换行,有点类似clear:bothGui, Add, Edit, r9 vFirstName w300 Limit50 ym , 请输入你要搜索的内容Gui, Color, E6FFE6Gui, Margin, 10, 10Gui, Add, Button, w300 h30, OKGui, Show,, Simple Input Examplereturn ; +g 其实就是添加吧MySubroutine:    MsgBox, %MyEditHwnd%    MsgBox, %A_EventInfo%, %A_GuiEvent%, %A_GuiControl%, %A_Gui%returnGuiClose:ButtonOK:Gui, Submit  ; 保存用户的输入到每个控件的关联变量中.    if (bd == 1) {    }return

 

 

 

 

 

自定义托盘到图标

 

 

文本插入

~^c::    Clipboard :=     Send, ^c    ClipWait    time := A_YYYY . "/" . A_MM . "/" . A_DD . " " . A_Hour . ":" . A_Min . ":" . A_Sec    FileAppend, __________________%time%__________________`n`n%Clipboard%`n`n, ./tmp.txtreturn

 

字符串操作:去掉空白、去掉换行、获取长度

if (StrLen(Trim(StrReplace(Clipboard, "`r`n"))) != 0) {}

 

快速搜索demo

!space::    InputBox, OutputVar, title, what's your Q?    if (ErrorLevel == 0)    {        /*        RUN, https://www.zhihu.com/search?type=content&q=%OutputVar%        RUN, https://segmentfault.com/search?q=%OutputVar%        RUN, https://www.google.com/search?q=%OutputVar%        RUN, https://stackoverflow.com/search?q=%OutputVar%        */        RUN, https://www.baidu.com/s?wd=%OutputVar%    }Return

 

 快速搜索音乐demo

; 快速搜索音乐!m::    InputBox, OutputVar, title, enter a music name?    if (OutputVar != "")     {        RUN, http://music.163.com/#/search/m/?s=%OutputVar%        RUN, https://y.qq.com/portal/search.html#w=%OutputVar%        RUN, https://www.xiami.com/search?key=%OutputVar%        RUN, http://www.kugou.com/yy/html/search.html#searchType=song&searchKeyWord=%OutputVar%    }return

 

 

(重要) 使用 #include 引入其他代码段

 https://wyagd001.github.io/zh-cn/docs/commands/_Include.htm

; 这里是htinfo.ahk::test::    MsgBox, 321return; 这里是main.ahk#include htinfo.ahk

 

热键也支持up 和 down到定义

F6 Up::    MsgBox, 123return

 

 

(重要)定义多个热键同个功能

 

修改托盘图标,但不能修改编译好的图标,其实没什么意思

Menu, Tray, Icon, ../static/favicon-201806020842523.ico

 

 

(重要)其实不需要输入到文本,也可以触发的。譬如

::layui::    run, https://github.com/dragon8github/ahk/blob/master/template/layui_template.zip?raw=truereturn

我们只需要输入layui 然后按下回车即可,不一定需要输出到面板。

 

scite4ahk 编辑器中间的神奇运用:鼠标中键列出所有的快捷键和定义。包含#include的东西

 

 

-12、字符串累加,时间输出

>^t::time := A_YYYY . "/" . A_MM . "/" . A_DD . " " . A_Hour . ":" . A_Min . ":" . A_SecSend, % timereturn

 

 

-11、确认框

MsgBox, 4,, Would you like to continue? (press Yes or No)IfMsgBox Yes    MsgBox You pressed Yes.else    MsgBox You pressed No.

 

-10、十分常用的功能,获取当前定义的快捷键A_ThisHotkey

::posa::    SendInput, (position: absolute`;)MsgBox, % A_ThisHotkeyReturn

 

 

-9、叠加剪切板

::Test::clipboard =   Var = (--Start ScriptsendToAHK = function (key)      --print('It was assigned string:    ' .. key)      local file = io.open("C:\\Users\\TaranWORK\\Documents\\GitHub\\2nd-keyboard-master\\LUAMACROS\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better!      --Make sure to substitute the path that leads to your own "keypressed.txt" file, using the double backslashes.      --print("we are inside the text file")      file:write(key)      file:flush() --"flush" means "save"      file:close()      lmc_send_keys('{F24}')  -- This presses F24. Using the F24 key to trigger AutoHotKey is probably NOT the best method. Feel free to program something better!end )RegExMatch(Var, "i)(\b\w+\b)(?CCallout)") Callout(m) {    clipboard .= m . ","   ; __Var__ = %__Var__% . %m%    ;__Array__.Insert(m)    ;MsgBox, % __Var__    ;MsgBox m=%m% `n m1=%m1% `n m2=%m2%    ; __Var__ .= m    return 1}return

 

 

-8、排序

MyVar = 5,3,7,9,1,1,13,999,-4Sort MyVar, U N D,  ; N数值排序, D默认使用逗号作为分隔符, U移除重复项MsgBox %MyVar%   ; 结果是 -4,1,3,5,7,9,13,999*/Return

 

 

 

-7、累加字符串,和php一样, .= 即可

Array := []Array.Insert("d")Array.Insert("a")Array.Insert("b")Array.Insert("c")for index, element in Array ; 在大多数情况下建议使用枚举的方式.{    ; 使用 "Loop", 索引必须是连续的数字, 从 1 到    ; 数组中元素的个数 (或者必须在循环中进行计算).    ; MsgBox % "Element number " . A_Index . " is " . Array[A_Index]    ; 使用"for",同时提供了索引(或"键")及与它关联    ; 的值,并且索引可以是您选择的*任何*值.    ;MsgBox % "Element number " . index . " is " . element    Var .= element    MsgBox, % Var}

 

 

-6、数组的创建和遍历

请注意,数组不能直接msg出来,只能通过for遍历

::arr::    Array := []    Array.Insert("a")    Array.Insert("b")    Array.Insert("c")    Array.Insert("d")        for index, element in Array ; 在大多数情况下建议使用枚举的方式.    {        ; 使用 "Loop", 索引必须是连续的数字, 从 1 到        ; 数组中元素的个数 (或者必须在循环中进行计算).        ; MsgBox % "Element number " . A_Index . " is " . Array[A_Index]        ; 使用"for",同时提供了索引(或"键")及与它关联        ; 的值,并且索引可以是您选择的*任何*值.        MsgBox % "Element number " . index . " is " . element    }Return

 

 

 

-5、打开文本,等待文本,聚焦文本

+d::    InputBox, OutputVar, title, enter your download url?    if (OutputVar != "") {        text := ajax(OutputVar)        RUN, notepad        WinWaitActive, 无标题 - 记事本, , 2        if ErrorLevel {            MsgBox, WinWait timed out.        }        else {            ; 这里需要聚焦一下            Winactivate            code(text)        }    }return

 

 

-4、正则匹配,这里最难和最坑的其实就是对\b的理解

https://wyagd001.github.io/zh-cn/docs/misc/RegExCallout.htm

::Test::Var = (--Start ScriptsendToAHK = function (key)      --print('It was assigned string:    ' .. key)      local file = io.open("C:\\Users\\TaranWORK\\Documents\\GitHub\\2nd-keyboard-master\\LUAMACROS\\keypressed.txt", "w") -- writing this string to a text file on disk is probably NOT the best method. Feel free to program something better!      --Make sure to substitute the path that leads to your own "keypressed.txt" file, using the double backslashes.      --print("we are inside the text file")      file:write(key)      file:flush() --"flush" means "save"      file:close()      lmc_send_keys('{F24}')  -- This presses F24. Using the F24 key to trigger AutoHotKey is probably NOT the best method. Feel free to program something better!end )   ;  FoundPos := RegExMatch(Var, "iO)\s(\w+)|(\w+)\s", SubPat)    ; MsgBox, % Match        ; 保证特征只有一个。那么空格是很好的    ;Haystack = The quick brown fox jumps over the lazy dog.;RegExMatch(Haystack, "i)(\b\w+\b)(?CCallout)")RegExMatch(Var, "i)(\b\w+\b)(?CCallout)") Callout(m) {    MsgBox m=%m% `n m1=%m1% `n m2=%m2%     return 1}return

 

 

-3、GUI

https://wyagd001.github.io/zh-cn/docs/commands/Gui.htm

!q::    Var =     (        审查清单        1、确定设计稿的开发友好性(开发成本、无法完美还原效果图的地方)        2、确定一些特殊的元素是否有合理的边界处理(如文案超出外层容器的情况)                3、确定页面的框架结构(Layout)                4、确定跨页面可复用组件(Site Global Component)                5、确定当前页面可复用组件(Page Component)                ...                把页面想象成一套房子        - HTML:可以决定网页架构结构(房子有几间房,各个区域的用途是什么)        - Css:可以决定网页的样式和布局(房间的颜色,布局,大小,装修,主题,色调)        - JS:决定页面具体交互和功能(智能家居,如空调根据温度自动启动和调节温度,灯光自动调节色温,房门感应自动打开和关闭)    )    Gui, font, s14, Microsoft yahei    Gui, color, f2f2f2    Gui, Add, Text,, %Var%    Gui, Show, W800 H600 X0 Y0 Center AutoSize, 标题    returnReturn

 

 

-2、Send打断文本的解决方案,利用剪切板和复制黏贴

c(code){tmp := ClipboardClipboard := codeSendInput, ^VClipboard := tmp}::gettop::Var = (function getElementTop(element){    try {      var actualTop = element.offsetTop;      var current = element.offsetParent;      while (current !== null){        actualTop += current.offsetTop;        current = current.offsetParent;      }      return actualTop;    } catch (e) {}})c(Var)Return

 

-1、网络下载内容

https://segmentfault.com/a/1190000005041741

::gettop::    whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")    ; Open() 的第三个参数代表同步或者异步,现在不用过多关注,true 就可以了    whr.Open("GET", "https://autohotkey.com/download/1.1/version.txt", true)    whr.Send()    whr.WaitForResponse()    version := whr.ResponseText    MsgBox, % versionReturn

 

::gettop::    whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")    ; Open() 的第三个参数代表同步或者异步,现在不用过多关注,true 就可以了    whr.Open("GET", "https://raw.githubusercontent.com/dragon8github/ahk/master/functions/gettop.js", true)    whr.Send()    TrayTip, 请稍后, 正在为你下载gettop代码,请保持网络顺畅, 20, 17    whr.WaitForResponse()    tmp := Clipboard    Clipboard := whr.ResponseText    send, ^V    Clipboard := tmp    TrayTip, 下载成功, (づ ̄3 ̄)づ╭❤~ , 20, 17Return

 

 

 

 

1、官方示例

#z::Run https://autohotkey.com^!n::if WinExist("Untitled - Notepad")    WinActivateelse    Run Notepadreturn

 

1.0 、设置终止符(重要)

https://wyagd001.github.io/zh-cn/docs/Hotstrings.htm#EndChars

Hotstring("EndChars", "`n`t ")  ; 设置为回车键、tab键和空格键 默认是这个: Hotstring("EndChars", "-()[]{}:;")

 

1.1.1 将中文符号强制转换为英文

; 无视输入法状态发送字符串uStr函数uStr(str){    charList:=StrSplit(str)    SetFormat, integer, hex        for key,val in charList        out.="{U+ " . ord(val) . "}"    return out},::SendInput % uStr(",")​?::SendInput % uStr("?")​.::SendInput % uStr(".")​!::SendInput % uStr("!"){::SendInput % uStr("{
")}::SendInput % uStr("}")[::SendInput % uStr("[")]::SendInput % uStr("]")`;::SendInput % uStr(";")>+;::SendInput % uStr(":")(::SendInput % uStr("("))::SendInput % uStr(")")>+':: a = " SendInput % uStr(a)Return':: a = ' SendInput % uStr(a)Return

 

 

 

 

 

1.1、快速重启脚本

!r::    send, ^s    reloadReturn

 

1.2、使用常量,获取年月日

!d::    Send, %A_YYYY%/%A_MM%/%A_DD%Return

 

 1.3、赋值剪切板

!x::    a = fuck you!!!!!!    Clipboard = %a%Return

 

 

2、快捷输入

^j::    Send, My First ScriptReturn

 

2.1、明白 Send,和 SendInput的区别。前者是慢慢输入,后者是直接输入

::dg::    Send, document.getElementById('')`;{left 3}Return::dg::    SendInput, document.getElementById('')`;{left 3}Return

 

3、补全

::ftw::Free the whales

输入 ftw 然后按下【空格、tab、回车、分号,感叹号等许多键时,会自动补全Free the whales】

 

4、弹出层

esc::    MsgBox Escape!!!!Return

 

5、弹出层2

::btw::    MsgBox You typed "btw".Return

 

 6、连续

^j::    MsgBox Wow!    MsgBox this is    Run, Notepad.exe     #IfWinActive 无标题 - 记事本     WinWaitActive, 无标题 - 记事本    Send, 7 lines{!}{enter}    SendInput, inside the ctrl{
+}j hotkeyReturn

 亮点在于 #IfWinActive 无标题 - 记事本 和  WinWaitActive, 无标题 - 记事本。

前者是判断当前是否为记事本,后者是等待

 

7、组合键

Numpad0 & Numpad1::    MsgBox You pressed Numpad1 while holding down Numpad0.ReturnNumpad0 & Numpad2::    Run NotepadReturn

同时按下0+1或者0+2试试,就像按Ctrl + C 一样即可,但必须是右侧九宫格

 

 8、案例3的加强版,自动补全不需要其他按键

:*:ftw::Free the whales

输入 ftw就自动变成Free the whales

 

9、监听当前窗口,其实案例6就已经展示了。这里再补习一下

#IfWinActive 无标题 - 记事本#space::    MsgBox You pressed Win+Spacebar in Notepad.Return

新开一个nodepad,然后按下快捷键即可。非常实用

 

10、如何添加注释

; 这是注释#IfWinActive 无标题 - 记事本!q::    MsgBox, You pressed Alt and Q in Notepad.Return#IfWinActive

 

 11、#IfWinActive作用域、代码块 下才有效

; Notepad#IfWinActive ahk_class Notepad#space::    MsgBox, You pressed Win+Spacebar in Notepad.Return::msg::You typed msg in Notepad#IfWinActive

 只有在Nodepad下输入msg + 【enter、space...等键】才有效果

 

12、输入 j 补全

~j::    Send, ackReturn

 

 13、多个监听

#i::    Run, http://www.baidu.com/Return^p::    Run, notepad.exeReturn~j::    Send, ackReturn:*:acheiv::achiev::achievment::achievement::acquaintence::acquaintance:*:adquir::acquir::aquisition::acquisition:*:agravat::aggravat:*:allign::align::ameria::America

 

 14、组合键

^b::                                          Send, {ctrl down}c{ctrl up}               ; 等于按下Ctrl + C ,然后松开Ctrl键     SendInput, [b]{ctrl down}v{ctrl up}[/b]   ; 输入[b]然后按下Ctrl + V,松开Ctrl键,然后输入[/b]Return

正式开发不可能那么复杂,而是使用热键,譬如

^b::                                          Send, ^c               ; 等于按下Ctrl + C ,然后松开Ctrl键     SendInput, [b]^v[/b]   ; 输入[b]然后按下Ctrl + V,松开Ctrl键,然后输入[/b]Return

 

 15、send换行快速使用enter

>^i::                                      Send,(Line 1Line 2Apples are a fruit.)

 

 16、函数的使用

Add(x, y){    return x + y  }^j::    Send, % Add(2, 3)Return

 

17、函数直接Send,表达式,记得要加%

Add(x, y){    Send, % x + y}^j::    Add(2, 3)Return

 

 18、函数,拼接字符串

Add(x){    return "{
{}" x "{}}"}^j:: Send, % Add("//...")Return

 

19、新建菜单,大有作为的工具

更多实例请参考:https://wyagd001.github.io/zh-cn/docs/commands/Menu.htm

我的做法和官方的做法不一样,而且也不符合复用和缓存的理念。但却非常实用,更关键的是能用!如果按照官方的做法是有问题的。在正式实战的时候

menu,add 默认会去掉重复项,但却不会去掉分隔符,也就是空值,所以为了方便直接每次显示完后删除所有最好了。

!p::    ; Create the popup menu by adding some items to it.    Menu, PythonMenu, Add, Item1, PythonHandler    Menu, PythonMenu, Add, Item2, PythonHandler    Menu, PythonMenu, Add  ; Add a separator line.    ; Create another menu destined to become a submenu of the above menu.    Menu, Submenu1, Add, Item1, PythonHandler    Menu, Submenu1, Add, Item2, PythonHandler    ; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.    Menu, PythonMenu, Add, My Submenu, :Submenu1    Menu, PythonMenu, Add  ; Add a separator line below the submenu.    Menu, PythonMenu, Add, Item3, MenuHandler  ; Add another menu item beneath the submenu.    Menu, PythonMenu, Show  ; i.e. press the Win-Z hotkey to show the menu.    Menu, PythonMenu, DeleteAllreturnPythonHandler:    MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.return

 

 

20、弹窗获取用户输入

https://wyagd001.github.io/zh-cn/docs/commands/InputBox.htm

#space::InputBox, OutputVar, title, enter a music name?if (OutputVar!="")   MsgBox, That's an awesome name, %OutputVar%.

 也可以用 ErrorLevel 来区分用户点击的是确认还是取消

InputBox, UserInput, Phone Number, Please enter a phone number., , 640, 480if ErrorLevel    MsgBox, CANCEL was pressed.else    MsgBox, You entered "%UserInput%"

 

21、获取鼠标位置的颜色

!a::  ; Control+Alt+Z hotkey.MouseGetPos, MouseX, MouseYPixelGetColor, color, %MouseX%, %MouseY%Clipboard = %color%return

 

22、弹出气泡提示TrayTip

https://wyagd001.github.io/zh-cn/docs/commands/TrayTip.htm

!a::MouseGetPos, MouseX, MouseYPixelGetColor, color, %MouseX%, %MouseY%Clipboard = %color%TrayTip, my title, current color is `n %color%, 20, 17return

 

23 关闭输入法

SwitchIME(dwLayout){    HKL:=DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1)    ControlGetFocus,ctl,A    SendMessage,0x50,0,HKL,%ctl%,A}esc::    ; 下方代码可只保留一个    SwitchIME(0x08040804) ; 英语(美国) 美式键盘    ;SwitchIME(0x04090409) ; 中文(中国) 简体中文-美式键盘return

 

你可能感兴趣的文章
完整部署CentOS7.2+OpenStack+kvm 云平台环境
查看>>
iOS开发证书都显示“此证书的签发者无效”,更新WWDR Certificate证书后还是显示无效...
查看>>
android多语言与国际化
查看>>
ThinkPHP 调用编辑器
查看>>
多文件上传,并生成缩略图
查看>>
sprintf函数分析
查看>>
redis源码分析-1 字符串处理
查看>>
return 、continue和break的区别
查看>>
RabbitMQ中的基本概念
查看>>
解决nginx下载大文件出现文件损坏,文件大小不一致
查看>>
fineui 时间控件 与格式化时间字符串方式 DateTime.ParseExact
查看>>
idea debug 接收命令行运行的项目
查看>>
Oracle Java Archive
查看>>
按需加载js文件功能实现
查看>>
apache shiro与spring整合、动态filterChainDefinitions、以及认证、授权
查看>>
TCP古董TIME_WAIT:为什么被动关闭的一方不需要TIME_WAIT傻等呢,似乎人人都了然了...
查看>>
javascript 获取和设置CSS的当前属性
查看>>
iOS 沙盒 NSCoding 归档 数据存储
查看>>
多重赋值
查看>>
运行topology出现错误
查看>>