最近在弄V2 , 为了让V1看起来语法更规范一下, 就定义了一下函数使得样子长得像V2
(1)主要是避免使用%,
(2)还有就是命令函数化,
(3)赋值统一用 :=
例子1:
RegRead(KeyName, ValueName) { ;Value := RegRead([KeyName, ValueName, Default]) RegRead OutputVar, %KeyName%, %ValueName% return OutputVar } RegWrite(Value, ValueType, KeyName, ValueName) { RegWrite %ValueType%, %KeyName%, %ValueName%, %Value% }
例子2:像msgbox在V2中就有返回值,而且删除了IfMsgBox,那么可以这样:
Msgbox(Text, Title:="", Options:="0") { ;MsgBox([Text, Title, Options]) ;v2返回button的值 MsgBox % Options, %Title%, %Text% ;v1 Options可以为表达式,如4+48 msg := ["yes","no","ok","cancel","abort","retry","Ignore","TryAgain","Continue"] loop % msg.length() { ifmsgbox % msg[A_index] { Return % msg[A_index] } else Continue } }
最后,在V1代码中#include上面的代码即可,如:#include v1forv2.ahk