AutoHotKey使用教程 下载本文

内容发布更新时间 : 2024/5/16 4:58:22星期一 下面是文章的全部内容请认真阅读。

Numpad9 NumpadPgUp

NumpadDot (.) NumpadDel NumpadDiv (/) NumpadDiv (/) NumpadMult (*) NumpadMult (*) NumpadAdd (+) NumpadAdd (+) NumpadSub (-) NumpadSub (-) NumpadEnter

NumpadEnter

1 a A LWin Control (or Ctrl) Alt Shift F1

PrintScreen CtrlBreak Pause Break

AutoHotKey使用教程(七)-----AutoHotkey脚本

AutoHotkey跟tcl等语言一样,是一种解释性语言。从脚本的头部至结尾顺序执行,除非遇到return,exit或者热键、热字符串。

一个AutoHotkey脚本如果不包含热键、热字符串、OnMessage或者 GUI等,就会在文件执行完成后推出,否则脚本会处于idle状态以备相应热键、热字符串等操作。

`的用法类似于c和tcl中的“\\”,例如`t (tab), `n (linefeed), and `r (carriage return).

Autohotkey中逗号和百分号都有专门的意义,如果要表示字符意义,可以使用`, `%。

MsgBox This is ok.

MsgBox, This is ok too (it has an explicit comma).

AutoHotkey脚本使用“;”注释,“;”跟在需注释的语句之后,注意语句和分号之间只要要有一个空格。如果要注意多个语句可以使用/* */ Run Notepad ; This is a comment on the same line as a command. /*

MsgBox, This line is commented out (disabled). MsgBox, This one too.

*/

为了增加脚本的可读性和可维护性,有时需要将一个较长的语句拆分成几个较小的语句,可以使用以下几种方法:

1) 一行以\\||, &&或者逗号开始,会自动跟上一句组合成一句。 FileAppend, This is the text to append.`n ; A comment is allowed here.

, %A_ProgramFiles%\\SomeApplication\\LogFile.txt ; Comment. if (Color = \ or Color = \or Color = \or Color = \Comment.

and ProductIsAvailableInColor(Product, Color) ; Comment. 2)这种方法适用于要连接很多行并且方法1不适用的情况。 ; EXAMPLE #1: Var = (

Line 1 of the text.

Line 2 of the text. By default, a linefeed (`n) is present between lines. )

; EXAMPLE #2:

FileAppend, ; The comma is required in this case. (

A line of text.

By default, the hard carriage return (Enter) between the previous line and this one will be written to the file as a linefeed (`n).

By default, the tab to the left of this line will also be written to the file (the same is true for spaces).

By default, variable references such

把所有要组合在一起的行放在一个圆括号内。

可以使用ahk2exe工具把Script 转换成 EXE文件(可以选用自己喜欢的图标)。也可以右键.ahk文件,选“Compile Script”进行编译。也可以使用命令行:

Ahk2exe.exe /in MyScript.ahk [/out MyScript.exe][/icon MyIcon.ico][/pass password][/NoDecompile] Pikka注意了一下,编译后文件会变的比较大。

AutoHotkey脚本允许设置断点,在需要设置断点的地方放上下面两句话就可以了,脚本运行到这个位置就会打印当前的变量。 ListVars Pause

AutoHotKey使用教程(八)-----变量和表达式

AutoHotkey没有显示地定义一些变量类型,所有的变量都是字符串类型。 AutoHotkey里面的所有的变量都是全局变量,能被文件内任何位置引用。除非在函数里面声明的,是局部变量,只能在函数内部引用。AutoHotkey的变量不需要声明直接使用。

变量的名字不区分大小写,长度最长254个字母。 变量的存储有两种方法:

方法1:使用“=”去定义数字、没带引号的字符串和带%的变量 MyNumber = 123

MyString = This is a literal string.

CopyOfVar = %Var% ; With the = operator, percent signs are required to retrieve a variable's contents.

方法2:使用“:=”去定义数字,带引号的字符串和不带%的变量 MyNumber := 123

MyString := \

CopyOfVar := Var ; Unlike its counterpart in the previous section, percent signs are not used with the := operator.

同样的,变量的引用也有两种方法: 方法1:

Var = 123

MsgBox The value in the variable named Var is %Var%. 方法2:

var := 123

MsgBox % \ 表达式的两个例子

NetPrice := Price * (1 - Discount/100)

if (CurrentSetting > 100 or FoundColor <> \

MsgBox The setting is too high or the wrong color is present. AutoHotkey支持的运算符包括:%Var%、++ --、**、- ! ~ & *、* / //、+ -、<< >>、& ^ |、. 、> < >= <=、= == <> !=、NOT、AND &&、OR ||、?:、:= += -= *= /= //= .= |= &= ^= >>= <<=、, 、 mod()、round()、abs() 下面这些变量是内嵌在程序中,有特殊的含义,任何脚本都可以引用它们,只能读不能写。

Special Characters: A_Space, A_Tab

Script Properties: command line parameters, A_WorkingDir, A_ScriptDir, A_ScriptName, (...more...)

Date and Time: A_YYYY, A_MM, A_DD, A_Hour, A_Min, A_Sec, (...more...) Script Settings: A_IsSuspended, A_BatchLines, A_TitleMatchMode, (...more...)

User Idle Time: A_TimeIdle, A_TimeIdlePhysical

GUI Windows and Menu Bars: A_Gui, A_GuiControl, A_GuiEvent, A_EventInfo

Hotkeys, Hotstrings, and Custom Menu Items: A_ThisHotkey, A_EndChar, A_ThisMenuItem, (...more...)

Operating System and User Info: A_OSVersion, A_ScreenWidth, A_ScreenHeight, (...more...)

Misc: A_Cursor, A_CaretX, A_CaretY, Clipboard, ClipboardAll, ErrorLevel

Loop: A_Index, (...more...)

AutoHotKey使用教程(九)-----函数

一个函数的简单的例子: Add(x, y) {

return x + y ; \Return\expression. }

函数调用时,变量的后面使用:= Var := Add(2, 3) ;

由于一个函数调用就是一个表达式,所以函数的参数列表里面的变量前面不能加百分号“%”,相反的,字符串要使用引号,请看下面的例子: if InStr(MyVar, \

MsgBox The variable MyVar contains the word fox.

当一个命令的参数调用函数的时候,如果命令的参数不支持表达式,就必须使用百分号“%”,请看下面的例子: MsgBox % \. Add(3, 2)

一个函数可以带参数也可以不带参数(类似C中的过程)。

函数的参数列表里的变量是局部变量,除非前面增加修饰符“ByRef”。 Swap(ByRef Left, ByRef Right)