AutoIt 回圈大致上分成五類 (1) For... Next (2) While... WhileEnd (3) Do... Until (4) For... In... Next (5) With... EndWith。其中第五項 With... EndWith 必須以物件為對象,此處暫不談論,只說明前四種方式,以1+2+3...+10為例,分述如下。
1. For... Next
$Sum = 0
For $i=1 To 10
$Sum=$Sum+$i
Next
MsgBox(0, "總合", $Sum) ; Show 55
上述每次增量為 +1,其中還可以再指定每個遞增的量,假設我們只要算出 1+3+5+7+9,每次增量為 +2,改寫如下。
edisonx 發表在 痞客邦 留言(0) 人氣(3,840)
AutoIt 條件判斷式主要分成3種,If ... Then... Else、 Select ... Case、 Switch ... Case ,分敘如下所述。
1. If... Then... Else
(1) 單用一個 If - 判斷一數是否大於零
$Var = 20
If $Var > 0 Then
MsgBox(0, "標題", "變數大於0")
EndIf
edisonx 發表在 痞客邦 留言(1) 人氣(4,276)
1. 算術運算
= : assign, ex: $Var = 5
+ : 加法, ex: $Var = 10+5 ; $Var = 15
- : 減法, ex: $Var = 10 - 5; $Var = 5
* : 乘法, ex: $Var = 10 * 5 ; $Var = 50
/ : 除法, ex: $Var = 10 / 5 ; $Var = 2
^ :次方, ex: $Var = 2^3; $Var = 8
&: 字串連接, ex: $Var = "Edi" & "so" & "nX" ; $Var = "EdisonX"
edisonx 發表在 痞客邦 留言(1) 人氣(2,148)
AutoIt 稱巨集的東西,和 C/C++ 的 #define 大同小異,但通常是直接取得一個字串或一個數字,而且巨集開頭一定是 @。如 @SW_HIDE 便代表隱藏並開啟一視窗。聲明,巨集實在是太多了,要用的話請查使用手冊。主要分成四大部份之巨集,在說明前先說二個常用的文字巨集
@LF -> ASCII(10), 也就是 '\n', 用於換行
@CR -> ASCII(13), 也就是 '\r', 用於換行
@CRLF -> 這不用說了吧,就是 @CR 加上 @LF, 也就是 "\r\n"
@Tab -> Tab, ASCII(9)
edisonx 發表在 痞客邦 留言(0) 人氣(3,175)
1. 變數組成
如之前所提, AutoIt 變數都是以 $ 方式代表變數,變數必須以 $ 為開頭,且只能有數字、字數、底線所組成。
2. Local 變數
使用 Local 宣告時,變數將被視為區域變數。如
edisonx 發表在 痞客邦 留言(0) 人氣(3,391)
AutoIt 事實上沒什麼資料型態可言,這點和 C 語言差很多,基本上只有數字、字串、布林、二進位、指標這幾種而已。不過這幾種變數轉換方式非常直接,大多不需要經過什麼特別函式就可以直接轉換。
這裡要先說, autoit 的分號代表整行註解。
0. 變數(Variable)
不管什麼型態變數,所有的變數都是用 $ 開頭宣告,而且使用前可以不必事先宣告。但我較習慣事先宣告,所以宣告下來可能就變這樣:
edisonx 發表在 痞客邦 留言(3) 人氣(3,234)
最近有人推我用這套,二年前有聽過 AutoIt 軟體,直譯程式,不過沒用的原因是因為我覺得它是小朋友在玩的東西。直到最近又有人推我用它,很認真花了一小時看說明書裡面有什麼東西,發現 - 真的多到不行!!它主要是拿來寫視窗程式用的,語法非常簡單,據說很像 VB (我沒用過 VB,所以不知道到底像不像) ,其中還有一些 office 自動化的用能;讓人最驚訝的是,它竟然還可以呼叫 .DLL 、COM 元件。
後來上網到官網找,AutoIt 是用 VC6、VC7 寫的。原始碼有開放,重點是抓下來很可能看不懂而已。目前已出到 V3.3.6.1,安裝後都有說明書一步一步教,不過我查過了,目前沒有專門一本書在教 AutoIt!! 然而只看說明檔又覺得很沒有系統,有空的時候我在 blog 做個筆記好了..
edisonx 發表在 痞客邦 留言(5) 人氣(1,463)
這裡主要包出一些函式去控制 Console 視窗,大多都是一邊看 MSDN 一邊去 try。但有些結果我覺得不是很好就註解掉,同時也讓我遇到了一些問題現在還沒辦法解決。下次再研究其它功能的時候,會再發另一篇出來,主要程式碼如下所示...
原始碼
/*
filename: EConsole.h
*/
edisonx 發表在 痞客邦 留言(0) 人氣(10,781)
常用 Console Function(截自MSDN)
Function |
Description |
FillConsoleOutputCharacter |
Writes a character to the console screen buffer a specified number of times. |
GetConsoleTitle |
Retrieves the title for the current console window. |
GetConsoleWindow |
Retrieves the window handle used by the console associated with the calling process. |
GetStdHandle |
Retrieves a handle for the standard input, standard output, or standard error device. |
PeekConsoleInput |
Reads data from the specified console input buffer without removing it from the buffer. |
ReadConsole |
Reads character input from the console input buffer and removes it from the buffer. |
ReadConsoleInput |
Reads data from a console input buffer and removes it from the buffer. |
ReadConsoleOutput |
Reads character and color attribute data from a rectangular block of character cells in a console screen buffer. |
ReadConsoleOutputCharacter |
Copies a number of characters from consecutive cells of a console screen buffer. |
ScrollConsoleScreenBuffer |
Moves a block of data in a screen buffer. |
SetConsoleCursorInfo |
Sets the size and visibility of the cursor for the specified console screen buffer. |
SetConsoleCursorPosition |
Sets the cursor position in the specified console screen buffer. |
SetConsoleTitle |
Sets the title for the current console window. |
SetStdHandle |
Sets the handle for the standard input, standard output, or standard error device. |
WriteConsole |
Writes a character string to a console screen buffer beginning at the current cursor location. |
WriteConsoleInput |
Writes data directly to the console input buffer. |
WriteConsoleOutput |
Writes character and color attribute data to a specified rectangular block of character cells in a console screen buffer. |
WriteConsoleOutputAttribute |
Copies a number of foreground and background color attributes to consecutive cells of a console screen buffer. |
WriteConsoleOutputCharacter |
Copies a number of characters to consecutive cells of a console screen buffer. |
edisonx 發表在 痞客邦 留言(3) 人氣(855)
前言
看過 朋友的網誌,決定補充這二個東西。事實上 keybd_event 和 mouse_event 算是最簡單的外掛函式之一,
然而在 Win32 API 與 MFC 裡面仍使用 SendMessage, PostMessage 之方式進行,
edisonx 發表在 痞客邦 留言(0) 人氣(3,676)