當(dāng)前位置:首頁 > IT技術(shù) > 移動平臺 > 正文

Selenium如何支持測試Windows application
2021-08-07 17:11:18

很長一段時間大家都支持Selenium是只支持測試Web應(yīng)用程序的。

縱觀Selenium的成長歷程,不難解釋這個原因。Selenium開始的時候是作為一個Firefox中的插件出現(xiàn)的,而且做得是純JS腳本的方式,目的就是一個老外測試的有點煩了,就寫了一個js的腳本每天去run自己的測試項目。從這個點來看,老外真的很有才。。想想國內(nèi)的同行有誰會想到做得有點煩了,去自己搞騰一個工具去做每天的工作。。。

后面Selenium做得挺不錯的,老外也感覺自己樂不如大家同樂。。。于是就開源了Selenium,后面進一步的壯大了,反而讓Selenium開花結(jié)果,產(chǎn)生了一個真正意義上的自動化的支持。先是java版本的,然后是其他語言版本的,像Ruby ,c#,python等等。。。感覺好強大啊。

而且Selenium就是針對QTP來干的。。。SeleniumHq,就是對著HP干的。。??闯鰜砹藛??

可能慢慢的你還發(fā)現(xiàn)Selenium做點web的測試還是可以的,可能針對Windows的程序如何用它去測試呢?

還是強大的網(wǎng)友給出了答案。讓Selenium支持Windows程序無縫連接。。。這里就是推薦使用AutoIt這個工具,關(guān)于如何使用你需要到網(wǎng)上搜索看看了。http://www.autoitscript.com/site/autoit/

下面是可以用的的AutoIt的API 函數(shù)。

Selenium如何支持測試Windows application_sedSelenium如何支持測試Windows application_ide_02
   1 /**
   2  * Copyright (c) 2011 Richard Kanavati
   3  *
   4  * Permission is hereby granted, free of charge, to any person obtaining a copy
   5  * of this software and associated documentation files (the "Software"), to deal
   6  * in the Software without restriction, including without limitation the rights
   7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   8  * copies of the Software, and to permit persons to whom the Software is
   9  * furnished to do so, subject to the following conditions:
  10  *
  11  * The above copyright notice and this permission notice shall be included in
  12  * all copies or substantial portions of the Software.
  13  *
  14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20  * THE SOFTWARE.
  21  */
  22 package com.hp.utility;
  23 
  24 import com.jacob.activeX.ActiveXComponent;
  25 import com.jacob.com.SafeArray;
  26 import com.jacob.com.Variant;
  27 
  28 /**
  29  * A Java AutoItX3 Bridge.
  30  * @author Richard Kanavati
  31  * this core function is wrapped ,so you should not modify this file anyway
  32  */
  33 public class AutoItXUtils {
  34 
  35     /**
  36      * The AutoItX Component.
  37      */
  38     protected ActiveXComponent autoItX;
  39     /**
  40      * Maximizes the specified window.
  41      */
  42     public final static int SW_MAXIMIZE = 3;
  43     /**
  44      * Minimizes the specified window and activates the next top-level window in the Z order.
  45      */
  46     public final static int SW_HIDE = 0;
  47     /**
  48      * Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
  49      */
  50     public final static int SW_RESTORE = 9;
  51     /**
  52      * Activates the window and displays it in its current size and position.
  53      */
  54     public final static int SW_SHOW = 5;
  55     /**
  56      * Sets the show state based on the SW_ value specified by the program that started the application.
  57      */
  58     public final static int SW_SHOWDEFAULT = 10;
  59     /**
  60      * Activates the window and displays it as a maximized window.
  61      */
  62     public final static int SW_SHOWMAXIMIZED = 3;
  63     /**
  64      * Activates the window and displays it as a minimized window.
  65      */
  66     public final static int SW_SHOWMINIMIZED = 2;
  67     /**
  68      * Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
  69      */
  70     public final static int SW_SHOWMINNOACTIVE = 7;
  71     /**
  72      * Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated.
  73      */
  74     public final static int SW_SHOWNA = 8;
  75     /**
  76      * Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived.
  77      */
  78     public final static int SW_SHOWNOACTIVATE = 4;
  79     /**
  80      * Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
  81      */
  82     public final static int SW_SHOWNORMAL = 1;
  83     /**
  84      * Sets the way coords are used in the caret functions, either absolute coords or coords relative to the current active window:
  85      * <br/>0 = relative coords to the active window,
  86      * <br/>1 = absolute screen coordinates (default),
  87      * <br/>2 = relative coords to the client area of the active window.
  88      */
  89     public final static String OPT_CARET_COORD_MODE = "CaretCoordMode";
  90     /**
  91      * Alters the length of the brief pause in between mouse clicks.
  92      * Time in milliseconds to pause (default=10).
  93      */
  94     public final static String OPT_MOUSE_CLICK_DELAY = "MouseClickDelay";
  95     /**
  96      * Alters the length of the brief pause in between mouse clicks.
  97      * Time in milliseconds to pause (default=10).
  98      */
  99     public final static String OPT_MOUSE_CLICK_DOWN_DELAY = "MouseClickDownDelay";
 100     /**
 101      * Alters the length of the brief pause at the start and end of a mouse drag operation.
 102      * Time in milliseconds to pause (default=250).
 103      */
 104     public final static String OPT_MOUSE_CLICK_DRAG_DELAY = "MouseClickDragDelay";
 105     /**
 106      * Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:
 107      * <br/>0 = relative coords to the active window
 108      * <br/>1 = absolute screen coordinates (default)
 109      * <br/>2 = relative coords to the client area of the active window
 110      */
 111     public final static String OPT_MOUSE_COORD_MODE = "MouseCoordMode";
 112     /**
 113      * Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:
 114      * <br/>0 = relative coords to the active window
 115      * <br/>1 = absolute screen coordinates (default)
 116      * <br/>2 = relative coords to the client area of the active window
 117      */
 118     public final static String OPT_PIXEL_COORD_MODE = "PixelCoordMode";
 119     /**
 120      * Sets the way coords are used in the pixel functions, either absolute coords or coords relative to the current active window:
 121      * <br/>0 = relative coords to the active window
 122      * <br/>1 = absolute screen coordinates (default)
 123      * <br/>2 = relative coords to the client area of the active window
 124      */
 125     public final static String OPT_SEND_ATTACH_MODE = "SendAttachMode";
 126     /**
 127      * Specifies if AutoIt attaches input threads when using then Send() function. When not attaching (default mode=0) detecting the state of capslock/scrolllock and numlock can be unreliable under NT4. However, when you specify attach mode=1 the Send("{... down/up}") syntax will not work and there may be problems with sending keys to "hung" windows. ControlSend() ALWAYS attaches and is not affected by this mode.
 128      * <br/>0 = don't attach (default)
 129      * <br/>1 = attach
 130      */
 131     public final static String OPT_SEND_CAPSLOCK_MODE = "SendCapslockMode";
 132     /**
 133      * Specifies if AutoIt should store the state of capslock before a Send function and restore it afterwards.
 134      * <br/>0 = don't store/restore
 135      * <br/>1 = store and restore (default)
 136      */
 137     public final static String OPT_SEND_KEY_DELAY = "SendKeyDelay";
 138     /**
 139      * Alters the length of time a key is held down before released during a keystroke. For applications that take a while to register keypresses (and many games) you may need to raise this value from the default.
 140      * Time in milliseconds to pause (default=1).
 141      */
 142     public final static String OPT_SEND_KEY_DOWN_DELAY = "SendKeyDownDelay";
 143     /**
 144      * Specifies if hidden window text can be "seen" by the window matching functions.
 145      * <br/>0 = Do not detect hidden text (default)
 146      * <br/>1 = Detect hidden text
 147      */
 148     public final static String OPT_WIN_DETECT_HIDDEN_TEXT = "WinDetectHiddenText";
 149     /**
 150      * Allows the window search routines to search child windows as well as top-level windows.
 151      * <br/>0 = Only search top-level windows (default)
 152      * <br/>1 = Search top-level and child windows
 153      */
 154     public final static String OPT_WIN_SEARCH_CHILDREN = "WinSearchChildren";
 155     /**
 156      * Alters the method that is used to match window text during search operations.
 157      * <br/>1 = Complete / Slow mode (default)
 158      * <br/>2 = Quick mode
 159      * In quick mode AutoIt can usually only "see" dialog text, button text and the captions of some controls. In the default mode much more text can be seen (for instance the contents of the Notepad window).
 160      * If you are having performance problems when performing many window searches then changing to the "quick" mode may help.
 161      */
 162     public final static String OPT_WIN_TEXT_MATCH_MODE = "WinTextMatchMode";
 163     /**
 164      * Alters the method that is used to match window titles during search operations.
 165      * <br/>1 = Match the title from the start (default)
 166      * <br/>2 = Match any substring in the title
 167      * <br/>3 = Exact title match
 168      * <br/>4 = Advanced mode, see Window Titles & Text (Advanced)
 169      */
 170     public final static String OPT_WIN_TITLE_MATCH_MODE = "WinTitleMatchMode";
 171     /**
 172      * Alters how long a script should briefly pause after a successful window-related operation.
 173      * Time in milliseconds to pause (default=250).
 174      */
 175     public final static String OPT_WIN_WAIT_DELAY = "WinWaitDelay";
 176    
 177 
 178     /**
 179      * Initializes the AutoItX Jacob COM object.
 180      */
 181     public AutoItXUtils() {
 182         autoItX = new ActiveXComponent("AutoItX3.Control");
 183     }
 184 
 185     
 186     /**
 187      * The AutoItX version.
 188      * @return The AutoItX version.
 189      */
 190     public String getVersion() {
 191         return autoItX.getProperty("version").getString();
 192     }
 193 
 194     /**
 195      * Value of the error flag.
 196      * @return The value of the error flag.
 197      */
 198     public int getError() {
 199         Variant error = autoItX.invoke("error");
 200         return error.getInt();
 201     }
 202 
 203     /**
 204      * Retrieves text from the clipboard.
 205      * @return A string containing the text on the clipboard. Sets error to 1 if clipboard is empty or contains a non-text entry.
 206      */
 207     public String clipGet() {
 208        return autoItX.invoke("ClipGet").getString();
 209     }
 210 
 211     /**
 212      * Writes text to the clipboard.
 213      * @param value The text to write to the clipboard.
 214      */
 215     public void clipPut(String value) {
 216         autoItX.invoke("ClipPut", new Variant(value));
 217     }
 218 
 219     /**
 220      * Maps a network drive.
 221      * <p><b>Doesn't always work</b></p>
 222      * @param device The device to map, for example "O:" or "LPT1:". If you pass a blank string for this parameter a connection is made but not mapped to a specific drive. If you specify "*" an unused drive letter will be automatically selected.
 223      * @param remote The remote share to connect to in the form "\servershare".
 224      * @return True if success, false otherwise
 225      */
 226     public boolean driveMapAdd(String device, String remote) {
 227         return driveMapAdd(device, remote, 0, "", "");
 228     }
 229 
 230     /**
 231      * Maps a network drive.     
 232      * @param device The device to map, for example "O:" or "LPT1:". If you pass a blank string for this parameter a connection is made but not mapped to a specific drive. If you specify "*" an unused drive letter will be automatically selected.
 233      * @param remote The remote share to connect to in the form "\servershare".
 234      * @param flags A combination of the following:0 = default, 1 = Persistent mapping, 8 = Show authentication dialog if required
 235      * @param username The username
 236      * @param password The password
 237      * @return True if success, false otherwise
 238      */
 239     public boolean driveMapAdd(String device, String remote, int flags, String username, String password) {
 240         Variant vDevice = new Variant(device);
 241         Variant vRemote = new Variant(remote);
 242         Variant vFlags = new Variant(flags);
 243         Variant vUsername = new Variant(username);
 244         Variant vPassword = new Variant(password);
 245         Variant[] params = new Variant[]{vDevice, vRemote, vFlags, vUsername, vPassword};
 246         Variant result = autoItX.invoke("DriveMapAdd", params);
 247         if (result.getvt() == Variant.VariantString) {
 248             return oneToTrue(Integer.parseInt(result.getString()));
 249         }
 250         return oneToTrue(result.getInt());
 251     }
 252 
 253     /**
 254      * Maps a network drive.
 255      * @param device The device to map, for example "O:" or "LPT1:". If you pass a blank string for this parameter a connection is made but not mapped to a specific drive. If you specify "*" an unused drive letter will be automatically selected.
 256      * @param remote The remote share to connect to in the form "\servershare".
 257      * @param flags A combination of the following:0 = default, 1 = Persistent mapping, 8 = Show authentication dialog if required
 258      * @return True if success, false otherwise
 259      */
 260     public boolean driveMapAdd(String device, String remote, int flags) {
 261         Variant vDevice = new Variant(device);
 262         Variant vRemote = new Variant(remote);
 263         Variant vFlags = new Variant(flags);
 264         Variant[] params = new Variant[]{vDevice, vRemote, vFlags};
 265         Variant result = autoItX.invoke("DriveMapAdd", params);
 266         if (result.getvt() == Variant.VariantString) {
 267             return oneToTrue(Integer.parseInt(result.getString()));
 268         }
 269         return oneToTrue(result.getInt());
 270     }
 271 
 272     /**
 273      * Disconnects a network drive.
 274      * @param device The device to disconnect, e.g. "O:" or "LPT1:".
 275      * @return True if success, false otherwise
 276      */
 277     public boolean driveMapDelete(String device) {
 278         Variant result = autoItX.invoke("DriveMapDel", device);
 279         return oneToTrue(result);
 280     }
 281 
 282     /**
 283      * The device (drive or printer) letter to query. Eg. "O:" or "LPT1:"
 284      * @param device The device to disconnect, e.g. "O:" or "LPT1:".
 285      * @return Details of the mapping, e.g. \servershare. If blank, sets .error() to 1.
 286      */
 287     public String driveMapGet(String device) {
 288         Variant result = autoItX.invoke("DriveMapGet", device);
 289         return result.getString();
 290     }
 291 
 292     /**
 293      * Deletes a value from a standard format .ini file.
 294      * @param filename The filename of the .ini file.
 295      * @param section The section name in the .ini file.
 296      * @param key The key name in the in the .ini file. If no key name is given the entire section is deleted.
 297      * @return True if success, false otherwise
 298      */
 299     public boolean iniDelete(String filename, String section, String key) {
 300         Variant vFilename = new Variant(filename);
 301         Variant vSection = new Variant(section);
 302         Variant vKey = new Variant(key);
 303         Variant[] params = new Variant[]{vFilename, vSection, vKey};
 304         Variant result = autoItX.invoke("IniDelete", params);
 305         return oneToTrue(result);
 306     }
 307 
 308     /**
 309      * Deletes a value from a standard format .ini file.
 310      * @param filename The filename of the .ini file.
 311      * @param section The section name in the .ini file.
 312      * @return True if success, false otherwise
 313      */
 314     public boolean iniDelete(String filename, String section) {
 315         return iniDelete(filename, section, "");
 316     }
 317 
 318     /**
 319      * Reads a value from a standard format .ini file.
 320      * @param filename The filename of the .ini file.
 321      * @param section The section name in the .ini file.
 322      * @param key The key name in the in the .ini file.
 323      * @param defaultVal The default value to return if the requested key is not found.
 324      * @return The requested key value if found, otherwise the default value.
 325      */
 326     public String iniRead(String filename, String section, String key, String defaultVal) {
 327         Variant vFilename = new Variant(filename);
 328         Variant vSection = new Variant(section);
 329         Variant vKey = new Variant(key);
 330         Variant vDefault = new Variant(defaultVal);
 331         Variant[] params = new Variant[]{vFilename, vSection, vKey, vDefault};
 332         Variant result = autoItX.invoke("IniRead", params);
 333         return result.getString();
 334     }
 335 
 336     /**
 337      * Writes a value to a standard format .ini file.
 338      * @param filename The filename of the .ini file.
 339      * @param section The section name in the .ini file.
 340      * @param key The key name in the in the .ini file.
 341      * @param value The value to write/change.
 342      * @return True if success, false otherwise.
 343      */
 344     public Boolean iniWrite(String filename, String section, String key, String value) {
 345         Variant vFilename = new Variant(filename);
 346         Variant vSection = new Variant(section);
 347         Variant vKey = new Variant(key);
 348         Variant vValue = new Variant(value);
 349         Variant[] params = new Variant[]{vFilename, vSection, vKey, vValue};
 350         Variant result = autoItX.invoke("IniWrite", params);
 351         return oneToTrue(result);
 352     }
 353 
 354     /**
 355      * Generates a checksum for a region of pixels.
 356      * @param left Left coordinate of rectangle.
 357      * @param top Top coordinate of rectangle.
 358      * @param right Right coordinate of rectangle.
 359      * @param bottom Bottom coordinate of rectangle.
 360      * @param step Instead of checksumming each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1.
 361      * @return The checksum value of the region.
 362      */
 363     public double pixelChecksum(int left, int top, int right, int bottom, int step) {
 364         Variant vLeft = new Variant(left);
 365         Variant vTop = new Variant(top);
 366         Variant vRight = new Variant(right);
 367         Variant vBottom = new Variant(bottom);
 368         Variant vStep = new Variant(step);
 369         Variant[] params = new Variant[]{vLeft, vTop, vRight, vBottom, vStep};
 370         Variant result = autoItX.invoke("PixelChecksum", params);
 371         return result.getDouble();
 372     }
 373 
 374     /**
 375      * Generates a checksum for a region of pixels.
 376      * @param left Left coordinate of rectangle.
 377      * @param top Top coordinate of rectangle.
 378      * @param right Right coordinate of rectangle.
 379      * @param bottom Bottom coordinate of rectangle.
 380      * @return The checksum value of the region.
 381      */
 382     public double pixelChecksum(int left, int top, int right, int bottom) {
 383         return pixelChecksum(left, top, right, bottom, 0);
 384     }
 385 
 386     /**
 387      * Returns a pixel color according to x,y pixel coordinates.
 388      * @param x x coordinate of pixel.
 389      * @param y y coordinate of pixel.
 390      * @return Decimal value of pixel's color.
 391      */
 392     public float pixelGetColor(int x, int y) {
 393         Variant vX = new Variant(x);
 394         Variant vY = new Variant(y);
 395         Variant[] params = new Variant[]{vX, vY};
 396         Variant result = autoItX.invoke("PixelGetColor", params);
 397         return result.getInt();
 398     }
 399 
 400     /**
 401      * Searches a rectangle of pixels for the pixel color provided.
 402      * @param left left coordinate of rectangle.
 403      * @param top top coordinate of rectangle.
 404      * @param right right coordinate of rectangle.
 405      * @param bottom bottom coordinate of rectangle.
 406      * @param color Color value of pixel to find (in decimal or hex).
 407      * @param shadeVariation A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the colour. Default is 0 (exact match).
 408      * @param step Instead of searching each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1.
 409      * @return The pixel's coordinates in a 2 element array, otherwise sets .error() to one.
 410      */
 411     public long[] pixelSearch(int left, int top, int right, int bottom, int color, int shadeVariation, int step) {
 412         Variant vLeft = new Variant(left);
 413         Variant vTop = new Variant(top);
 414         Variant vRight = new Variant(right);
 415         Variant vBottom = new Variant(bottom);
 416         Variant vColor = new Variant(color);
 417         Variant vShadeVariation = new Variant(shadeVariation);
 418         Variant vStep = new Variant(step);
 419         Variant[] params = new Variant[]{vLeft, vTop, vRight, vBottom, vColor, vShadeVariation, vStep};
 420         Variant result = autoItX.invoke("PixelSearch", params);
 421         long[] l = new long[2];
 422 
 423         if (result.getvt() == 8204) {
 424             l[0] = result.toSafeArray().getLong(0);
 425             l[1] = result.toSafeArray().getLong(1);
 426             return l;
 427         }
 428         return l;
 429     }
 430 
 431     /**
 432      * Searches a rectangle of pixels for the pixel color provided.
 433      * @param left left coordinate of rectangle.
 434      * @param top top coordinate of rectangle.
 435      * @param right right coordinate of rectangle.
 436      * @param bottom bottom coordinate of rectangle.
 437      * @param color Color value of pixel to find (in decimal or hex).
 438      * @return The pixel's coordinates in a 2 element array, otherwise sets .error() to one.
 439      */
 440     public long[] pixelSearch(int left, int top, int right, int bottom, int color) {
 441         return pixelSearch(left, top, right, bottom, color, 0, 1);
 442     }
 443 
 444     /**
 445      * Sends simulated keystrokes to the active window.
 446      * @param keys The sequence of keys to send.
 447      * @param isRaw Changes how "keys" is processed:   true -  Text contains special characters like + and ! to indicate SHIFT and ALT key presses.  false, keys are sent raw.
 448      */
 449     public void send(String keys, boolean isRaw) {
 450         Variant vKeys = new Variant(keys);
 451         Variant vFlag = new Variant(isRaw ? 1 : 0);
 452         Variant[] params = new Variant[]{vKeys, vFlag};
 453         autoItX.invoke("Send", params);
 454     }
 455 
 456     /**
 457      * Sends simulated keystrokes to the active window.
 458      * @param keys The sequence of keys to send.
 459      */
 460     public void send(String keys) {
 461         send(keys, true);
 462     }
 463 
 464     /**
 465      * Creates a tooltip anywhere on the screen.
 466      * @param text The text of the tooltip. (An empty string clears a displaying tooltip)
 467      * @param x The x,y position of the tooltip.
 468      * @param y The x,y position of the tooltip.
 469      */
 470     public void toolTip(String text, int x, int y) {
 471         Variant vText = new Variant(text);
 472         Variant vX = new Variant(x);
 473         Variant vY = new Variant(y);
 474         Variant[] params = new Variant[]{vText, vX, vY};
 475         autoItX.invoke("ToolTip", params);
 476     }
 477 
 478     /**
 479      *  Creates a tooltip anywhere on the screen.
 480      * @param text The text of the tooltip. (An empty string clears a displaying tooltip)
 481      */
 482     public void toolTip(String text) {
 483         autoItX.invoke("ToolTip", text);
 484     }
 485 
 486     /**
 487      * Disable/enable the mouse and keyboard.
 488      * Requires admin rights in Vista and Windows 7.
 489      * @param disableInput True = disable user input, false = re-enable it.
 490      */
 491     public void blockInput(boolean disableInput) {
 492         autoItX.invoke("BlockInput", (disableInput ? 1 : 0));
 493     }
 494 
 495     /**
 496      * Opens or closes the CD tray.
 497      * @param drive The drive letter of the CD tray to control, in the format D:, E:, etc.
 498      * @param status Specifies if you want the CD tray to be open or closed: "open" or "closed"
 499      * @return True if success, false if drive is locked via CD burning software or if the drive letter is not a CD drive.
 500      */
 501     public boolean cdTray(String drive, String status) {
 502         Variant vDrive = new Variant(drive);
 503         Variant vStatus = new Variant(status);
 504         Variant[] params = new Variant[]{vDrive, vStatus};
 505         Variant result = autoItX.invoke("CDTray", params);
 506         return oneToTrue(result);
 507     }
 508 
 509     /**
 510      * Checks if the current user has administrator privileges.
 511      * @return True if is admin, false otherwise.
 512      */
 513     public boolean isAdmin() {
 514         return oneToTrue(autoItX.invoke("IsAdmin"));
 515     }
 516 
 517     /**
 518      * Changes the operation of various AutoIt functions/parameters.
 519      * @param option The option to change.
 520      * @param param The parameter (varies by option).
 521      * @return Value of the previous setting.
 522      */
 523     public String autoItSetOption(String option, String param) {
 524         Variant vOption = new Variant(option);
 525         Variant vParam = new Variant(param);
 526         Variant[] params = new Variant[]{vOption, vParam};
 527         Variant result = autoItX.invoke("AutoItSetOption", params);
 528         if (result.getvt() == Variant.VariantInt) {
 529             int i = result.getInt();
 530             return String.valueOf(i);
 531         }
 532         return result.getString();
 533     }
 534 
 535     /**
 536      * Changes the operation of various AutoIt functions/parameters.
 537      * @param option The option to change.
 538      * @param param The parameter (varies by option).
 539      * @return Value of the previous setting.
 540      */
 541     public String setOption(String option, String param) {
 542         return autoItSetOption(option, param);
 543     }
 544 
 545     /**
 546      * Perform a mouse click operation.
 547      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 548      * @param x The x/y coordinates to move the mouse to. If no x and y coords are given, the current position is used.
 549      * @param y The x/y coordinates to move the mouse to. If no x and y coords are given, the current position is used.
 550      * @param clicks The number of times to click the mouse. Default is 1.
 551      * @param speed The speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.
 552      */
 553     public void mouseClick(String button, int x, int y, int clicks, int speed) {
 554         Variant vButton = new Variant(button);
 555         Variant vX = new Variant(x);
 556         Variant vY = new Variant(y);
 557         Variant vClicks = new Variant(clicks);
 558         Variant vSpeed = new Variant(speed);
 559         Variant[] params = new Variant[]{vButton, vX, vY, vClicks, vSpeed};
 560         autoItX.invoke("MouseClick", params);
 561 
 562     }
 563 
 564     /**
 565      * Perform a mouse click operation.
 566      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 567      * @param clicks The number of times to click the mouse. Default is 1.
 568      * @param speed The speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.
 569      */
 570     public void mouseClick(String button, int clicks, int speed) {
 571         Variant vButton = new Variant(button);
 572         Variant vClicks = new Variant(clicks);
 573         Variant vSpeed = new Variant(speed);
 574         Variant[] params = new Variant[]{vButton, vClicks, vSpeed};
 575         autoItX.invoke("MouseClick", params);
 576     }
 577 
 578     /**
 579      * Perform a mouse click and drag operation.
 580      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 581      * @param x The x/y coords to start the drag operation from.
 582      * @param y The x/y coords to start the drag operation from.
 583      * @param x2 The x/y coords to start the drag operation to.
 584      * @param y2 The x/y coords to start the drag operation to.
 585      * @param speed The speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.
 586      */
 587     public void mouseClickDrag(String button, int x, int y, int x2, int y2, int speed) {
 588         Variant vButton = new Variant(button);
 589         Variant vX = new Variant(x);
 590         Variant vY = new Variant(y);
 591         Variant vX2 = new Variant(x2);
 592         Variant vY2 = new Variant(y2);
 593         Variant vSpeed = new Variant(speed);
 594         Variant[] params = new Variant[]{vButton, vX, vY, vX2, vY2, vSpeed};
 595         autoItX.invoke("MouseClickDrag", params);
 596     }
 597 
 598     /**
 599      * Perform a mouse click and drag operation.
 600      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 601      * @param x The x/y coords to start the drag operation from.
 602      * @param y The x/y coords to start the drag operation from.
 603      * @param x2 The x/y coords to start the drag operation to.
 604      * @param y2 The x/y coords to start the drag operation to.
 605      */
 606     public void mouseClickDrag(String button, int x, int y, int x2, int y2) {
 607         mouseClickDrag(button, x, y, x2, y2, 10);
 608     }
 609 
 610     /**
 611      * Perform a mouse down event at the current mouse position.
 612      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 613      */
 614     public void mouseDown(String button) {
 615         autoItX.invoke("MouseDown", button);
 616     }
 617 
 618     /**
 619      * Returns a cursor ID Number of the current Mouse Cursor.
 620      * @return  0 = UNKNOWN (this includes pointing and grabbing hand icons)
 621      * <br/> 1 = APPSTARTING
 622      * <br/> 2 = ARROW
 623      * <br/> 3 = CROSS
 624      * <br/> 4 = HELP
 625      * <br/> 5 = IBEAM
 626      * <br/> 6 = ICON
 627      * <br/> 7 = NO
 628      * <br/> 8 = SIZE
 629      * <br/> 9 = SIZEALL
 630      * <br/> 10 = SIZENESW
 631      * <br/> 11 = SIZENS
 632      * <br/> 12 = SIZENWSE
 633      * <br/> 13 = SIZEWE
 634      * <br/> 14 = UPARROW
 635      * <br/> 15 = WAIT
 636      */
 637     public int mouseGetCursor() {
 638         return autoItX.invoke("MouseGetCursor").getInt();
 639     }
 640 
 641     /**
 642      * Retrieves the current X position of the mouse cursor.
 643      * @return The current X position of the mouse cursor.
 644      */
 645     public int mouseGetPosX() {
 646         return autoItX.invoke("MouseGetPosX").getInt();
 647     }
 648 
 649     /**
 650      * Retrieves the current Y position of the mouse cursor.
 651      * @return The current Y position of the mouse cursor.
 652      */
 653     public int mouseGetPosY() {
 654         return autoItX.invoke("MouseGetPosY").getInt();
 655     }
 656 
 657     /**
 658      * Moves the mouse pointer.
 659      * @param x The screen x coordinate to move the mouse to.
 660      * @param y The screen y coordinate to move the mouse to.
 661      * @param speed The speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.
 662      * @return true if success, false otherwise (is this correct)?
 663      */
 664     public boolean mouseMove(int x, int y, int speed) {
 665         Variant vX = new Variant(x);
 666         Variant vY = new Variant(y);
 667         Variant vSpeed = new Variant(speed);
 668         Variant[] params = new Variant[]{vX, vY, vSpeed};
 669         return oneToTrue(autoItX.invoke("MouseMove", params).getInt());
 670     }
 671 
 672     /**
 673      * Moves the mouse pointer.
 674      * @param x The screen x coordinate to move the mouse to.
 675      * @param y The screen y coordinate to move the mouse to.
 676      * @return true if success, false otherwise (is this correct)?
 677      */
 678     public boolean mouseMove(int x, int y) {
 679         return mouseMove(x, y, 10);
 680     }
 681 
 682     /**
 683      * Perform a mouse up event at the current mouse position.
 684      * @param button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
 685      */
 686     public void mouseUp(String button) {
 687         autoItX.invoke("MouseUp", button);
 688     }
 689 
 690     /**
 691      * Moves the mouse wheel up or down. NT/2000/XP ONLY.
 692      * @param direction "up" or "down"
 693      * @param clicks The number of times to move the wheel. Default is 1.
 694      */
 695     public void mouseWheel(String direction, int clicks) {
 696         Variant vDirection = new Variant(direction);
 697         Variant vClicks = new Variant(clicks);
 698         Variant[] params = new Variant[]{vDirection, vClicks};
 699         autoItX.invoke("MouseWheel", params);
 700     }
 701 
 702     /**
 703      * Moves the mouse wheel up or down. NT/2000/XP ONLY.
 704      * @param direction "up" or "down"
 705      */
 706     public void mouseWheel(String direction) {
 707         mouseWheel(direction, 1);
 708     }
 709 
 710     /**
 711      * Terminates a named process.
 712      * @param process The title or PID of the process to terminate.
 713      */
 714     public void processClose(String process) {
 715         autoItX.invoke("ProcessClose", process);
 716     }
 717 
 718     /**
 719      * Checks to see if a specified process exists.
 720      * @param process The name or PID of the process to check.
 721      * @return The PID of the process. 0 if process does not exist.
 722      */
 723     public int processExists(String process) {
 724         return autoItX.invoke("ProcessExists", process).getInt();
 725     }
 726 
 727     /**
 728      * Changes the priority of a process
 729      * @param process The name or PID of the process to check.
 730      * @param priority A flag which determines what priority to set
 731      * <br/>    0 - Idle/Low
 732      * <br/>    1 - Below Normal (Not supported on Windows 95/98/ME)
 733      * <br/>    2 - Normal
 734      * <br/>    3 - Above Normal (Not supported on Windows 95/98/ME)
 735      * <br/>    4 - High
 736      * <br/>    5 - Realtime (Use with caution, may make the system unstable)
 737      * @return True if success, false otherwise.
 738      */
 739     public boolean processSetPriority(String process, int priority) {
 740         Variant vProcess = new Variant(process);
 741         Variant vPriority = new Variant(priority);
 742         Variant[] params = new Variant[]{vProcess, vPriority};
 743         Variant result = autoItX.invoke("ProcessSetPriority", params);
 744         return oneToTrue(result.getInt());
 745     }
 746 
 747     /**
 748      * Pauses script execution until a given process exists.
 749      * @param process The name of the process to check.
 750      * @param timeout Specifies how long to wait (default is to wait indefinitely).
 751      * @return True if success, false otherwise.
 752      */
 753     public boolean processWait(String process, int timeout) {
 754         Variant vProcess = new Variant(process);
 755         Variant vTimeout = new Variant(timeout);
 756         Variant[] params = new Variant[]{vProcess, vTimeout};
 757         Variant result = autoItX.invoke("ProcessWait", params);
 758         return oneToTrue(result.getInt());
 759     }
 760 
 761     /**
 762      * Pauses script execution until a given process exists.
 763      * @param process The name of the process to check.
 764      * @return True if success, false otherwise.
 765      */
 766     public boolean processWait(String process) {
 767         Variant result = autoItX.invoke("ProcessWait", process);
 768         return oneToTrue(result.getInt());
 769     }
 770 
 771     /**
 772      * Pauses script execution until a given process exists.
 773      * @param process The name of the process to check.
 774      * @param timeout Specifies how long to wait (default is to wait indefinitely).
 775      * @return True if success, false otherwise.
 776      */
 777     public boolean processWaitClose(String process, int timeout) {
 778         Variant vProcess = new Variant(process);
 779         Variant vTimeout = new Variant(timeout);
 780         Variant[] params = new Variant[]{vProcess, vTimeout};
 781         Variant result = autoItX.invoke("ProcessWaitClose", params);
 782         return oneToTrue(result.getInt());
 783     }
 784 
 785     /**
 786      * Pauses script execution until a given process exists.
 787      * @param process The name of the process to check.
 788      * @return True if success, false otherwise.
 789      */
 790     public boolean processWaitClose(String process) {
 791         Variant result = autoItX.invoke("ProcessWaitClose", process);
 792         return oneToTrue(result.getInt());
 793     }
 794 
 795     /**
 796      * Runs an external program.
 797      * @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
 798      * @param workingDirectory The working directory.
 799      * @param flag The "show" flag of the executed program:
 800      * <br/>SW_HIDE = Hidden window
 801      * <br/>SW_MINIMIZE = Minimized window
 802      * <br/>SW_MAXIMIZE = Maximized window
 803      * @return The PID of the process that was launched. After running the requested program the script continues. To pause execution of the script until the spawned program has finished use the RunWait function instead.
 804      * The error property is set to 1 as an indication of failure.
 805      */
 806     public int run(String filename, String workingDirectory, int flag) {
 807         Variant vFilename = new Variant(filename);
 808         Variant vWorkingDirectory = new Variant(workingDirectory);
 809         Variant vFlag = new Variant(flag);
 810         Variant[] params = new Variant[]{vFilename, vWorkingDirectory, vFlag};
 811         return autoItX.invoke("Run", params).getInt();
 812     }
 813 
 814     /**
 815      * Runs an external program.
 816      * @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
 817      * @param workingDirectory The working directory.
 818      * @return The PID of the process that was launched. After running the requested program the script continues. To pause execution of the script until the spawned program has finished use the RunWait function instead.
 819      * The error property is set to 1 as an indication of failure.
 820      */
 821     public int run(String filename, String workingDirectory) {
 822         Variant vFilename = new Variant(filename);
 823         Variant vWorkingDirectory = new Variant(workingDirectory);
 824         Variant[] params = new Variant[]{vFilename, vWorkingDirectory};
 825         return autoItX.invoke("Run", params).getInt();
 826     }
 827 
 828     /**
 829      * Runs an external program.
 830      * @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
 831      * @return The PID of the process that was launched. After running the requested program the script continues. To pause execution of the script until the spawned program has finished use the RunWait function instead.
 832      * The error property is set to 1 as an indication of failure.
 833      */
 834     public int run(String filename) {
 835         return autoItX.invoke("Run", filename).getInt();
 836     }
 837 
 838     /**
 839      * Initialize a set of user credentials to use during Run and RunWait operations. 2000/XP or later ONLY.
 840      * @param username The user name to use.
 841      * @param domain The domain name to use.
 842      * @param password The password to use.
 843      * @param options 0 = do not load the user profile, 1 = (default) load the user profile, 2 = use for net credentials only
 844      * @return Returns 0 if the operating system does not support this function.
 845      * Otherwise returns 1--regardless of success. (If the login information was invalid, subsequent Run/RunWait commands will fail....)
 846      */
 847     public int runAsSet(String username, String domain, String password, int options) {
 848         Variant vUsername = new Variant(username);
 849         Variant vDomain = new Variant(domain);
 850         Variant vPassword = new Variant(password);
 851         Variant vOptions = new Variant(options);
 852         Variant[] params = new Variant[]{vUsername, vDomain, vPassword, vOptions};
 853         return autoItX.invoke("RunAsSet", params).getInt();
 854     }
 855 
 856     /**
 857      * Initialize a set of user credentials to use during Run and RunWait operations. 2000/XP or later ONLY.
 858      * @param username The user name to use.
 859      * @param domain The domain name to use.
 860      * @param password The password to use.
 861      * @return Returns 0 if the operating system does not support this function.
 862      * Otherwise returns 1--regardless of success. (If the login information was invalid, subsequent Run/RunWait commands will fail....)
 863      */
 864     public int runAsSet(String username, String domain, String password) {
 865         return runAsSet(username, domain, password, 1);
 866     }
 867 
 868     /**
 869      * Runs an external program and pauses script execution until the program finishes.
 870      * @param filename The name of the executable (EXE, BAT, COM, PIF) to run.
 871      * @param workingDirectory The working directory.
 872      * @param flag The "show" flag of the executed program:
 873      * <br/>            SW_HIDE = Hidden window
 874      * <br/>            SW_MINIMIZE = Minimized window
 875      * <br/>            SW_MAXIMIZE = Maximized window
 876      * @return Returns the exit code of the program that was run. The error property is set to 1 as an indication of failure.
 877      */
 878     public int runWait(String filename, String workingDirectory, int flag) {
 879         Variant vFilename = new Variant(filename);
 880         Variant vWorkingDirectory = new Variant(workingDirectory);
 881         Variant vFlag = new Variant(flag);
 882         Variant[] params = new Variant[]{vFilename, vWorkingDirectory, vFlag};
 883         return autoItX.invoke("RunWait", params).getInt();
 884     }
 885 
 886     /**
 887      * Runs an external program and pauses script execution until the program finishes.
 888      * @param filename The name of the executable (EXE, BAT, COM, PIF) to run.
 889      * @param workingDirectory The working directory.
 890      * @return Returns the exit code of the program that was run. The error property is set to 1 as an indication of failure.
 891      */
 892     public int runWait(String filename, String workingDirectory) {
 893         Variant vFilename = new Variant(filename);
 894         Variant vWorkingDirectory = new Variant(workingDirectory);
 895         Variant[] params = new Variant[]{vFilename, vWorkingDirectory};
 896         return autoItX.invoke("RunWait", params).getInt();
 897     }
 898 
 899     /**
 900      * Runs an external program and pauses script execution until the program finishes.
 901      * @param filename The name of the executable (EXE, BAT, COM, PIF) to run.
 902      * @return Returns the exit code of the program that was run. The error property is set to 1 as an indication of failure.
 903      */
 904     public int runWait(String filename) {
 905         return autoItX.invoke("RunWait", filename).getInt();
 906     }
 907 
 908     /**
 909      * Shuts down the system.
 910      * @param code The shutdown code is a combination of the following values:
 911      * <br/>0 = Logoff
 912      * <br/>1 = Shutdown
 913      * <br/>2 = Reboot
 914      * <br/>4 = Force
 915      * <br/>8 = Power down
 916      * Add the required values together. To shutdown and power down, for example, the code would be 9 (shutdown + power down = 1 + 8 = 9).
 917      * @return True if success, false otherwise.
 918      */
 919     public boolean shutdown(int code) {
 920         return oneToTrue(autoItX.invoke("Shutdown", new Variant(code)).getInt());
 921     }
 922 
 923     /**
 924      * Deletes a key from the registry.
 925      * @param keyname The registry key to write to.
 926      * @return Success: Returns 1. Special: Returns 0 if the key does not exist. Failure: Returns 2 if error deleting key. 
 927      */
 928     public int regDeleteKey(String keyname) {
 929         return autoItX.invoke("RegDeleteKey", keyname).getInt();
 930     }
 931 
 932     /**
 933      * Deletes a value from the registry.
 934      * @param keyname The registry key to write to.
 935      * @return Success: Returns 1. Special: Returns 0 if the key does not exist. Failure: Returns 2 if error deleting key.
 936      */
 937     public int regDeleteVal(String keyname) {
 938         return autoItX.invoke("RegDeleteVal", keyname).getInt();
 939     }
 940 
 941     /**
 942      * Reads the name of a subkey according to it's instance.
 943      * @param keyname The registry key to read.
 944      * @param instance The 1-based key instance to retrieve.
 945      * @return Success: Returns the requested subkey name. Otherwise Returns "" and sets the .error() flag,  1 if unable to open requested key, -1 if unable to retrieve requested subkey (key instance out of range)
 946      */
 947     public String regEnumKey(String keyname, int instance) {
 948         Variant vKeyname = new Variant(keyname);
 949         Variant vInstance = new Variant(instance);
 950         Variant[] params = new Variant[]{vKeyname, vInstance};
 951         return autoItX.invoke("RegEnumKey", params).getString();
 952     }
 953 
 954     /**
 955      * Reads the name of a value according to it's instance.
 956      * @param keyname The registry key to read.
 957      * @param instance The 1-based key instance to retrieve.
 958      * @return Success: Returns the requested subkey name. Otherwise Returns "" and sets the .error() flag,  1 if unable to open requested key, -1 if unable to retrieve requested subkey (key instance out of range)
 959      */
 960     public String regEnumVal(String keyname, int instance) {
 961         Variant vKeyname = new Variant(keyname);
 962         Variant vInstance = new Variant(instance);
 963         Variant[] params = new Variant[]{vKeyname, vInstance};
 964         return autoItX.invoke("RegEnumVal", params).getString();
 965     }
 966 
 967     /**
 968      * Reads the name of a value according to it's instance.
 969      * @param keyname The registry key to read.
 970      * @param valueName The registry value to read.
 971      * @return Success:Returns the requested registry value value.
 972      * Otherwise Returns numeric 1 and sets the oAutoIt.error flag:
 973      * <br/>1 if unable to open requested key
 974      * <br/>-1 if unable to open requested value
 975      * <br/>-2 if value type not supported
 976      */
 977     public String regRead(String keyname, String valueName) {
 978         Variant vKeyname = new Variant(keyname);
 979         Variant vValueName = new Variant(valueName);
 980         Variant[] params = new Variant[]{vKeyname, vValueName};
 981         Variant result = autoItX.invoke("RegRead", params);
 982         if (result.getvt() == Variant.VariantInt) {
 983             return String.valueOf(result.getInt());
 984         }
 985         if (result.getvt() == Variant.VariantString) {
 986             return result.getString();
 987         }
 988         return "";
 989     }
 990 
 991     /**
 992      * Creates a key or value in the registry.
 993      * @param keyname The registry key to write to. If no other parameters are specified this key will simply be created.
 994      * @param valueName The valuename to write to.
 995      * @param type Type of key to write: "REG_SZ", "REG_MULTI_SZ", "REG_EXPAND_SZ", "REG_DWORD", or "REG_BINARY".
 996      * @param value The value to write.
 997      * @return True if success, false otherwise.
 998      */
 999     public boolean regWrite(String keyname, String valueName, String type, String value) {
1000         Variant vKeyname = new Variant(keyname);
1001         Variant vValueName = new Variant(valueName);
1002         Variant vType = new Variant(type);
1003         Variant vValue = new Variant(value);
1004         Variant[] params = new Variant[]{vKeyname, vValueName, vType, vValue};
1005         Variant result = autoItX.invoke("RegWrite", params);
1006         return oneToTrue(result.getInt());
1007     }
1008 
1009     /**
1010      * Pause script execution.
1011      * @param delay Amount of time to pause (in milliseconds).
1012      */
1013     public void sleep(int delay) {
1014         autoItX.invoke("sleep", delay);
1015     }
1016 
1017     /**
1018      * Sends a mouse click command to a given control.
1019      * @param title The title of the window to access.
1020      * @param text The text of the window to access.
1021      * @param controlID The control to interact with.
1022      * @param button The button to click, "left", "right" or "middle". Default is the left button.
1023      * @param clicks The number of times to click the mouse. Default is center.
1024      * @param x The x position to click within the control. Default is center.
1025      * @param y The y position to click within the control. Default is center.
1026      * @return True if success, false otherwise.
1027      */
1028     public boolean controlClick(String title, String text, String controlID, String button, int clicks, int x, int y) {
1029         Variant vTitle = new Variant(title);
1030         Variant vText = new Variant(text);
1031         Variant vControlID = new Variant(controlID);
1032         Variant vButton = new Variant(button);
1033         Variant vClicks = new Variant(clicks);
1034         Variant vX = new Variant(x);
1035         Variant vY = new Variant(y);
1036         Variant[] params = new Variant[]{vTitle, vText, vControlID, vButton, vClicks, vX, vY};
1037         Variant result = autoItX.invoke("ControlClick", params);
1038         return oneToTrue(result.getInt());
1039     }
1040 
1041     /**
1042      * Sends a mouse click command to a given control.
1043      * @param title The title of the window to access.
1044      * @param text The text of the window to access.
1045      * @param controlID The control to interact with.
1046      * @param button The button to click, "left", "right" or "middle". Default is the left button.
1047      * @param clicks The number of times to click the mouse. Default is center.
1048      * @return True if success, false otherwise.
1049      */
1050     public boolean controlClick(String title, String text, String controlID, String button, int clicks) {
1051         Variant vTitle = new Variant(title);
1052         Variant vText = new Variant(text);
1053         Variant vControlID = new Variant(controlID);
1054         Variant vButton = new Variant(button);
1055         Variant vClicks = new Variant(clicks);
1056         Variant[] params = new Variant[]{vTitle, vText, vControlID, vButton, vClicks};
1057         Variant result = autoItX.invoke("ControlClick", params);
1058         return oneToTrue(result.getInt());
1059     }
1060 
1061     /**
1062      * Sends a mouse click command to a given control.
1063      * @param title The title of the window to access.
1064      * @param text The text of the window to access.
1065      * @param controlID The control to interact with.
1066      * @param button The button to click, "left", "right" or "middle". Default is the left button.
1067      * @return True if success, false otherwise.
1068      */
1069     public boolean controlClick(String title, String text, String controlID, String button) {
1070         return controlClick(title, text, controlID, button, 1);
1071     }
1072 
1073     /**
1074      * Sends a mouse click command to a given control.
1075      * @param title The title of the window to access.
1076      * @param text The text of the window to access.
1077      * @param controlID The control to interact with.
1078      * @return True if success, false otherwise.
1079      */
1080     public boolean controlClick(String title, String text, String controlID) {
1081         return controlClick(title, text, controlID, "left", 1);
1082     }
1083 
1084     protected String controlCommandString(String title, String text, String control, String command, String option) {
1085         Variant result = controlCommandVariant(title, text, control, command, option);
1086         return result.getString();
1087     }
1088 
1089     protected void controlCommandVoid(String title, String text, String control, String command, String option) {
1090         controlCommandVariant(title, text, control, command, option);
1091 
1092     }
1093 
1094     protected Variant controlCommandVariant(String title, String text, String control, String command, String option) {
1095         Variant vTitle = new Variant(title);
1096         Variant vText = new Variant(text);
1097         Variant vControl = new Variant(control);
1098         Variant vCommand = new Variant(command);
1099         Variant vOption = new Variant(option);
1100         Variant[] params = new Variant[]{vTitle, vText, vControl, vCommand, vOption};
1101         return autoItX.invoke("ControlCommand", params);
1102     }
1103 
1104     /**
1105      * Drops a ComboBox
1106      * @param title The title of the window to access.
1107      * @param text The text of the window to access.
1108      * @param control The control to interact with.
1109      */
1110     public void controlCommandShowDropdown(String title, String text, String control) {
1111         controlCommandVoid(title, text, control, "ShowDropDown", "");
1112     }
1113 
1114     /**
1115      * Undrops a ComboBox
1116      * @param title The title of the window to access.
1117      * @param text The text of the window to access.
1118      * @param control The control to interact with.
1119      */
1120     public void controlCommandHideDropDown(String title, String text, String control) {
1121         controlCommandVoid(title, text, control, "HideDropDown", "");
1122     }
1123 
1124     /**
1125      * Checks radio or check Button
1126      * @param title The title of the window to access.
1127      * @param text The text of the window to access.
1128      * @param control The control to interact with.
1129      */
1130     public void controlCommandCheck(String title, String text, String control) {
1131         controlCommandVoid(title, text, control, "Check", "");
1132     }
1133 
1134     /**
1135      * Unchecks radio or check Button
1136      * @param title The title of the window to access.
1137      * @param text The text of the window to access.
1138      * @param control The control to interact with.
1139      */
1140     public void controlCommandUncheck(String title, String text, String control) {
1141         controlCommandVoid(title, text, control, "UnCheck", "");
1142     }
1143 
1144     /**
1145      * Adds a string to the end in a ListBox or ComboBox
1146      * @param title The title of the window to access.
1147      * @param text The text of the window to access.
1148      * @param control The control to interact with.
1149      */
1150     public void controlCommandAddString(String title, String text, String control, String string) {
1151         controlCommandVoid(title, text, control, "AddString", string);
1152     }
1153 
1154     /**
1155      * Deletes a string according to occurrence in a ListBox or ComboBox.
1156      * @param title The title of the window to access.
1157      * @param text The text of the window to access.
1158      * @param control The control to interact with.
1159      */
1160     public void controlCommandDeleteString(String title, String text, String control, String occurance) {
1161         controlCommandVoid(title, text, control, "DelString", occurance);
1162     }
1163 
1164     /**
1165      * Pastes the 'string' at the Edit's caret position.
1166      * @param title The title of the window to access.
1167      * @param text The text of the window to access.
1168      * @param control The control to interact with.
1169      */
1170     public void controlCommandEditPaste(String title, String text, String control, String string) {
1171         controlCommandVoid(title, text, control, "EditPaste", string);
1172     }
1173 
1174     /**
1175      * Sets selection to occurrence ref in a ListBox or ComboBox.
1176      * @param title The title of the window to access.
1177      * @param text The text of the window to access.
1178      * @param control The control to interact with.
1179      */
1180     public void controlCommandSetCurrentSelection(String title, String text, String control, String occurance) {
1181         controlCommandVoid(title, text, control, "SetCurrentSelection", occurance);
1182     }
1183 
1184     /**
1185      * Sets selection according to string in a ListBox or ComboBox
1186      * @param title The title of the window to access.
1187      * @param text The text of the window to access.
1188      * @param control The control to interact with.
1189      */
1190     public void controlCommandSelectString(String title, String text, String control, String string) {
1191         controlCommandVoid(title, text, control, "SelectString", string);
1192     }
1193 
1194     protected boolean controlCommandBoolean(String title, String text, String control, String command, String option) {
1195         return oneToTrue(controlCommandInts(title, text, control, command, option));
1196     }
1197 
1198     /**
1199      * Checks whether a control is visible.
1200      * @param title The title of the window to access.
1201      * @param text The text of the window to access.
1202      * @param control The control to interact with.
1203      * @return True if is visible.
1204      */
1205     public boolean controlCommandIsVisible(String title, String text, String control) {
1206         return controlCommandBoolean(title, text, control, "IsVisible", "");
1207     }
1208 
1209     /**
1210      * Checks whether a control is checked.
1211      * @param title The title of the window to access.
1212      * @param text The text of the window to access.
1213      * @param control The control to interact with.
1214      * @return True if is checked.
1215      */
1216     public boolean controlCommandIsChecked(String title, String text, String control) {
1217         return controlCommandBoolean(title, text, control, "IsChecked", "");
1218     }
1219 
1220     /**
1221      * Checks whether a control is enabled.
1222      * @param title The title of the window to access.
1223      * @param text The text of the window to access.
1224      * @param control The control to interact with.
1225      * @return True if is enabled.
1226      */
1227     public boolean controlCommandIsEnabled(String title, String text, String control) {
1228         return controlCommandBoolean(title, text, control, "IsEnabled", "");
1229     }
1230 
1231     /**
1232      * Returns occurrence ref of the exact string in a ListBox or ComboBox.
1233      * @param title The title of the window to access.
1234      * @param text The text of the window to access.
1235      * @param control The control to interact with.
1236      * @return Returns occurrence ref of the exact string in a ListBox or ComboBox.
1237      */
1238     public int controlCommandFindString(String title, String text, String control, String string) {
1239         return controlCommandInts(title, text, control, "FindString", string);
1240     }
1241 
1242     protected int controlCommandInts(String title, String text, String control, String command, String option) {
1243         Variant result = controlCommandVariant(title, text, control, command, option);
1244         int iResult = 0;
1245         if (result.getvt() == Variant.VariantString) {
1246             iResult = Integer.parseInt(result.getString());
1247         }
1248         return iResult;
1249     }
1250 
1251     /**
1252      * Returns the line # where the caret is in an Edit
1253      * @param title The title of the window to access.
1254      * @param text The text of the window to access.
1255      * @param control The control to interact with.
1256      * @return Returns the line # where the caret is in an Edit
1257      */
1258     public int controlCommandGetCurrentLine(String title, String text, String control) {
1259         return controlCommandInts(title, text, control, "GetCurrentLine", "");
1260     }
1261 
1262     /**
1263      * Returns the column # where the caret is in an Edit
1264      * @param title The title of the window to access.
1265      * @param text The text of the window to access.
1266      * @param control The control to interact with.
1267      * @return Returns the line # where the caret is in an Edit
1268      */
1269     public int controlCommandGetCurrentCol(String title, String text, String control) {
1270         return controlCommandInts(title, text, control, "GetCurrentCol", "");
1271     }
1272 
1273     /**
1274      * Returns the column # where the caret is in an Edit
1275      * @param title The title of the window to access.
1276      * @param text The text of the window to access.
1277      * @param control The control to interact with.
1278      * @return Returns the line # where the caret is in an Edit
1279      */
1280     public int controlCommandGetLineCount(String title, String text, String control) {
1281         return controlCommandInts(title, text, control, "GetLineCount", "");
1282     }
1283 
1284     /**
1285      * Sets selection according to string in a ListBox or ComboBox
1286      * @param title The title of the window to access.
1287      * @param text The text of the window to access.
1288      * @param control The control to interact with.
1289      * @param charLength The er size.
1290      */
1291     public String controlCommandGetCurrentSelection(String title, String text, String control, int charLength) {
1292         return controlCommandString(title, text, control, "GetCurrentSelection", "");
1293     }
1294 
1295     /**
1296      * Returns selected text of an Edit.
1297      * @param title The title of the window to access.
1298      * @param text The text of the window to access.
1299      * @param control The control to interact with.
1300      */
1301     public String controlCommandGetSelected(String title, String text, String control, int charLength) {
1302         return controlCommandString(title, text, control, "GetSelected", "");
1303     }
1304 
1305     /**
1306      * Moves to the next tab to the right of a SysTabControl32
1307      * @param title The title of the window to access.
1308      * @param text The text of the window to access.
1309      * @param control The control to interact with.
1310      */
1311     public void controlCommandTabLeft(String title, String text, String control) {
1312         controlCommandVoid(title, text, control, "TabLeft", "");
1313     }
1314 
1315     /**
1316      * Moves to the next tab to the right of a SysTabControl32
1317      * @param title The title of the window to access.
1318      * @param text The text of the window to access.
1319      * @param control The control to interact with.
1320      */
1321     public void controlCommandTabRight(String title, String text, String control) {
1322         controlCommandVoid(title, text, control, "TabRight", "");
1323     }
1324 
1325     /**
1326      * Returns the current Tab shown of a SysTabControl32.
1327      * @param title The title of the window to access.
1328      * @param text The text of the window to access.
1329      * @param control The control to interact with.
1330      */
1331     public String controlCommandCurrentTab(String title, String text, String control) {
1332         return controlCommandString(title, text, control, "CurrentTab", "");
1333     }
1334 
1335     /**
1336      * Disables or "grays-out" a control.
1337      * @param title The title of the window to access.
1338      * @param text The text of the window to access.
1339      * @param control The control to interact with.
1340      * @return True if success, false otherwise.
1341      */
1342     public boolean controlDisable(String title, String text, String control) {
1343         Variant vTitle = new Variant(title);
1344         Variant vText = new Variant(text);
1345         Variant vControl = new Variant(control);
1346         Variant[] params = new Variant[]{vTitle, vText, vControl};
1347         Variant result = autoItX.invoke("ControlDisable", params);
1348         return oneToTrue(result.getInt());
1349     }
1350 
1351     /**
1352      * Enables a "grayed-out" control.
1353      * Use with caution.
1354      * When using a control name in the Control functions, you need to add a number to the end of the name to indicate which control. For example, if there two controls listed called "MDIClient", you would refer to these as "MDIClient1" and "MDIClient2".
1355      * @param title The title of the window to access.
1356      * @param text The text of the window to access.
1357      * @param control The control to interact with.
1358      * @return True if success, false otherwise.
1359      */
1360     public boolean controlEnable(String title, String text, String control) {
1361         Variant vTitle = new Variant(title);
1362         Variant vText = new Variant(text);
1363         Variant vControl = new Variant(control);
1364         Variant[] params = new Variant[]{vTitle, vText, vControl};
1365         Variant result = autoItX.invoke("ControlEnable", params);
1366         return oneToTrue(result.getInt());
1367     }
1368 
1369     /**
1370      * Sets input focus to a given control on a window.
1371      * @param title The title of the window to access.
1372      * @param text The text of the window to access.
1373      * @param control The control to interact with.
1374      * @return True if success, false otherwise.
1375      */
1376     public boolean controlFocus(String title, String text, String control) {
1377         return controlBool(title, text, control, "ControlFocus");
1378     }
1379 
1380     /**
1381      * Returns the ControlRef# of the control that has keyboard focus within a specified window.
1382      * @param title Title of window to check.
1383      * @param text Text from window to check.
1384      * @return ControlRef# of the control that has keyboard focus within a specified window. Otherwise returns a blank string and sets .error() to 1 if window is not found.
1385      */
1386     public String controlGetFocus(String title, String text) {
1387         Variant vTitle = new Variant(title);
1388         Variant vText = new Variant(text);
1389         Variant[] params = new Variant[]{vTitle, vText};
1390         return autoItX.invoke("ControlGetFocus", params).getString();
1391     }
1392 
1393     /**
1394      * Returns the ControlRef# of the control that has keyboard focus within a specified window.
1395      * @param title Title of window to check.
1396      * @return ControlRef# of the control that has keyboard focus within a specified window. Otherwise returns a blank string and sets .error() to 1 if window is not found.
1397      */
1398     public String controlGetFocus(String title) {
1399         return autoItX.invoke("ControlGetFocus", title).getString();
1400     }
1401 
1402     /**
1403      * Retrieves the internal handle of a control.
1404      * @param title The title of the window to read.
1405      * @param text The text of the window to read.
1406      * @param controlID The control to interact with.
1407      * @return Returns a string containing the control handle value. Otherwise returns "" (blank string) and sets oAutoIt.error to 1 if no window matches the criteria.
1408      */
1409     public String controlGetHandle(String title, String text, String controlID) {
1410         return controlString(title, text, controlID, "ControlGetHandle");
1411     }
1412 
1413     /**
1414      * Retrieves the position and size of a control relative to it's window.
1415      * @param title The title of the window to access.
1416      * @param text The text of the window to access.
1417      * @param controlID The control to interact with.
1418      * @return The X coordinate of the control. Otherwise returns the X coordinate of the control.
1419      */
1420     public int controlGetPosX(String title, String text, String controlID) {
1421         return controlInt(title, text, controlID, "ControlGetPosX");
1422     }
1423 
1424     /**
1425      * Retrieves the position and size of a control relative to it's window.
1426      * @param title The title of the window to access.
1427      * @param text The text of the window to access.
1428      * @param controlID The control to interact with.
1429      * @return The Y coordinate of the control. Otherwise returns the Y coordinate of the control.
1430      */
1431     public int controlGetPosY(String title, String text, String controlID) {
1432         return controlInt(title, text, controlID, "ControlGetPosY");
1433     }
1434 
1435     /**
1436      * Retrieves the position and size of a control relative to it's window.
1437      * @param title The title of the window to access.
1438      * @param text The text of the window to access.
1439      * @param controlID The control to interact with.
1440      * @return The width of the control. Otherwise sets .error() to 1.
1441      */
1442     public int controlGetPosWidth(String title, String text, String controlID) {
1443         return controlInt(title, text, controlID, "ControlGetPosWidth");
1444     }
1445 
1446     /**
1447      * Retrieves the position and size of a control relative to it's window.
1448      * @param title The title of the window to access.
1449      * @param text The text of the window to access.
1450      * @param controlID The control to interact with.
1451      * @return Returns the height of the control. Otherwise returns the Y coordinate of the control.
1452      */
1453     public int controlGetPosHeight(String title, String text, String controlID) {
1454         return controlInt(title, text, controlID, "ControlGetPosHeight");
1455     }
1456 
1457     /**
1458      * Retrieves text from a control.
1459      * @param title The title of the window to access.
1460      * @param text The text of the window to access.
1461      * @param controlID The control to interact with.
1462      * @return Text from a control. If fails, sets .error() to 1 and returns a blank string of "".
1463      */
1464     public String controlGetText(String title, String text, String controlID) {
1465         return controlString(title, text, controlID, "ControlGetText");
1466     }
1467 
1468     /**
1469      * Hides a control.
1470      * @param title The title of the window to access.
1471      * @param text The text of the window to access.
1472      * @param controlID The control to interact with.
1473      * @return True if success, false otherwise.
1474      */
1475     public boolean controlHide(String title, String text, String controlID) {
1476         return controlBool(title, text, controlID, "ControlHide");
1477     }
1478 
1479     /**
1480      * Returns the item index of the string. Returns -1 if the string is not found.
1481      * @param title The title of the window to access.
1482      * @param text The text of the window to access.
1483      * @param control The control to interact with.
1484      * @param string String to find
1485      * @param subitem The SubItem
1486      * @return Returns the item index of the string. Returns -1 if the string is not found.
1487      */
1488     public int controlListViewFindItem(String title, String text, String control, String string, String subitem) {
1489         return controlListViewInt(title, text, control, "FindItem", string, subitem);
1490     }
1491 
1492     protected int controlListViewInt(String title, String text, String control, String command, String option, String option2) {
1493         return controlView(title, text, control, command, option, option2, "ControlListView").getInt();
1494     }
1495 
1496     protected String controlListViewString(String title, String text, String control, String command, String option, String option2) {
1497         return controlView(title, text, control, command, option, option2, "ControlListView").getString();
1498     }
1499 
1500     protected Variant controlView(String title, String text, String control, String command, String option, String option2, String function) {
1501         Variant vTitle = new Variant(title);
1502         Variant vText = new Variant(text);
1503         Variant vControl = new Variant(control);
1504         Variant vCommand = new Variant(command);
1505         Variant vOption = new Variant(option);
1506         Variant vOption2 = new Variant(option2);
1507         Variant[] params = new Variant[]{vTitle, vText, vControl, vCommand, vOption, vOption2};
1508         return autoItX.invoke(function, params);
1509     }
1510 
1511     /**
1512      * Returns the number of list items.
1513      * @param title The title of the window to access.
1514      * @param text The text of the window to access.
1515      * @param control The control to interact with.
1516      * @return Returns the number of list items.
1517      */
1518     public int controlListViewGetItemCount(String title, String text, String control) {
1519         return controlListViewInt(title, text, control, "GetItemCount", "", "");
1520 
1521     }
1522 
1523     /**
1524      * Returns the number of items that are selected.
1525      * @param title The title of the window to access.
1526      * @param text The text of the window to access.
1527      * @param control The control to interact with.
1528      * @return Returns the number of items that are selected.
1529      */
1530     public int controlListViewGetSelectedCount(String title, String text, String control) {
1531         return controlListViewInt(title, text, control, "GetSelectedCount", "", "");
1532     }
1533 
1534     /**
1535      * Returns the number of subitems.
1536      * @param title The title of the window to access.
1537      * @param text The text of the window to access.
1538      * @param control The control to interact with.
1539      * @return Returns the number of subitems.
1540      */
1541     public int controlListViewGetSubItemCount(String title, String text, String control) {
1542         return controlListViewInt(title, text, control, "GetSubItemCount", "", "");
1543     }
1544 
1545     /**
1546      * Returns the text of a given item/subitem.
1547      * @param title The title of the window to access.
1548      * @param text The text of the window to access.
1549      * @param control The control to interact with.
1550      * @param item The text of an item.
1551      * @param subitem The text of a subitem.
1552      * @return Returns the text of a given item/subitem.
1553      */
1554     public String controlListViewGetText(String title, String text, String control, String item, String subitem) {
1555         return controlListViewString(title, text, control, "GetText", item, subitem);
1556     }
1557 
1558     /**
1559      * Returns 1 if the item is selected, otherwise returns 0.
1560      * Returns the text of a given item/subitem.
1561      * @param title The title of the window to access.
1562      * @param text The text of the window to access.
1563      * @param control The control to interact with.
1564      * @param item The text of an item.
1565      * @return Returns 1 if the item is selected, otherwise returns 0.
1566      */
1567     public boolean controlListViewIsSelected(String title, String text, String control, String item) {
1568         return oneToTrue(controlListViewInt(title, text, control, "IsSelected", item, ""));
1569     }
1570 
1571     /**
1572      * Returns a string containing the item index of selected items. If option=0 (default) only the first selected item is returned. If option=1 then all the selected items are returned delimited by |, e.g: "0|3|4|10". If no items are selected a blank "" string is returned.
1573      * @param title The title of the window to access.
1574      * @param text The text of the window to access.
1575      * @param control The control to interact with.
1576      * @return Returns a string containing the item index of selected items. If option=0 (default) only the first selected item is returned. If option=1 then all the selected items are returned delimited by |, e.g: "0|3|4|10". If no items are selected a blank "" string is returned.
1577      */
1578     public String controlListViewGetSelected(String title, String text, String control) {
1579         return controlListViewString(title, text, control, "GetSelected", "", "");
1580     }
1581 
1582     /**
1583      * Returns a string containing the item index of selected items. If option=0 (default) only the first selected item is returned. If option=1 then all the selected items are returned delimited by |, e.g: "0|3|4|10". If no items are selected a blank "" string is returned.
1584      * If no items are selected a blank "" string is returned.
1585      * @param title The title of the window to access.
1586      * @param text The text of the window to access.
1587      * @param control The control to interact with.
1588      * @return Returns a string containing the item index of selected items. If option=0 (default) only the first selected item is returned. If option=1 then all the selected items are returned delimited by |, e.g: "0|3|4|10". If no items are selected a blank "" string is returned.
1589      */
1590     public String[] controlListViewGetSelectedArray(String title, String text, String control) {
1591         SafeArray safeArr = controlView(title, text, control, "GetSelected", "", "", "ControlListView").toSafeArray();
1592         return safeArr.toStringArray();
1593     }
1594 
1595     /**
1596      * Selects one or more items.
1597      * @param title The title of the window to access.
1598      * @param text The text of the window to access.
1599      * @param control The control to interact with.
1600      * @param from The start index.
1601      * @param to The to index.
1602      */
1603     public void controlListViewSelect(String title, String text, String control, String from, String to) {
1604         controlView(title, text, control, "Select", from, to, "ControlListView");
1605     }
1606 
1607     /**
1608      * Selects all items.
1609      * @param title The title of the window to access.
1610      * @param text The text of the window to access.
1611      * @param control The control to interact with.
1612      */
1613     public void controlListViewSelectAll(String title, String text, String control, String from, String to) {
1614         controlView(title, text, control, "SelectAll", from, to, "ControlListView");
1615     }
1616 
1617     /**
1618      * Selects all items.
1619      * @param title The title of the window to access.
1620      * @param text The text of the window to access.
1621      * @param control The control to interact with.
1622      * @param from The start index.
1623      */
1624     public void controlListViewSelectAll(String title, String text, String control, String from) {
1625         Variant vTitle = new Variant(title);
1626         Variant vText = new Variant(text);
1627         Variant vControl = new Variant(control);
1628         Variant vCommand = new Variant("SelectAll");
1629         Variant vFrom = new Variant(from);
1630         Variant[] params = new Variant[]{vTitle, vText, vControl, vCommand, vFrom};
1631         autoItX.invoke("ControlListView", params);
1632     }
1633 
1634     /**
1635      * Clears the selection of all items.
1636      * @param title The title of the window to access.
1637      * @param text The text of the window to access.
1638      * @param control The control to interact with.
1639      */
1640     public void controlListViewSelectClear(String title, String text, String control) {
1641         controlView(title, text, control, "SelectClear", "", "", "ControlListView");
1642     }
1643 
1644     /**
1645      * Inverts the current selection.
1646      * @param title The title of the window to access.
1647      * @param text The text of the window to access.
1648      * @param control The control to interact with.
1649 
1650      */
1651     public void controlListViewSelectInvert(String title, String text, String control) {
1652         controlView(title, text, control, "SelectInvert", "", "", "ControlListView");
1653     }
1654 
1655     /**
1656      * Changes the current view. Valid views are "list", "details", "smallicons", "largeicons".
1657      * @param title The title of the window to access.
1658      * @param text The text of the window to access.
1659      * @param control The control to interact with.
1660      * @param view Valid views are "list", "details", "smallicons", "largeicons".
1661      */
1662     public void controlListViewSelectViewChange(String title, String text, String control, String view) {
1663         controlView(title, text, control, "ViewChnage", view, "", "ControlListView");
1664     }
1665 
1666     protected Variant controlVariant(String title, String text, String control, String function) {
1667         Variant vTitle = new Variant(title);
1668         Variant vText = new Variant(text);
1669         Variant vControl = new Variant(control);
1670         Variant[] params = new Variant[]{vTitle, vText, vControl};
1671         return autoItX.invoke(function, params);
1672     }
1673 
1674     protected boolean controlBool(String title, String text, String control, String function) {
1675         Variant result = controlVariant(title, text, control, function);
1676         return oneToTrue(result.getInt());
1677     }
1678 
1679     protected int controlInt(String title, String text, String control, String function) {
1680         Variant result = controlVariant(title, text, control, function);
1681         return result.getInt();
1682     }
1683 
1684     protected String controlString(String title, String text, String control, String function) {
1685         Variant result = controlVariant(title, text, control, function);
1686         if (result.getvt() == Variant.VariantString) {
1687             return result.getString();
1688         }
1689         if (result.getvt() == Variant.VariantInt) {
1690             return String.valueOf(result.getInt());
1691         }
1692         return "";
1693     }
1694 
1695     /**
1696      * Moves a control within a window.
1697      * @param title The title of the window to access.
1698      * @param text The text of the window to access.
1699      * @param control The control to interact with.
1700      * @param x X coordinate to move to.
1701      * @param y Y coordinate to move to.
1702      * @param width New width of the window.
1703      * @param height New height of the window.
1704      * @return True if success, false otherwise
1705      */
1706     public boolean controlMove(String title, String text, String control, int x, int y, int width, int height) {
1707         Variant vTitle = new Variant(title);
1708         Variant vText = new Variant(text);
1709         Variant vControl = new Variant(control);
1710         Variant vX = new Variant(x);
1711         Variant vY = new Variant(y);
1712         Variant vWidth = new Variant(width);
1713         Variant vHeight = new Variant(height);
1714         Variant[] params = new Variant[]{vTitle, vText, vControl, vX, vY, vWidth, vHeight};
1715         Variant result = autoItX.invoke("ControlMove", params);
1716         return oneToTrue(result.getInt());
1717     }
1718 
1719     /**
1720      * Moves a control within a window.
1721      * @param title The title of the window to access.
1722      * @param text The text of the window to access.
1723      * @param control The control to interact with.
1724      * @param x X coordinate to move to.
1725      * @param y Y coordinate to move to.
1726      * @return True if success, false otherwise
1727      */
1728     public boolean controlMove(String title, String text, String control, int x, int y) {
1729         Variant vTitle = new Variant(title);
1730         Variant vText = new Variant(text);
1731         Variant vControl = new Variant(control);
1732         Variant vX = new Variant(x);
1733         Variant vY = new Variant(y);
1734         Variant[] params = new Variant[]{vTitle, vText, vControl, vX, vY};
1735         Variant result = autoItX.invoke("ControlMove", params);
1736         return oneToTrue(result.getInt());
1737     }
1738 
1739     /**
1740      * Sends a string of characters to a control.
1741      * @param title The title of the window to access.
1742      * @param text The text of the window to access.
1743      * @param control The control to interact with.
1744      * @param string String of characters to send to the control.
1745      * @param sendRawKeys If true, text contains special characters like + to indicate SHIFT and {LEFT} to indicate left arrow. If false, text is sent raw.
1746      * @return  True if success, false otherwise
1747      */
1748     public boolean controlSend(String title, String text, String control, String string, boolean sendRawKeys) {
1749         Variant vTitle = new Variant(title);
1750         Variant vText = new Variant(text);
1751         Variant vControl = new Variant(control);
1752         Variant vString = new Variant(string);
1753         int flag = (sendRawKeys) ? 1 : 0;
1754         Variant vFlag = new Variant(flag);
1755         Variant[] params = new Variant[]{vTitle, vText, vControl, vString, vFlag};
1756         Variant result = autoItX.invoke("ControlSend", params);
1757         return oneToTrue(result.getInt());
1758     }
1759 
1760     /**
1761      * Sends a string of characters to a control.
1762      * @param title The title of the window to access.
1763      * @param text The text of the window to access.
1764      * @param control The control to interact with.
1765      * @param string String of characters to send to the control.
1766      * @return True if success, false otherwise
1767      */
1768     public boolean controlSend(String title, String text, String control, String string) {
1769         return controlSend(title, text, control, string, false);
1770     }
1771 
1772     /**
1773      * Sets text of a control.
1774      * Sends a string of characters to a control.
1775      * @param title The title of the window to access.
1776      * @param text The text of the window to access.
1777      * @param control The control to interact with.
1778      * @param string The new text to be set into the control.
1779      * @return True if success, false otherwise
1780      */
1781     public boolean ControlSetText(String title, String text, String control, String string) {
1782         Variant vTitle = new Variant(title);
1783         Variant vText = new Variant(text);
1784         Variant vControl = new Variant(control);
1785         Variant vString = new Variant(string);
1786         Variant[] params = new Variant[]{vTitle, vText, vControl, vString};
1787         Variant result = autoItX.invoke("ControlSetText", params);
1788         return oneToTrue(result.getInt());
1789     }
1790 
1791     /**
1792      * Shows a control that was hidden.
1793      * @param title The title of the window to access.
1794      * @param text The text of the window to access.
1795      * @param control The control to interact with.
1796      * @return True if success, false otherwise.
1797      */
1798     public boolean controlShow(String title, String text, String control) {
1799         return controlBool(title, text, control, "ControlShow");
1800     }
1801 
1802     protected String controlTreeViewString(String title, String text, String control, String command, String option, String option2) {
1803         return controlView(title, text, control, command, option, option2, "ControlTreeView").getString();
1804     }
1805 
1806     protected int controlTreeViewInt(String title, String text, String control, String command, String option, String option2) {
1807         return controlView(title, text, control, command, option, option2, "ControlTreeView").getInt();
1808     }
1809 
1810     public boolean controlTreeViewBoolean(String title, String text, String control, String command, String option, String option2) {
1811         Variant result = controlView(title, text, control, command, option, option2, "ControlTreeView");
1812         return oneToTrue(result.getInt());
1813     }
1814 
1815     /**
1816      * Checks an item (if the item supports it).
1817      * @param title The title of the window to access.
1818      * @param text The text of the window to access.
1819      * @param control The control to interact with.
1820      * @param item The item to check
1821      */
1822     public void controlTreeViewCheck(String title, String text, String control, String item) {
1823         controlView(title, text, control, "Check", item, "", "ControlTreeView");
1824     }
1825 
1826     /**
1827      * Collapses an item to hide its children.
1828      * @param title The title of the window to access.
1829      * @param text The text of the window to access.
1830      * @param control The control to interact with.
1831      * @param item The item to check
1832      */
1833     public void controlTreeViewCollapse(String title, String text, String control, String item) {
1834         controlView(title, text, control, "Collapse", item, "", "ControlTreeView");
1835     }
1836 
1837     /**
1838      * Checks if an item exists
1839      * @param title The title of the window to access.
1840      * @param text The text of the window to access.
1841      * @param control The control to interact with.
1842      * @param item The item to check
1843      */
1844     public Boolean controlTreeViewExists(String title, String text, String control, String item) {
1845         return controlTreeViewBoolean(title, text, control, "Exists", item, "");
1846     }
1847 
1848     /**
1849      * Expands an item to show its children.
1850      * @param title The title of the window to access.
1851      * @param text The text of the window to access.
1852      * @param control The control to interact with.
1853      * @param item The item to expand
1854      */
1855     public void controlTreeViewExpand(String title, String text, String control, String item) {
1856         controlView(title, text, control, "Expand", item, "", "ControlTreeView");
1857     }
1858 
1859     /**
1860      * Returns the number of children for a selected item.
1861      * @param title The title of the window to access.
1862      * @param text The text of the window to access.
1863      * @param control The control to interact with.
1864      * @param item The item to check
1865      * @return The number of children for a selected item.
1866      */
1867     public int controlTreeViewGetItemCount(String title, String text, String control, String item) {
1868         return controlTreeViewInt(title, text, control, "GetItemCount", item, "");
1869     }
1870 
1871     /**
1872      * Returns the item reference of the current selection using the index reference of the item.
1873      * @param title The title of the window to access.
1874      * @param text The text of the window to access.
1875      * @param control The control to interact with.
1876      * @return The item reference of the current selection using the index reference of the item.
1877      */
1878     public int controlTreeViewGetSelectedItemIndex(String title, String text, String control) {
1879         Variant vTitle = new Variant(title);
1880         Variant vText = new Variant(text);
1881         Variant vControl = new Variant(control);
1882         Variant vCommand = new Variant("GetSelected");
1883         Variant vIndex = new Variant(1);
1884         Variant[] params = new Variant[]{vTitle, vText, vControl, vCommand, vIndex};
1885         return autoItX.invoke("ControlTreeView", params).getInt();
1886     }
1887 
1888     /**
1889      * Returns the item reference of the current selection using the text reference of the item.
1890      * @param title The title of the window to access.
1891      * @param text The text of the window to access.
1892      * @param control The control to interact with.
1893      * @return The item reference of the current selection using the text reference of the item.
1894      */
1895     public String controlTreeViewGetSelectedItemText(String title, String text, String control) {
1896         Variant vTitle = new Variant(title);
1897         Variant vText = new Variant(text);
1898         Variant vControl = new Variant(control);
1899         Variant vCommand = new Variant("GetSelected");
1900         Variant vIndex = new Variant(0);
1901         Variant[] params = new Variant[]{vTitle, vText, vControl, vCommand, vIndex};
1902         return autoItX.invoke("ControlTreeView", params).getString();
1903     }
1904 
1905     /**
1906      * GetText
1907      * @param title The title of the window to access.
1908      * @param text The text of the window to access.
1909      * @param control The control to interact with.
1910      * @param item The item to get
1911      * @return The the text of an item.
1912      */
1913     public String controlTreeViewGetText(String title, String text, String control, String item) {
1914         return controlTreeViewString(title, text, control, "GetText", item, "");
1915     }
1916 
1917     /**
1918      * Returns the state of an item. 1:checked, 0:unchecked, -1:not a checkbox.
1919      * @param title The title of the window to access.
1920      * @param text The text of the window to access.
1921      * @param control The control to interact with.
1922      * @return Returns the state of an item. 1:checked, 0:unchecked, -1:not a checkbox.
1923      */
1924     public int controlTreeViewIsChecked(String title, String text, String control) {
1925         return controlView(title, text, control, "IsChecked", "", "", "ControlTreeView").getInt();
1926     }
1927 
1928     /**
1929      * Selects an item.
1930      * @param title The title of the window to access.
1931      * @param text The text of the window to access.
1932      * @param control The control to interact with.
1933      * @param item The item to select
1934      */
1935     public void controlTreeViewSelect(String title, String text, String control, String item) {
1936         controlView(title, text, control, "Select", item, "", "ControlTreeView");
1937     }
1938 
1939     /**
1940      * Uncheck an item.
1941      * @param title The title of the window to access.
1942      * @param text The text of the window to access.
1943      * @param control The control to interact with.
1944      * @param item The item to select
1945      */
1946     public void controlTreeViewUncheck(String title, String text, String control, String item) {
1947         controlView(title, text, control, "Uncheck", item, "", "ControlTreeView");
1948     }
1949 
1950     /**
1951      * Retrieves the text from a standard status bar control.
1952      * @param title The title of the window to check.
1953      * @param text The text of the window to check.
1954      * @param part The "part" number of the status bar to read - the default is 1. 1 is the first possible part and usually the one that contains the useful messages like "Ready" "Loading...", etc.
1955      * @return The text from a standard status bar control.
1956      */
1957     public String statusbarGetText(String title, String text, int part) {
1958         Variant vTitle = new Variant(title);
1959         Variant vText = new Variant(text);
1960         Variant vPart = new Variant(part);
1961         Variant[] params = new Variant[]{vTitle, vText, vPart};
1962         return autoItX.invoke("StatusbarGetText", params).getString();
1963     }
1964 
1965     /**
1966      * Retrieves the text from a standard status bar control.
1967      * @param title The title of the window to check.
1968      * @param text The text of the window to check.
1969      * @return  The text from a standard status bar control.
1970      */
1971     public String StatusbarGetText(String title, String text) {
1972         return winVariant(title, text, "StatusbarGetText").getString();
1973 
1974     }
1975 
1976     protected Variant winVariant(String title, String text, String function) {
1977         Variant vTitle = new Variant(title);
1978         Variant vText = new Variant(text);
1979         Variant[] params = new Variant[]{vTitle, vText};
1980         return autoItX.invoke(function, params);
1981     }
1982 
1983     protected Variant winVariant(String title, String function) {
1984         Variant vTitle = new Variant(title);
1985         Variant[] params = new Variant[]{vTitle};
1986         return autoItX.invoke(function, params);
1987     }
1988 
1989     /**
1990      * Activates (gives focus to) a window.
1991      * @param title The title of the window to activate.
1992      * @param text The text of the window to activate.
1993      */
1994     public void winActivate(String title, String text) {
1995         winVariant(title, text, "WinActivate");
1996     }
1997 
1998     /**
1999      * Activates (gives focus to) a window.
2000      * @param title The title of the window to activate.
2001      */
2002     public void winActivate(String title) {
2003         winVariant(title, "WinActivate");
2004     }
2005 
2006     /**
2007      * Checks to see if a specified window exists and is currently active.
2008      * @param title The title of the window to activate.
2009      * @param text The text of the window to activate.
2010      */
2011     public void winActive(String title, String text) {
2012         winVariant(title, text, "WinActive");
2013     }
2014 
2015     /**
2016      * Checks to see if a specified window exists and is currently active.
2017      * @param title The title of the window to activate.
2018      */
2019     public void winActive(String title) {
2020         winVariant(title, "WinActive");
2021     }
2022 
2023     /**
2024      * Closes a window.
2025      * @param title The title of the window to activate.
2026      * @param text The text of the window to activate.
2027      */
2028     public void winClose(String title, String text) {
2029         winVariant(title, text, "WinClose");
2030     }
2031 
2032     /**
2033      * Closes a window.
2034      * @param title The title of the window to activate.
2035      */
2036     public void winClose(String title) {
2037         winVariant(title, "WinClose");
2038     }
2039 
2040     /**
2041      * Checks to see if a specified window exists.
2042      * @param title The title of the window to activate.
2043      * @param text The text of the window to activate.
2044      * @return True if window exists, false otherwise.
2045      */
2046     public boolean winExists(String title, String text) {
2047         Variant result = winVariant(title, text, "WinExists");
2048         return oneToTrue(result.getInt());
2049     }
2050 
2051     /**
2052      * Checks to see if a specified window exists.
2053      * @param title The title of the window to activate.
2054      * @return True if window exists, false otherwise.
2055      */
2056     public boolean winExists(String title) {
2057         Variant result = winVariant(title, "WinExists");
2058         return oneToTrue(result.getInt());
2059     }
2060 
2061     /**
2062      * Returns the coordinates of the caret in the foreground window
2063      * @return The coordinates of the caret in the foreground window
2064      */
2065     public int winGetCaretPosX() {
2066         return autoItX.invoke("WinGetCaretPosX").getInt();
2067     }
2068 
2069     /**
2070      * Returns the coordinates of the caret in the foreground window
2071      * @return The coordinates of the caret in the foreground window
2072      */
2073     public int winGetCaretPosY() {
2074         return autoItX.invoke("WinGetCaretPosY").getInt();
2075     }
2076 
2077     /**
2078      * Retrieves the classes from a window.
2079      * @param title The title of the window to read.
2080      * @param text The text of the window to read.
2081      * @return A string containing the window classes read, otherwise returns empty string and sets .error() to 1.
2082      */
2083     public String winGetClassList(String title, String text) {
2084         Variant vTitle = new Variant(title);
2085         Variant vText = new Variant(text);
2086         Variant[] params = new Variant[]{vTitle, vText};
2087         Variant result = autoItX.invoke("WinGetClassList", params);
2088         return safeString(result);
2089     }
2090 
2091     /**
2092      * Retrieves the size of a given window's client area.
2093      * @param title The title of the window to read.
2094      * @param text The text of the window to read.
2095      * @return Returns the width of the window's client area, else returns 1 and sets .error() =1;
2096      */
2097     public int winGetClientSizeWidth(String title, String text) {
2098         Variant result = winVariant(title, text, "WinGetClientSizeWidth");
2099         return result.getInt();
2100     }
2101 
2102     /**
2103      * Retrieves the size of a given window's client area.
2104      * @param title The title of the window to read.
2105      * @param text The text of the window to read.
2106      * @return Returns the height of the window's client area, else returns 1 and sets .error() =1;
2107      */
2108     public int winGetClientSizeHeight(String title, String text) {
2109         Variant result = winVariant(title, text, "WinGetClientSizeHeight");
2110         return result.getInt();
2111     }
2112 
2113     /**
2114      * Retrieves the size of a given window's client area.
2115      * @param title The title of the window to read.
2116      * @return Returns the width of the window's client area, else returns 1 and sets .error() =1;
2117      */
2118     public int winGetClientSizeWidth(String title) {
2119         Variant result = winVariant(title, "WinGetClientSizeWidth");
2120         return result.getInt();
2121     }
2122 
2123     /**
2124      * Retrieves the size of a given window's client area.
2125      * @param title The title of the window to read.
2126      * @return Returns the height of the window's client area, else returns 1 and sets .error() =1;
2127      */
2128     public int winGetClientSizeHeight(String title) {
2129         Variant result = winVariant(title, "WinGetClientSizeHeight");
2130         return result.getInt();
2131     }
2132 
2133     protected String safeString(Variant v) {
2134         String safeResult = "";
2135         if (v.getvt() == Variant.VariantString) {
2136             safeResult = v.getString();
2137         }
2138         return safeResult;
2139     }
2140 
2141     /**
2142      * Retrieves the internal handle of a window.
2143      * @param title The title of the window to read.
2144      * @param text The text of the window to read.
2145      * @return A string containing the window handle value. Otherwise returns "" and sets .error() to 1.
2146      */
2147     public String winGetHandle(String title, String text) {
2148         Variant result = winVariant(title, text, "WinGetHandle");
2149         return result.getString();
2150     }
2151 
2152     /**
2153      * Retrieves the internal handle of a window.
2154      * @param title The title of the window to read.
2155      * @return A string containing the window handle value. Otherwise returns "" and sets .error() to 1.
2156      */
2157     public String winGetHandle(String title) {
2158         Variant result = winVariant(title, "WinGetHandle");
2159         return result.getString();
2160     }
2161 
2162     /**
2163      * Retrieves the position and size of a given window.
2164      * @param title The title of the window to read.
2165      * @param text The text of the window to read.
2166      * @return Returns the X coordinate of the window. Otherwise returns 1 and sets .error() = 1
2167      */
2168     public int winGetPosX(String title, String text) {
2169         Variant result = winVariant(title, text, "WinGetPosX");
2170         return result.getInt();
2171     }
2172 
2173     /**
2174      * Retrieves the position and size of a given window.
2175      * @param title The title of the window to read.
2176      * @return Returns the X coordinate of the window. Otherwise returns 1 and sets .error() = 1
2177      */
2178     public int winGetPosX(String title) {
2179         Variant result = winVariant(title, "WinGetPosX");
2180         return result.getInt();
2181     }
2182 
2183     /**
2184      * Retrieves the position and size of a given window.
2185      * @param title The title of the window to read.
2186      * @param text The text of the window to read.
2187      * @return Returns the Y coordinate of the window. Otherwise returns 1 and sets .error() = 1
2188      */
2189     public int winGetPosY(String title, String text) {
2190         Variant result = winVariant(title, text, "WinGetPosY");
2191         return result.getInt();
2192     }
2193 
2194     /**
2195      * Retrieves the position and size of a given window.
2196      * @param title The title of the window to read.
2197      * @return Returns the Y coordinate of the window. Otherwise returns 1 and sets .error() = 1
2198      */
2199     public int winGetPosY(String title) {
2200         Variant result = winVariant(title, "WinGetPosY");
2201         return result.getInt();
2202     }
2203 
2204     /**
2205      * Retrieves the position and size of a given window.
2206      * @param title The title of the window to read.
2207      * @param text The text of the window to read.
2208      * @return Returns the width of the window. Otherwise returns 1 and sets .error() = 1
2209      */
2210     public int winGetPosWidth(String title, String text) {
2211         Variant result = winVariant(title, text, "WinGetPosWidth");
2212         return result.getInt();
2213     }
2214 
2215     /**
2216      * Retrieves the position and size of a given window.
2217      * @param title The title of the window to read.
2218      * @return Returns the width of the window. Otherwise returns 1 and sets .error() = 1
2219      */
2220     public int winGetPosWidth(String title) {
2221         Variant result = winVariant(title, "WinGetPosWidth");
2222         return result.getInt();
2223     }
2224 
2225     /**
2226      * Retrieves the position and size of a given window.
2227      * @param title The title of the window to read.
2228      * @param text The text of the window to read.
2229      * @return Returns the height of the window. Otherwise returns 1 and sets .error() = 1
2230      */
2231     public int winGetPosHeight(String title, String text) {
2232         Variant result = winVariant(title, text, "WinGetPosHeight");
2233         return result.getInt();
2234     }
2235 
2236     /**
2237      * Retrieves the position and size of a given window.
2238      * @param title The title of the window to read.
2239      * @return Returns the height of the window. Otherwise returns 1 and sets .error() = 1
2240      */
2241     public int winGetPosHeight(String title) {
2242         Variant result = winVariant(title, "WinGetPosHeight");
2243         return result.getInt();
2244     }
2245 
2246     /**
2247      * Retrieves the Process ID (PID) associated with a window.
2248      * @param title The title of the window to read.
2249      * @param text The text of the window to read.
2250      * @return The PID, otherwise returns "".
2251      */
2252     public String winGetProcess(String title, String text) {
2253         Variant v = winVariant(title, text, "WinGetProcess");
2254         return v.getString();
2255     }
2256 
2257     /**
2258      * Retrieves the Process ID (PID) associated with a window.
2259      * @param title The title of the window to read.
2260      * @return The PID, otherwise returns "".
2261      */
2262     public String winGetProcess(String title) {
2263         Variant v = winVariant(title, "WinGetProcess");
2264         return v.getString();
2265     }
2266 
2267     /**
2268      * Retrieves the state of a given window.
2269      * @param title The title of the window to read.
2270      * @param text The text of the window to read.
2271      * @return  Returns a value indicating the state of the window. Multiple values are added together so use BitAND() to examine the part you are interested in:
2272      * 1 =  Window exists
2273      * 2 = Window is visible
2274      * 4 = Windows is enabled
2275      * 8 = Window is active
2276      * 16 = Window is minimized
2277      * otherwise returns 0 and sets oAutoIt.error to 1 if the window is not found.
2278      */
2279     public int winGetState(String title, String text) {
2280         Variant result = winVariant(title, text, "WinGetState");
2281         return result.getInt();
2282     }
2283 
2284     /**
2285      * Retrieves the state of a given window.
2286      * @param title The title of the window to read.
2287      * @return  Returns a value indicating the state of the window. Multiple values are added together so use BitAND() to examine the part you are interested in:
2288      * <br/> 1 =  Window exists
2289      * <br/> 2 = Window is visible
2290      * <br/> 4 = Windows is enabled
2291      * <br/> 8 = Window is active
2292      * <br/> 16 = Window is minimized
2293      * <br/> otherwise returns 0 and sets oAutoIt.error to 1 if the window is not found.
2294      */
2295     public int winGetState(String title) {
2296         Variant result = winVariant(title, "WinGetState");
2297         return result.getInt();
2298     }
2299 
2300     /**
2301      * Retrieves up to 64KB of text from a window.
2302      * <p>WinGetText works on minimized windows, but only works on hidden windows if you've set AutoItSetOption("WinDetectHiddenText", 1)
2303      * If multiple windows match the criteria for WinGetText, the information for the most recently active match is returned.
2304      * Use WinGetText("") to get the active window's text.</p>
2305      * @param title The title of the window to read.
2306      * @param text The text of the window to read.
2307      * @return Returns a string containing up to 64k of the window text read.
2308      */
2309     public String winGetText(String title, String text) {
2310         Variant result = winVariant(title, text, "WinGetText");
2311         return result.getString();
2312     }
2313 
2314     /**
2315      * Retrieves up to 64KB of text from a window.
2316      * <p>WinGetText works on minimized windows, but only works on hidden windows if you've set AutoItSetOption("WinDetectHiddenText", 1)
2317      * If multiple windows match the criteria for WinGetText, the information for the most recently active match is returned.
2318      * Use WinGetText("") to get the active window's text.</p>
2319      * @param title The title of the window to read.
2320      * @return Returns a string containing up to 64k of the window text read.
2321      */
2322     public String winGetText(String title) {
2323         Variant result = winVariant(title, "WinGetText");
2324         return result.getString();
2325     }
2326 
2327     /**
2328      * Retrieves the full title from a window.
2329      * @param title The title of the window to read.
2330      * @param text The text of the window to read.
2331      * @return  A string containing the complete window title. Otherwise "".
2332      */
2333     public String winGetTitle(String title, String text) {
2334         Variant result = winVariant(title, text, "WinGetTitle");
2335         if (result.getvt() == Variant.VariantString) {
2336             return result.getString();
2337         }
2338         return "";
2339     }
2340 
2341     /**
2342      * Retrieves the full title from a window.
2343      * @param title The title of the window to read.
2344      * @return  A string containing the complete window title. Otherwise "".
2345      */
2346     public String winGetTitle(String title) {
2347         Variant result = winVariant(title, "WinGetTitle");
2348         if (result.getvt() == Variant.VariantString) {
2349             return result.getString();
2350         }
2351         return "";
2352     }
2353 
2354     /**
2355      * Forces a window to close.
2356      * @param title The title of the window.
2357      * @param text The text of the window.
2358      */
2359     public void winKill(String title, String text) {
2360         winVariant(title, text, "WinKill");
2361     }
2362 
2363     /**
2364      * Forces a window to close.
2365      * @param title The title of the window.
2366      */
2367     public void winKill(String title) {
2368         winVariant(title, "WinKill");
2369     }
2370 
2371     /**
2372      * Retrieves a list of windows.
2373      * @param title The title of the window.
2374      * @param text The text of the window.
2375      * @return Returns a 2 dimensional array containing the window titles and corresponding handles.
2376      */
2377     public String[][] winList(String title, String text) {
2378         Variant result = winVariant(title, text, "WinList");
2379         SafeArray arr = result.toSafeArray();
2380         int entries = arr.getInt(0, 0);
2381         String[][] resultArr = new String[2][entries + 1];
2382         for (int i = 0; i <= entries; i++) {
2383             resultArr[0][i] = arr.getString(0, i);
2384             resultArr[1][i] = arr.getString(1, i);
2385         }
2386         return resultArr;
2387     }
2388 
2389     /**
2390      * Retrieves a list of windows.
2391      * @param title The title of the window.
2392      * @return Returns a 2 dimensional array containing the window titles and corresponding handles.
2393      */
2394     public String[][] winList(String title) {
2395         Variant result = winVariant(title, "WinList");
2396         SafeArray arr = result.toSafeArray();
2397         int entries = arr.getInt(0, 0);
2398         String[][] resultArr = new String[2][entries + 1];
2399         for (int i = 0; i <= entries; i++) {
2400             resultArr[0][i] = arr.getString(0, i);
2401             resultArr[1][i] = arr.getString(1, i);
2402         }
2403         return resultArr;
2404     }
2405 
2406     /**
2407      * Invokes a menu item of a window.
2408      * @param title The title of the window to read.
2409      * @param text The text of the window to read.
2410      * @param item Text of Menu Item
2411      * @return True if success, false otherwise.
2412      */
2413     public boolean winMenuSelectItem(String title, String text, String item) {
2414         Variant vTitle = new Variant(title);
2415         Variant vText = new Variant(text);
2416         Variant vItem = new Variant(item);
2417         Variant[] params = new Variant[]{vTitle, vText, vItem};
2418         Variant result = autoItX.invoke("WinMenuSelectItem", params);
2419         return oneToTrue(result.getInt());
2420     }
2421 
2422     /**
2423      * Invokes a menu item of a window.
2424      * @param title The title of the window to read.
2425      * @param text The text of the window to read.
2426      * @param item Text of Menu Item
2427      * @param item2 Text of Menu Item
2428      * @return True if success, false otherwise.
2429      */
2430     public boolean winMenuSelectItem(String title, String text, String item, String item2) {
2431         Variant vTitle = new Variant(title);
2432         Variant vText = new Variant(text);
2433         Variant vItem = new Variant(item);
2434         Variant vItem2 = new Variant(item2);
2435         Variant[] params = new Variant[]{vTitle, vText, vItem, vItem2};
2436         Variant result = autoItX.invoke("WinMenuSelectItem", params);
2437         return oneToTrue(result.getInt());
2438     }
2439 
2440     /**
2441      * Invokes a menu item of a window.
2442      * @param title The title of the window to read.
2443      * @param text The text of the window to read.
2444      * @param item Text of Menu Item
2445      * @param item2 Text of Menu Item
2446      * @param item3 Text of Menu Item
2447      * @return True if success, false otherwise.
2448      */
2449     public boolean winMenuSelectItem(String title, String text, String item, String item2, String item3) {
2450         Variant vTitle = new Variant(title);
2451         Variant vText = new Variant(text);
2452         Variant vItem = new Variant(item);
2453         Variant vItem2 = new Variant(item2);
2454         Variant vItem3 = new Variant(item3);
2455         Variant[] params = new Variant[]{vTitle, vText, vItem, vItem2, vItem3};
2456         Variant result = autoItX.invoke("WinMenuSelectItem", params);
2457         return oneToTrue(result.getInt());
2458     }
2459 
2460     /**
2461      * Invokes a menu item of a window.
2462      * @param title The title of the window to read.
2463      * @param text The text of the window to read.
2464      * @param item Text of Menu Item
2465      * @param item2 Text of Menu Item
2466      * @param item3 Text of Menu Item
2467      * @param item4 Text of Menu Item
2468      * @param item5 Text of Menu Item
2469      * @param item6 Text of Menu Item
2470      * @param item7 Text of Menu Item
2471      * @return True if success, false otherwise.
2472      */
2473     public boolean winMenuSelectItem(String title, String text, String item, String item2, String item3, String item4, String item5, String item6, String item7) {
2474         Variant vTitle = new Variant(title);
2475         Variant vText = new Variant(text);
2476         Variant vItem = new Variant(item);
2477         Variant vItem2 = new Variant(item2);
2478         Variant vItem3 = new Variant(item3);
2479         Variant vItem4 = new Variant(item4);
2480         Variant vItem5 = new Variant(item5);
2481         Variant vItem6 = new Variant(item6);
2482         Variant vItem7 = new Variant(item7);
2483         Variant[] params = new Variant[]{vTitle, vText, vItem, vItem2, vItem3, vItem4, vItem5, vItem6, vItem7};
2484         Variant result = autoItX.invoke("WinMenuSelectItem", params);
2485         return oneToTrue(result.getInt());
2486     }
2487 
2488     /**
2489      * Minimizes all windows.
2490      */
2491     public void winMinimizeAll() {
2492         autoItX.invoke("WinMinimizeAll");
2493     }
2494 
2495     /**
2496      * Undoes a previous WinMinimizeAll function.
2497      */
2498     public void winMinimizeAllUndo() {
2499         autoItX.invoke("WinMinimizeAllUndo");
2500     }
2501 
2502     /**
2503      * Moves and/or resizes a window.
2504      * @param title The title of the window to move/resize.
2505      * @param text The text of the window to move/resize.
2506      * @param x X coordinate to move to.
2507      * @param y Y coordinate to move to.
2508      * @param width New width of the window.
2509      * @param height New height of the window.
2510      */
2511     public void winMove(String title, String text, int x, int y, int width, int height) {
2512         Variant vTitle = new Variant(title);
2513         Variant vText = new Variant(text);
2514         Variant vX = new Variant(x);
2515         Variant vY = new Variant(y);
2516         Variant vWidth = new Variant(width);
2517         Variant vHeight = new Variant(height);
2518         Variant[] params = new Variant[]{vTitle, vText, vX, vY, vWidth, vHeight};
2519         autoItX.invoke("WinMove", params);
2520     }
2521 
2522     /**
2523      * Moves and/or resizes a window.
2524      * @param title The title of the window to move/resize.
2525      * @param text The text of the window to move/resize.
2526      * @param x X coordinate to move to.
2527      * @param y Y coordinate to move to.
2528      */
2529     public void winMove(String title, String text, int x, int y) {
2530         Variant vTitle = new Variant(title);
2531         Variant vText = new Variant(text);
2532         Variant vX = new Variant(x);
2533         Variant vY = new Variant(y);
2534         Variant[] params = new Variant[]{vTitle, vText, vX, vY};
2535         autoItX.invoke("WinMove", params);
2536     }
2537 
2538     /**
2539      * Change a window's "Always On Top" attribute.
2540      * @param title The title of the window to affect.
2541      * @param text The text of the window to affect.
2542      * @param isTopMost Determines whether the window should have the "TOPMOST" flag set.
2543      * true=set on top flag, false = remove on top flag
2544      */
2545     public void winSetOnTop(String title, String text, boolean isTopMost) {
2546         Variant vTitle = new Variant(title);
2547         Variant vText = new Variant(text);
2548         int flag = 0;
2549         if (isTopMost) {
2550             flag = 1;
2551         }
2552         Variant vFlag = new Variant(flag);
2553         Variant[] params = new Variant[]{vTitle, vText, vFlag};
2554         autoItX.invoke("WinSetOnTop", params);
2555     }
2556 
2557     /**
2558      * Shows, hides, minimizes, maximizes, or restores a window.
2559      * @param title The title of the window to affect.
2560      * @param text The text of the window to affect.
2561      * @param flag The "show" flag of the executed program:
2562      * <br/>SW_HIDE = Hide window,
2563      * <br/>SW_SHOW = Shows a previously hidden window,
2564      * <br/>SW_MINIMIZE = Minimize window,
2565      * <br/>SW_MAXIMIZE = Maximize window,
2566      * <br/>SW_RESTORE = Undoes a window minimization or maximization.
2567      */
2568     public void winSetState(String title, String text, int flag) {
2569         Variant vTitle = new Variant(title);
2570         Variant vText = new Variant(text);
2571         Variant vFlag = new Variant(flag);
2572         Variant[] params = new Variant[]{vTitle, vText, vFlag};
2573         autoItX.invoke("WinSetState", params);
2574     }
2575 
2576     /**
2577      * Changes the title of a window.
2578      * @param title The title of the window to affect.
2579      * @param text The text of the window to affect.
2580      * @param newtitle The new title to give to the window.
2581      */
2582     public void winSetTitle(String title, String text, String newtitle) {
2583         Variant vTitle = new Variant(title);
2584         Variant vText = new Variant(text);
2585         Variant vNewtitle = new Variant(newtitle);
2586         Variant[] params = new Variant[]{vTitle, vText, vNewtitle};
2587         autoItX.invoke("WinSetTitle", params);
2588     }
2589 
2590     /**
2591      * Sets the transparency of a window. (Windows 2000/XP or later)
2592      * @param title The title of the window to affect.
2593      * @param text The text of the window to affect.
2594      * @param transparency A number in the range 0 - 255. The larger the number, the more transparent the window will become.
2595      * @return True on success, false on failure. .error() will be set to 1 if the function isn't supported on an OS.
2596      */
2597     public boolean winSetTrans(String title, String text, int transparency) {
2598         Variant vTitle = new Variant(title);
2599         Variant vText = new Variant(text);
2600         Variant vTransparency = new Variant(transparency);
2601         Variant[] params = new Variant[]{vTitle, vText, vTransparency};
2602         Variant result = autoItX.invoke("WinSetTrans", params);
2603         int iResult = result.getInt();
2604         if (iResult != 0) {
2605             return true;
2606         }
2607         return false;
2608     }
2609 
2610     /**
2611      * Pauses execution of the script until the requested window exists.
2612      * The script polls for window match every 250 milliseconds or so.
2613      * @param title The title of the window to check.
2614      * @param text The text of the window to check.
2615      * @param timeout Timeout in seconds
2616      * @return True if success, false otherwise.
2617      */
2618     public boolean winWait(String title, String text, int timeout) {
2619         return winVariantBool(title, text, timeout, "WinWait");
2620     }
2621 
2622     /**
2623      * Pauses execution of the script until the requested window exists.
2624      * The script polls for window match every 250 milliseconds or so.
2625      * @param title The title of the window to check.
2626      * @return True if success, false otherwise.
2627      */
2628     public boolean winWait(String title) {
2629         return winVariantBool(title, "WinWait");
2630     }
2631 
2632     /**
2633      * Pauses execution of the script until the requested window exists.
2634      * The script polls for window match every 250 milliseconds or so.
2635      * @param title The title of the window to check.
2636      * @param text The text of the window to check.
2637      * @return True if success, false otherwise.
2638      */
2639     public boolean winWait(String title, String text) {
2640         return winVariantBool(title, text, "WinWait");
2641     }
2642 
2643     /**
2644      * Pauses execution of the script until the requested window is active.
2645      * @param title The title of the window to check.
2646      * @param text The text of the window to check.
2647      * @param timeout The timeout in seconds.
2648      * @return True if success, false otherwise.
2649      */
2650     public boolean winWaitActive(String title, String text, int timeout) {
2651         return winVariantBool(title, text, timeout, "WinWaitActive");
2652     }
2653 
2654     /**
2655      * Pauses execution of the script until the requested window is active.
2656      * @param title The title of the window to check.
2657      * @param text The text of the window to check.
2658      * @return True if success, false otherwise.
2659      */
2660     public boolean winWaitActive(String title, String text) {
2661         return winVariantBool(title, text, "WinWaitActive");
2662     }
2663 
2664     /**
2665      * Pauses execution of the script until the requested window is active.
2666      * @param title The title of the window to check.
2667      * @return True if success, false otherwise.
2668      */
2669     public boolean winWaitActive(String title) {
2670         return winVariantBool(title, "WinWaitActive");
2671     }
2672 
2673     /**
2674      * Pauses execution of the script until the requested window does not exist.
2675      * @param title The title of the window to check.
2676      * @param text The text of the window to check.
2677      * @param timeout The timeout in seconds.
2678      * @return True if success, false otherwise.
2679      */
2680     public boolean winWaitClose(String title, String text, int timeout) {
2681         return winVariantBool(title, text, timeout, "WinWaitClose");
2682     }
2683 
2684     /**
2685      * Pauses execution of the script until the requested window does not exist.
2686      * @param title The title of the window to check.
2687      * @return True if success, false otherwise.
2688      */
2689     public boolean winWaitClose(String title) {
2690         return winVariantBool(title, "WinWaitClose");
2691     }
2692 
2693     /**
2694      * Pauses execution of the script until the requested window does not exist.
2695      * @param title The title of the window to check.
2696      * @param text The text of the window to check.
2697      * @return True if success, false otherwise.
2698      */
2699     public boolean winWaitClose(String title, String text) {
2700         return winVariantBool(title, text, "WinWaitClose");
2701     }
2702 
2703     /**
2704      * Pauses execution of the script until the requested window is not active.
2705      * @param title The title of the window to check.
2706      * @param text The text of the window to check.
2707      * @param timeout The timeout in seconds.
2708      * @return True if success, false otherwise.
2709      */
2710     public boolean winWaitNoActive(String title, String text, int timeout) {
2711         return winVariantBool(title, text, timeout, "WinWaitNotActive");
2712     }
2713 
2714     /**
2715      * Pauses execution of the script until the requested window is not active.
2716 
2717 
2718 
2719      * @param title The title of the window to check.
2720      * @return True if success, false otherwise.
2721      */
2722     public boolean winWaitNoActive(String title) {
2723         return winVariantBool(title, "WinWaitNotActive");
2724     }
2725 
2726     /**
2727      * Pauses execution of the script until the requested window is not active.
2728      * @param title The title of the window to check.
2729      * @param text The text of the window to check.
2730      * @return True if success, false otherwise.
2731      */
2732     public boolean winWaitNoActive(String title, String text) {
2733         return winVariantBool(title, text, "WinWaitNotActive");
2734     }
2735 
2736     protected boolean winVariantBool(String title, String text, int timeout, String function) {
2737         Variant vTitle = new Variant(title);
2738         Variant vText = new Variant(text);
2739         Variant vTimeout = new Variant(timeout);
2740         Variant[] params = new Variant[]{vTitle, vText, vTimeout};
2741         Variant result = autoItX.invoke(function, params);
2742         return oneToTrue(result.getInt());
2743     }
2744 
2745     protected boolean winVariantBool(String title, String text, String function) {
2746         Variant vTitle = new Variant(title);
2747         Variant vText = new Variant(text);
2748         Variant[] params = new Variant[]{vTitle, vText};
2749         Variant result = autoItX.invoke(function, params);
2750         return oneToTrue(result.getInt());
2751     }
2752 
2753     protected boolean winVariantBool(String title, String function) {
2754         Variant vTitle = new Variant(title);
2755         Variant[] params = new Variant[]{vTitle};
2756         Variant result = autoItX.invoke(function, params);
2757         return oneToTrue(result.getInt());
2758     }
2759 
2760     /**
2761      * Retrieves the text from a standard status bar control.
2762      * @param title The title of the window to check.
2763      * @return  The text from a standard status bar control.
2764      */
2765     public String statusbarGetText(String title) {
2766         return autoItX.invoke("StatusbarGetText", title).getString();
2767     }
2768 
2769     /**
2770      * Converts the value 1 to true, anything else to false.
2771      * @param i The value to convert to true/false
2772      * @return 1 = true, anything else = false.
2773      */
2774     protected boolean oneToTrue(int i) {
2775         return (i == 1) ? true : false;
2776     }
2777 
2778     /**
2779      * Converts the value 1 to true, anything else to false.
2780      * @param i The value to convert to true/false
2781      * @return 1 = true, anything else = false.
2782      */
2783     protected boolean oneToTrue(Variant v) {
2784         if (v.getvt() == Variant.VariantInt
2785                 || v.getvt() == Variant.VariantShort) {
2786             return (v.getInt() == 1) ? true : false;
2787         }
2788         return false;
2789     }
2790 }
View Code

需要兩個文件才能使用Autoit提供的外部操作API.

一個是jacob文件,這個是java操作DCOM的一個橋梁API工具;

一個是AutoitX3.dll文件;

?

下載了上面的兩個文件,一個是在本地register所需要的autoit dll文件。

采用命令:regsvr32 autoitx3.dll 文件即可;

然后再java代碼中如下調(diào)用即可:

Selenium如何支持測試Windows application_sedSelenium如何支持測試Windows application_ide_02
    File file;
        try{
           file= new File("lib", "jacob-1.18-M1-x86.dll"); //path to the jacob dll
           logger.info("Using jacob dll x86 bit file to load the jacob now...");
        }catch(UnsatisfiedLinkError error){
            logger.info("the java VM is x86 so we change to load the jacob dll with x64 bit:"+error.getMessage());
            file= new File("lib", "jacob-1.18-M1-x64.dll"); //path to the jacob dll
        }
        logger.info("Get the jacob dll file path is:"+file.getAbsolutePath());
        System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
View Code

,之后你就能在你的java程序中調(diào)用Autoit的API即可。

如下:

AutoItXUtils autoit=getAutoItX();   //得到Autoit的實體類
        autoit.winWait(title, text, 120);   //激活一個windows窗口,只需要指定窗口的標(biāo)題和對應(yīng)的可見文本,這里會等待窗口出現(xiàn),如果在120秒內(nèi)還是沒有出現(xiàn)就返回false
        autoit.winActivate(title, text);  //激活窗口
        boolean clicked=autoit.controlClick(title, text, controlID); //點擊一個控件,需要指定這個控件的windows id,還有控件所對應(yīng)的title及其可見的text

是不是很不錯,可以的話,你可以嘗試下去操作弄弄。

不過使用了AutoIt的話,你就不能使用Selenium的RemoteWebDriver的特性了,也就是分布式執(zhí)行的相關(guān)操作了,因為所有的Autoit的腳本其實都是運行在本地的,所以如果你需要讓Selenium繼續(xù)可以在不同的機器上運行,你可能需要使用Jenkins操作了。


作者:高級測試開發(fā)網(wǎng)
本文版權(quán)歸作者所有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。



?
?
?
?

本文摘自 :https://blog.51cto.com/u

開通會員,享受整站包年服務(wù)立即開通 >