autoit3簡要筆記

<!-- /* Font Definitions */ @font-face {font-family:宋體; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋體"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋體; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {mso-style-noshow:yes; mso-style-priority:99; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} p {mso-style-noshow:yes; mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋體; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p.code, li.code, div.code {mso-style-name:code; mso-style-unhide:no; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} p.codebox, li.codebox, div.codebox {mso-style-name:codebox; mso-style-unhide:no; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} span.s4 {mso-style-name:s4; mso-style-unhide:no;} span.s8 {mso-style-name:s8; mso-style-unhide:no;} span.s7 {mso-style-name:s7; mso-style-unhide:no;} span.s0 {mso-style-name:s0; mso-style-unhide:no;} span.s9 {mso-style-name:s9; mso-style-unhide:no;} p.codeheader, li.codeheader, div.codeheader {mso-style-name:codeheader; mso-style-unhide:no; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page WordSection1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.WordSection1 {page:WordSection1;} /* List Definitions */ @list l0 {mso-list-id:1532570669; mso-list-type:hybrid; mso-list-template-ids:-420083948 -2124751396 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:none; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

1.autoit3 腳本參數

$CmdLine[0] is number of parameters
$CmdLine[1] is param 1 (after the script name)
$CmdLine[2] is param 2 etc
...
$CmdLine[$CmdLine[0]] is one way to get the last parameter...

 

So if your script is run like this:

    AutoIt3.exe myscript.au3 param1 "this is another param"

$CmdLine[0] equals... 2

$CmdLine[1] equals... param1

$CmdLine[2] equals... this is another param

@ScriptName equals... myscript.au3

2.vistaUser Account Control (UAC) .

Vista 下,提示用戶腳本運行的用戶是否有administrators 的權限。

; This script requires full Administrative rights
#requireadmin

MsgBox(0, "Info", "This script has admin rights! ")

 

3 windows handles

A window handle is a special value that windows assigns to a window each time it is created.The advantage of using window handles is that if you have multiple copies of an application open - which have the same title/text - you can uniquely identify them when using handles.

 

 

4 autoit 快捷鍵

!代表alt

5

Autoit 中的宏是用@ 開頭的,變量是以$ 開頭的。

6 循環

除了for in next vbscript 中的for each next 不同外。其餘幾個語法一直。

7 com 的調用

使用oleviewer 查看當前機器上的com 組件。Most important is the " VersionIndependentProgID ". This is the name to be used in an ObjCreate, ObjGet or ObjEvent functionAutoIt uses the  IDispatch interface for automationRight-click on the name IDispatch and choose " View... " from the context menu. Then click the " View TypeInfo... " button

8.autoit3 GUI

GUI 上的 control id

  The control ID is a positive number (that is, a number greater than 0)

  Each control ID is unique - even when there are multiple windows

  The control ID is actually the same value as the Control ID that the AutoIt Window Info Tool shows

GUI 具有兩種模式, 1. 消息驅動模式 2. 事件驅動模式

1.       消息驅動模式

GUI 將不停的循環,使用 GUIGetMsg() 來獲取 GUI 上的事件,例如點擊 Button, 關閉 GUI

While 1
  $msg = GUIGetMsg()
  ...
  ...
WEnd

Remark: 注意,不要在 GUI 中嘗試添加 Sleep 函數,這會導致 GUI 無法響應用戶,不用擔心 LOOP 會過分消耗 CPU GUIGetMsg 已經幫你考慮到這點了。

GUIGetMsg() 將返回三種結果:

·   No Event   返回爲 0

·   Control Event   返回 CONTROL ID

  System Event   返回負值

$GUI_EVENT_CLOSE
$GUI_EVENT_MINIMIZE
$GUI_EVENT_RESTORE
$GUI_EVENT_MAXIMIZE
$GUI_EVENT_PRIMARYDOWN
$GUI_EVENT_PRIMARYUP
$GUI_EVENT_SECONDARYDOWN
$GUI_EVENT_SECONDARYUP
$GUI_EVENT_MOUSEMOVE
$GUI_EVENT_RESIZED
$GUI_EVENT_DROPPED

Control id 是獨一無二的,但System Event 在多窗口的情況下就需要再指明是哪個窗口的事件了。因此使用帶參數的GUIGetMsg 方法。

$msg = GUIGetMsg(1) 

When called with the 1 parameter instead of returning an event value an array will be returned, the array contains the event ( in $array[0] ) and extra information such as the window handle ( in $array[1] )

The first major change is the GUISwitch function call - when a new window is created it becomes the "default" window for future GUI operations (including control creation). 

使用 GUISwitch($mainwindow) 來切換活動窗口。

 

2. 事件驅動模式

The default mode is the MessageLoop mode so before using the OnEvent mode we must use Opt("GUIOnEventMode", 1) .

 

9autoit3 函數

9 1 環境管理

clipGet  獲取剪切板中內容

Clipput  設置剪切板中內容

EnvGet  獲取環境變量   $var = EnvGet ( "PATH" )

EnvSet  設置環境變量 EnvSet ( "MYENV" , "this is a test" )

MemGetStats ( ) 獲取內存狀態。 返回七個元素的數組。

9.2 文件 ,目錄,磁盤管理

  Autoit3 有類似 vbs 的文件目錄磁盤函數,另外, autoit3 能夠對 .ini 文件直接讀寫。便於操作這種鍵值對應的文件。

 

10 autoit3 網絡編程

10.1 網絡下載文件

; Advanced example - downloading in the background
Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "/update.dat", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload)   ; Close the handle to release resourcs.
MsgBox(0, "", "Bytes read: " & $nBytes)

10.2 socket 編程

Step1: TCPStartup ( )

Step2: TCPListen ( IPAddr, port [, MaxPendingConnection] )

Step3: 服務器端 TCPAccept ( mainsocket ) ,客戶端 TCPConnect ( IPAddr, port )

Step4: 客戶端 TCPSend ( mainsocket, data )

服務端 TCPRecv ( mainsocket, maxlen [, flag] )

Step5: TCPCloseSocket ( socket ) 關閉 TCPListen TCPAccept 建立的 socket 連接。

Step6: TCPShutdown ( ) ; To stop TCP services

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章