AutoIt介绍

简介: AutoIt的下载网址: https://www.autoitscript.com/site/autoit/downloads/ AutoIt在线文档:http://www.

AutoIt的下载网址: https://www.autoitscript.com/site/autoit/downloads/
AutoIt在线文档:http://www.autoit3.cn/Doc/

AutoIt的优势:

  • 简单易懂的类BASIC 表达式
  • 模拟键盘,鼠标动作事件
  • 操作窗口与进程
  • 直接与窗口的”标准控件”交互(设置/获取文字,移动,关闭,等等)
  • 脚本可以编译为标准可执行文件
  • 创建用户图形界面接口(GUI)
  • COM 支持
  • 正则表达式
  • 直接调用外部DLL 和Windows API 函数
  • 程序运行为功能(让程序运行于其它账户)
  • 详细易懂的帮助文件于基于社区的支持论坛
  • 完全兼容于Windows 2000 / XP / 2003 / Vista / 2008
  • Unicode 与64位运算支持
  • 高精度,易使用的数学运算
  • 可以运行于Windows Vista Account Control (UAC)

运行AutoIt程序:

1.先打开SciTE Script Editor, 在Editor中输入以下程序:

Msgbox(0,"Autoit窗口","欢迎来到Autoit的世界")

2.编译:Tools –> Complie, 会生成.exe文件
3.双击.exe文件,就能看到运行结果



Autoit程序例子

例1: 消息框显示

Msgbox(0,"Autoit窗口","欢迎来到Autoit的世界")




例2:带交互的消息框显示

Dim $name
$name=InputBox("您好","请输入姓名:")
Msgbox(0,"欢迎",$name&",欢迎来到Autoit的世界")




例3: 变量的使用

在AU3中变量使用关键字Dim, Local 和Global 来声明并创建变量。一般变量是以美元符号$
开头的。

Dim $a, $b
$a=InputBox("运算","输入a:")
$b=InputBox("运算","输入b:")
Msgbox(0,"结果",$a&'*'&$b&'='&($a*$b))




例4 条件判断语句

Dim $age
$age=inputbox("您好","请输入年龄")
if $age < 18 then
msgbox(0,"结果","未成年人")
else
msgbox(0,"结果","年龄"& $age &",成年人")
endif




例5 循环结构 While…WEnd

Dim $sum, $i, $end
$sum = 0
$end = inputbox("输入","输入结尾数字")
$i = 1
While $i <= $end
    $sum = $sum + $i
    $i = $i +1
WEnd
MsgBox(0,"输出","1到"& $end &"的和是:"& $sum)




例6 循环结构 For…Next

Dim $sum, $i, $end
$sum = 0
$end = inputbox("输入","输入结尾数字")
For $i = 1 To $end
    $sum = $sum + $i
Next
MsgBox(0,"输出","1到"& $end &"的和是:"& $sum)



例7 九九乘法表

@CRLF 换行
@TAB 制表符
ACSII值:Chr(9)=@TAB

Dim $i, $j
Dim $s
For $i=1 To 9
    For $j=1 To $i
        $s = $s&$i&"*"&$j&"="&($i*$j)&@TAB
    Next
    $s = $s & @CRLF
Next
MsgBox(0,"九九乘法表",$s)




例8 数组的使用

Const $N=50
Dim $a[$N], $i, $s=""
For $i=0 To $N-1
    $a[$i] = $i
Next
For $i=0 To $N-1
    $s = $s&$a[$i]&"  "
Next
MsgBox(0,"数组的使用", $s)




例9 数组的显示及随机数

#include<Array.au3>
Const $N=11
Dim $i, $RandomArray[$N]
For $i=0 To $N-1
    $RandomArray[$i] = Random(1,100,1)
Next
_ArrayDisplay($RandomArray,"随机数组")



例10 函数的使用

Func <函数名>([参数1][,参数2]...[,参数n])
     [函数体]
     [Return 数据]
EndFunc

样例代码:

Func Max($x, $y)
    Local $max
    If $x >= $y Then
        $max = $x
    Else
        $max = $y
    EndIf
    Return $max
EndFunc

Local $a, $b, $c
$a = 10
$b = 20
$c = Max($a, $b)
MsgBox(0,"函数", $a&"和"&$b&"的最大值为:"&$c)



Autoit中的函数参考网址: http://kone-wu.iteye.com/blog/1910019

例11 自动化控制1:新建txt文件, 往记事本里输文字并不保存

#include <Constants.au3>

; Script Function:
;   Opens Notepad, types in some text and then quits the application.
;

; Prompt the user to run the script - use a Yes/No prompt with the flag parameter set at 4 (see the help file for more details)
Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL), "AutoIt Example", "This script will run Notepad, type in some text and then quit.  Do you want to run it?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $iAnswer = 7 Then
    MsgBox($MB_SYSTEMMODAL, "AutoIt", "OK.  Bye!")
    Exit
EndIf

; Run Notepad
Run("notepad.exe")

; Wait for the Notepad to become active. The classname "Notepad" is monitored instead of the window title
WinWaitActive("[CLASS:Notepad]")

; Now that the Notepad window is active type some text
Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")
Sleep(500)
Send("+{UP 2}")
Sleep(500)

; Now quit by pressing Alt-F and then scrolling down (simulating the down arrow being pressed six times) to the Exit menu
Send("!f")
Sleep(1000)
Send("{DOWN 6}{ENTER}")

; Now a screen will pop up and ask to save the changes, the classname of the window is called
; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
WinWaitActive("[CLASS:#32770]")
Sleep(500)
Send("{TAB}{ENTER}")

; Now wait for Notepad to close before continuing
WinWaitClose("[CLASS:Notepad]")

; Finished!

Send 函数参考网址:http://blog.csdn.net/u012248603/article/details/52706093

例12 自动化控制2: 自己新建txt文件,然后往记事本里面写入文字并保存

自己新建txt文件放在桌面, 利用AutoIt Window Info工具查到其位置(x,y)



; using AutoIt Window Info to find the location of new created txt file
MouseClick('left', 409, 234, 2)

; sleep for 2 seconds, then type some words into txt file
sleep(2000)
Send("Hello{Enter}{Space}from{Enter}{Space}Autoit{Enter}{!}{Enter}")

; Now quit by pressing Alt-F and then scrolling down (simulating the down arrow being pressed six times) to the Exit menu
Send("!f")
Sleep(1000)
Send("{DOWN 6}{ENTER}")

; Now a screen will pop up and ask to save the changes, the classname of the window is called
; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
WinWaitActive("[CLASS:#32770]")
Sleep(500)
Send("{ENTER}")

; Now wait for Notepad to close before continuing
WinWaitClose("[CLASS:Notepad]")

编译上述文件,生成first_au3.exe, 并将exe文件E盘中。这样就能通过CMD来运行exe文件了,该命令为: E://first_au3.exe.



本地分享到此结束,欢迎大家交流~

目录
相关文章
|
传感器 机器学习/深度学习 Web App开发
AI之Robot:机器人Robot的简介、发展历史、案例应用之详细攻略
AI之Robot:机器人Robot的简介、发展历史、案例应用之详细攻略
|
弹性计算 运维 负载均衡
【阿里云弹性计算】阿里云ECS在金融科技中的应用案例:高性能交易系统的构建
【5月更文挑战第27天】阿里云ECS助力某证券公司构建高性能交易系统,满足高并发、高可用和弹性扩展需求。ECS凭借最新处理器技术、高速内存实现高性能计算;支持多地域、多可用区部署保证高可用性;弹性伸缩特性适应业务波动,降低运维成本。通过分布式架构和负载均衡技术,实现交易请求高效处理,确保系统稳定运行。案例证明,阿里云ECS是金融科技领域构建高性能交易系统的理想选择。
507 1
|
机器学习/深度学习 数据采集
R语言逻辑回归、GAM、LDA、KNN、PCA主成分分类分析预测房价及交叉验证
上述介绍仅为简要概述,每个模型在实施时都需要仔细调整与优化。为了实现高度精确的预测,模型选择与调参是至关重要的步骤,并且交叉验证是提升模型稳健性的有效途径。在真实世界的房价预测问题中,可能还需要结合地域经济、市场趋势等宏观因素进行综合分析。
400 3
|
Shell 网络安全 开发工具
Git,GitHub,Gitee&IDEA集成Git
Git提交项目到GitHub简洁版、版本控制、安装、常用命令、分支、团队协作机制、Github、Gitee远程仓库、IDEA集成Git、IDEA集成Github、IDEA集成Gitee
Git,GitHub,Gitee&IDEA集成Git
|
文字识别
文本,文字识别,PaddleOCR,如何删除,PaddleOCR详解,检测,方向分类器,识别,检测的意思是检查字符的位置,查像素坐标,方向分类器,能够实现180度的图像,字符识别是把识别字符
文本,文字识别,PaddleOCR,如何删除,PaddleOCR详解,检测,方向分类器,识别,检测的意思是检查字符的位置,查像素坐标,方向分类器,能够实现180度的图像,字符识别是把识别字符
|
存储 程序员
操作系统的运行机制、中断和异常、系统调用
操作系统的运行机制、中断和异常、系统调用
422 1
|
机器学习/深度学习 数据可视化 TensorFlow
基于tensorflow深度学习的猫狗分类识别
基于tensorflow深度学习的猫狗分类识别
813 1
|
JavaScript 前端开发
完美解决 报错 Vue Invalid prop: type check failed for prop “min“. Expected Number with value 1,
完美解决 报错 Vue Invalid prop: type check failed for prop “min“. Expected Number with value 1,
891 1
|
机器学习/深度学习 JavaScript 数据挖掘
【理论+案例实战】Python数据分析之逻辑回归(logistic regression)
逻辑回归是分类当中极为常用的手段,它属于概率型非线性回归,分为二分类和多分类的回归模型。对于二分类的logistic回归,因变量y只有“是”和“否”两个取值,记为1和0。假设在自变量x1,x2,……,xp,作用下,y取“是”的概率是p,则取“否”的概率是1-p。
15319 0
|
前端开发 Shell PHP
Python(二十七)python raise语法!
Python可以使用raise手动抛出异常。 看到菜鸟教程里边对 raise 的这个定义的时候,我有点迷茫,我在极力的去避免异常出现,我为什么还要手动抛出异常呢? 1:raise 语句的基本语法格式: raise [exceptionName [(reason)]] 2:基本使用方法 (1):直接一个raise抛出异常 python 复制代码 try: i = 1 while(i < 10): raise print(i) i += 1 except: print('raise 手动抛出异常') 输出: bas
634 1

热门文章

最新文章