AHK语法整理

AHK语法(官方文档

字符串

  1. 字符串拼接
    • 隐式:"the value is " my_value(空格或制表符)
    • 显示:"the value is " . my_value
  2. 格式化
    • format("{1}, {2}", value1, value2)

常用函数

  1. msgbox % format("test {1}", c)(%表示动态)

数组

  • 普通数组[1, 2, 3]
  • 联合数组{"key1" : A, (key2) : B}

操作符

  • %变量%:

例1

MsgBox % "Hello %A_UserName%."  ; Shows "%A_UserName%"
MsgBox    Hello %A_UserName%.   ; Shows your username.

例2

target := 42
second := "target"
MsgBox   %second%  ; Normal (single) variable reference in text => target
MsgBox %  second   ; Normal (single) variable reference in an expression => target
MsgBox % %second%  ; Double-deref in an expression => 42
  • :=, =:赋值
  • ```````:转义(`r, `n)

条件

if (Var1 >= Low and Var1 <= High)
if Var1 between %Low% and %High% 
<>, !=, =, >, >=, <, <=, and, or, ||, &&
break, continue
  • if
    • If Var
    • If Var op Value, where op is one of the following operators: =, <>, !=, >, >=, <, <=.
    • If Var [not] between Lower and Upper
    • If Var [not] in/contains MatchList
    • If Var is [not] Type
  • loop
    t := "column 1`tcolumn 2`nvalue 1`tvalue 2"
    Loop Parse, t, `n
    {
        rowtext := A_LoopField
        rownum := A_Index  ; Save this for use in the second loop, below.
        Loop Parse, rowtext, `t
        {
            MsgBox %rownum%:%A_Index% = %A_LoopField%
        }
    }
    
    • Loop Count executes a statement repeatedly: either the specified number of times or until break is encountered.
    • Loop Reg retrieves the contents of the specified registry subkey, one item at a time.
    • Loop Files retrieves the specified files or folders, one at a time.
    • Loop Parse retrieves substrings (fields) from a string, one at a time.
    • Loop Read retrieves the lines in a text file, one at a time.
    • While executes a statement repeatedly until the specified expression evaluates to false. The expression is evaluated before each iteration.
    • For executes a statement once for each value or pair of values returned by an enumerator, such as each key-value pair in an object.

函数

MyFunction(FirstParameter, Second, ByRef Third, Fourth:="")
{
    ...
    return "a value"
}
  • ByRef:引用调用
  • Optional:可选参数
  • 可以用#include包含含有函数定义的文件

其他

  • #if等

    #if GetKeyState("[") && GetKeyState("]")
    \::MsgBox
    

    只有[]\三个键按下触发

    if GetKeyState("[") && GetKeyState("]")
    \::MsgBox
    

    只要[]\三个键按下触发

发布了8 篇原创文章 · 获赞 0 · 访问量 24

猜你喜欢

转载自blog.csdn.net/u014182377/article/details/105715610
AHK
今日推荐