-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathAutoItX.java
More file actions
2990 lines (2729 loc) · 119 KB
/
AutoItX.java
File metadata and controls
2990 lines (2729 loc) · 119 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2011 Richard Kanavati
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package autoitx4java;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.SafeArray;
import com.jacob.com.Variant;
/**
* A Java AutoItX3 Bridge.
* @author Richard Kanavati
*/
public class AutoItX {
/**
* The AutoItX Component.
*/
protected ActiveXComponent autoItX;
/**
* Maximizes the specified window.
*/
public final static int SW_MAXIMIZE = 3;
/**
* Minimizes the specified window and activates the next top-level window
* in the Z order.
*/
public final static int SW_HIDE = 0;
/**
* 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.
*/
public final static int SW_RESTORE = 9;
/**
* Activates the window and displays it in its current size and position.
*/
public final static int SW_SHOW = 5;
/**
* Sets the show state based on the SW_ value specified by the program
* that started the application.
*/
public final static int SW_SHOWDEFAULT = 10;
/**
* Activates the window and displays it as a maximized window.
*/
public final static int SW_SHOWMAXIMIZED = 3;
/**
* Activates the window and displays it as a minimized window.
*/
public final static int SW_SHOWMINIMIZED = 2;
/**
* Displays the window as a minimized window. This value is similar to
* SW_SHOWMINIMIZED, except the window is not activated.
*/
public final static int SW_SHOWMINNOACTIVE = 7;
/**
* Displays the window in its current size and position. This value is
* similar to SW_SHOW, except the window is not activated.
*/
public final static int SW_SHOWNA = 8;
/**
* Displays a window in its most recent size and position. This value is
* similar to SW_SHOWNORMAL, except the window is not actived.
*/
public final static int SW_SHOWNOACTIVATE = 4;
/**
* 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.
*/
public final static int SW_SHOWNORMAL = 1;
/**
* Sets the way coords are used in the caret functions, either absolute
* coords or coords relative to the current active window:
* <br/>0 = relative coords to the active window,
* <br/>1 = absolute screen coordinates (default),
* <br/>2 = relative coords to the client area of the active window.
*/
public final static String OPT_CARET_COORD_MODE = "CaretCoordMode";
/**
* Alters the length of the brief pause in between mouse clicks.
* Time in milliseconds to pause (default=10).
*/
public final static String OPT_MOUSE_CLICK_DELAY = "MouseClickDelay";
/**
* Alters the length of the brief pause in between mouse clicks.
* Time in milliseconds to pause (default=10).
*/
public final static String OPT_MOUSE_CLICK_DOWN_DELAY = "MouseClickDownDelay";
/**
* Alters the length of the brief pause at the start and end of a mouse
* drag operation. Time in milliseconds to pause (default=250).
*/
public final static String OPT_MOUSE_CLICK_DRAG_DELAY = "MouseClickDragDelay";
/**
* Sets the way coords are used in the mouse functions, either absolute
* coords or coords relative to the current active window:
* <br/>0 = relative coords to the active window
* <br/>1 = absolute screen coordinates (default)
* <br/>2 = relative coords to the client area of the active window
*/
public final static String OPT_MOUSE_COORD_MODE = "MouseCoordMode";
/**
* Sets the way coords are used in the mouse functions, either absolute
* coords or coords relative to the current active window:
* <br/>0 = relative coords to the active window
* <br/>1 = absolute screen coordinates (default)
* <br/>2 = relative coords to the client area of the active window
*/
public final static String OPT_PIXEL_COORD_MODE = "PixelCoordMode";
/**
* Sets the way coords are used in the pixel functions, either absolute
* coords or coords relative to the current active window:
* <br/>0 = relative coords to the active window
* <br/>1 = absolute screen coordinates (default)
* <br/>2 = relative coords to the client area of the active window
*/
public final static String OPT_SEND_ATTACH_MODE = "SendAttachMode";
/**
* 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.
* <br/>0 = don't attach (default)
* <br/>1 = attach
*/
public final static String OPT_SEND_CAPSLOCK_MODE = "SendCapslockMode";
/**
* Specifies if AutoIt should store the state of capslock before a
* Send function and restore it afterwards.
* <br/>0 = don't store/restore
* <br/>1 = store and restore (default)
*/
public final static String OPT_SEND_KEY_DELAY = "SendKeyDelay";
/**
* 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.
* Time in milliseconds to pause (default=1).
*/
public final static String OPT_SEND_KEY_DOWN_DELAY = "SendKeyDownDelay";
/**
* Specifies if hidden window text can be "seen" by the window matching functions.
* <br/>0 = Do not detect hidden text (default)
* <br/>1 = Detect hidden text
*/
public final static String OPT_WIN_DETECT_HIDDEN_TEXT = "WinDetectHiddenText";
/**
* Allows the window search routines to search child windows as well as top-level windows.
* <br/>0 = Only search top-level windows (default)
* <br/>1 = Search top-level and child windows
*/
public final static String OPT_WIN_SEARCH_CHILDREN = "WinSearchChildren";
/**
* Alters the method that is used to match window text during search operations.
* <br/>1 = Complete / Slow mode (default)
* <br/>2 = Quick mode
* 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).
* If you are having performance problems when performing many window
* searches then changing to the "quick" mode may help.
*/
public final static String OPT_WIN_TEXT_MATCH_MODE = "WinTextMatchMode";
/**
* Alters the method that is used to match window titles during search operations.
* <br/>1 = Match the title from the start (default)
* <br/>2 = Match any substring in the title
* <br/>3 = Exact title match
* <br/>4 = Advanced mode, see Window Titles & Text (Advanced)
*/
public final static String OPT_WIN_TITLE_MATCH_MODE = "WinTitleMatchMode";
/**
* Alters how long a script should briefly pause after a successful window-related operation.
* Time in milliseconds to pause (default=250).
*/
public final static String OPT_WIN_WAIT_DELAY = "WinWaitDelay";
/**
* Initializes the AutoItX Jacob COM object.
*/
public AutoItX() {
autoItX = new ActiveXComponent("AutoItX3.Control");
}
/**
* The AutoItX version.
* @return The AutoItX version.
*/
public String getVersion() {
return autoItX.getProperty("version").getString();
}
/**
* Value of the error flag.
* @return The value of the error flag.
*/
public int getError() {
Variant error = autoItX.invoke("error");
return error.getInt();
}
/**
* Retrieves text from the clipboard.
* @return A string containing the text on the clipboard. Sets error to 1
* if clipboard is empty or contains a non-text entry.
*/
public String clipGet() {
return autoItX.invoke("ClipGet").getString();
}
/**
* Writes text to the clipboard.
* @param value The text to write to the clipboard.
*/
public void clipPut(String value) {
autoItX.invoke("ClipPut", new Variant(value));
}
/**
* Maps a network drive.
* <p><b>Doesn't always work</b></p>
* @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.
* @param remote The remote share to connect to in the form "\\server\share".
* @return True if success, false otherwise
*/
public boolean driveMapAdd(String device, String remote) {
return driveMapAdd(device, remote, 0, "", "");
}
/**
* Maps a network drive.
* @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.
* @param remote The remote share to connect to in the form "\\server\share".
* @param flags A combination of the following: 0 = default,
* 1 = Persistent mapping,
* 8 = Show authentication dialog if required
* @param username The username
* @param password The password
* @return True if success, false otherwise
*/
public boolean driveMapAdd(String device, String remote, int flags, String username, String password) {
Variant vDevice = new Variant(device);
Variant vRemote = new Variant(remote);
Variant vFlags = new Variant(flags);
Variant vUsername = new Variant(username);
Variant vPassword = new Variant(password);
Variant[] params = new Variant[]{vDevice, vRemote, vFlags, vUsername, vPassword};
Variant result = autoItX.invoke("DriveMapAdd", params);
if (result.getvt() == Variant.VariantString) {
return oneToTrue(Integer.parseInt(result.getString()));
}
return oneToTrue(result.getInt());
}
/**
* Maps a network drive.
* @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.
* @param remote The remote share to connect to in the form "\\server\share".
* @param flags A combination of the following:0 = default,
* 1 = Persistent mapping, 8 = Show authentication dialog if required
* @return True if success, false otherwise
*/
public boolean driveMapAdd(String device, String remote, int flags) {
Variant vDevice = new Variant(device);
Variant vRemote = new Variant(remote);
Variant vFlags = new Variant(flags);
Variant[] params = new Variant[]{vDevice, vRemote, vFlags};
Variant result = autoItX.invoke("DriveMapAdd", params);
if (result.getvt() == Variant.VariantString) {
return oneToTrue(Integer.parseInt(result.getString()));
}
return oneToTrue(result.getInt());
}
/**
* Disconnects a network drive.
* @param device The device to disconnect, e.g. "O:" or "LPT1:".
* @return True if success, false otherwise
*/
public boolean driveMapDelete(String device) {
Variant result = autoItX.invoke("DriveMapDel", device);
return oneToTrue(result);
}
/**
* The device (drive or printer) letter to query. Eg. "O:" or "LPT1:"
* @param device The device to disconnect, e.g. "O:" or "LPT1:".
* @return Details of the mapping, e.g. \\server\share. If blank, sets .error() to 1.
*/
public String driveMapGet(String device) {
Variant result = autoItX.invoke("DriveMapGet", device);
return result.getString();
}
/**
* Deletes a value from a standard format .ini file.
* @param filename The filename of the .ini file.
* @param section The section name in the .ini file.
* @param key The key name in the in the .ini file.
* If no key name is given the entire section is deleted.
* @return True if success, false otherwise
*/
public boolean iniDelete(String filename, String section, String key) {
Variant vFilename = new Variant(filename);
Variant vSection = new Variant(section);
Variant vKey = new Variant(key);
Variant[] params = new Variant[]{vFilename, vSection, vKey};
Variant result = autoItX.invoke("IniDelete", params);
return oneToTrue(result);
}
/**
* Deletes a value from a standard format .ini file.
* @param filename The filename of the .ini file.
* @param section The section name in the .ini file.
* @return True if success, false otherwise
*/
public boolean iniDelete(String filename, String section) {
return iniDelete(filename, section, "");
}
/**
* Reads a value from a standard format .ini file.
* @param filename The filename of the .ini file.
* @param section The section name in the .ini file.
* @param key The key name in the in the .ini file.
* @param defaultVal The default value to return if the requested key is not found.
* @return The requested key value if found, otherwise the default value.
*/
public String iniRead(String filename, String section, String key, String defaultVal) {
Variant vFilename = new Variant(filename);
Variant vSection = new Variant(section);
Variant vKey = new Variant(key);
Variant vDefault = new Variant(defaultVal);
Variant[] params = new Variant[]{vFilename, vSection, vKey, vDefault};
Variant result = autoItX.invoke("IniRead", params);
return result.getString();
}
/**
* Writes a value to a standard format .ini file.
* @param filename The filename of the .ini file.
* @param section The section name in the .ini file.
* @param key The key name in the in the .ini file.
* @param value The value to write/change.
* @return True if success, false otherwise.
*/
public Boolean iniWrite(String filename, String section, String key, String value) {
Variant vFilename = new Variant(filename);
Variant vSection = new Variant(section);
Variant vKey = new Variant(key);
Variant vValue = new Variant(value);
Variant[] params = new Variant[]{vFilename, vSection, vKey, vValue};
Variant result = autoItX.invoke("IniWrite", params);
return oneToTrue(result);
}
/**
* Generates a checksum for a region of pixels.
* @param left Left coordinate of rectangle.
* @param top Top coordinate of rectangle.
* @param right Right coordinate of rectangle.
* @param bottom Bottom coordinate of rectangle.
* @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.
* @return The checksum value of the region.
*/
public double pixelChecksum(int left, int top, int right, int bottom, int step) {
Variant vLeft = new Variant(left);
Variant vTop = new Variant(top);
Variant vRight = new Variant(right);
Variant vBottom = new Variant(bottom);
Variant vStep = new Variant(step);
Variant[] params = new Variant[]{vLeft, vTop, vRight, vBottom, vStep};
Variant result = autoItX.invoke("PixelChecksum", params);
return result.getDouble();
}
/**
* Generates a checksum for a region of pixels.
* @param left Left coordinate of rectangle.
* @param top Top coordinate of rectangle.
* @param right Right coordinate of rectangle.
* @param bottom Bottom coordinate of rectangle.
* @return The checksum value of the region.
*/
public double pixelChecksum(int left, int top, int right, int bottom) {
return pixelChecksum(left, top, right, bottom, 0);
}
/**
* Returns a pixel color according to x,y pixel coordinates.
* @param x x coordinate of pixel.
* @param y y coordinate of pixel.
* @return Decimal value of pixel's color.
*/
public float pixelGetColor(int x, int y) {
Variant vX = new Variant(x);
Variant vY = new Variant(y);
Variant[] params = new Variant[]{vX, vY};
Variant result = autoItX.invoke("PixelGetColor", params);
return result.getInt();
}
/**
* Searches a rectangle of pixels for the pixel color provided.
* @param left left coordinate of rectangle.
* @param top top coordinate of rectangle.
* @param right right coordinate of rectangle.
* @param bottom bottom coordinate of rectangle.
* @param color Color value of pixel to find (in decimal or hex).
* @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).
* @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.
* @return The pixel's coordinates in a 2 element array, otherwise sets
* .error() to one.
*/
public long[] pixelSearch(int left, int top, int right, int bottom,
int color, int shadeVariation, int step) {
Variant vLeft = new Variant(left);
Variant vTop = new Variant(top);
Variant vRight = new Variant(right);
Variant vBottom = new Variant(bottom);
Variant vColor = new Variant(color);
Variant vShadeVariation = new Variant(shadeVariation);
Variant vStep = new Variant(step);
Variant[] params = new Variant[]{vLeft, vTop, vRight, vBottom, vColor, vShadeVariation, vStep};
Variant result = autoItX.invoke("PixelSearch", params);
long[] l = new long[2];
if (result.getvt() == 8204) {
l[0] = result.toSafeArray().getLong(0);
l[1] = result.toSafeArray().getLong(1);
}
return l;
}
/**
* Searches a rectangle of pixels for the pixel color provided.
* @param left left coordinate of rectangle.
* @param top top coordinate of rectangle.
* @param right right coordinate of rectangle.
* @param bottom bottom coordinate of rectangle.
* @param color Color value of pixel to find (in decimal or hex).
* @return The pixel's coordinates in a 2 element array, otherwise
* sets .error() to one.
*/
public long[] pixelSearch(int left, int top, int right, int bottom, int color) {
return pixelSearch(left, top, right, bottom, color, 0, 1);
}
/**
* Sends simulated keystrokes to the active window.
* @param keys The sequence of keys to send.
* @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.
*/
public void send(String keys, boolean isRaw) {
Variant vKeys = new Variant(keys);
Variant vFlag = new Variant(isRaw ? 1 : 0);
Variant[] params = new Variant[]{vKeys, vFlag};
autoItX.invoke("Send", params);
}
/**
* Sends simulated keystrokes to the active window.
* @param keys The sequence of keys to send.
*/
public void send(String keys) {
send(keys, true);
}
/**
* Creates a tooltip anywhere on the screen.
* @param text The text of the tooltip. (An empty string clears a displaying tooltip)
* @param x The x,y position of the tooltip.
* @param y The x,y position of the tooltip.
*/
public void toolTip(String text, int x, int y) {
Variant vText = new Variant(text);
Variant vX = new Variant(x);
Variant vY = new Variant(y);
Variant[] params = new Variant[]{vText, vX, vY};
autoItX.invoke("ToolTip", params);
}
/**
* Creates a tooltip anywhere on the screen.
* @param text The text of the tooltip. (An empty string clears a displaying tooltip)
*/
public void toolTip(String text) {
autoItX.invoke("ToolTip", text);
}
/**
* Disable/enable the mouse and keyboard.
* Requires admin rights in Vista and Windows 7.
* @param disableInput True = disable user input, false = re-enable it.
*/
public void blockInput(boolean disableInput) {
autoItX.invoke("BlockInput", (disableInput ? 1 : 0));
}
/**
* Opens or closes the CD tray.
* @param drive The drive letter of the CD tray to control, in the format D:, E:, etc.
* @param status Specifies if you want the CD tray to be open or closed: "open" or "closed"
* @return True if success, false if drive is locked via CD burning
* software or if the drive letter is not a CD drive.
*/
public boolean cdTray(String drive, String status) {
Variant vDrive = new Variant(drive);
Variant vStatus = new Variant(status);
Variant[] params = new Variant[]{vDrive, vStatus};
Variant result = autoItX.invoke("CDTray", params);
return oneToTrue(result);
}
/**
* Checks if the current user has administrator privileges.
* @return True if is admin, false otherwise.
*/
public boolean isAdmin() {
return oneToTrue(autoItX.invoke("IsAdmin"));
}
/**
* Changes the operation of various AutoIt functions/parameters.
* @param option The option to change.
* @param param The parameter (varies by option).
* @return Value of the previous setting.
*/
public String autoItSetOption(String option, String param) {
Variant vOption = new Variant(option);
Variant vParam = new Variant(param);
Variant[] params = new Variant[]{vOption, vParam};
Variant result = autoItX.invoke("AutoItSetOption", params);
if (result.getvt() == Variant.VariantInt) {
return String.valueOf(result.getInt());
}
return result.getString();
}
/**
* Changes the operation of various AutoIt functions/parameters.
* @param option The option to change.
* @param param The parameter (varies by option).
* @return Value of the previous setting.
*/
public String setOption(String option, String param) {
return autoItSetOption(option, param);
}
/**
* Perform a mouse click operation.
* @param button The button to click: "left", "right", "middle", "main",
* "menu", "primary", "secondary".
* @param x The x/y coordinates to move the mouse to.
* If no x and y coords are given, the current position is used.
* @param y The x/y coordinates to move the mouse to.
* If no x and y coords are given, the current position is used.
* @param clicks The number of times to click the mouse. Default is 1.
* @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.
*/
public void mouseClick(String button, int x, int y, int clicks, int speed) {
Variant vButton = new Variant(button);
Variant vX = new Variant(x);
Variant vY = new Variant(y);
Variant vClicks = new Variant(clicks);
Variant vSpeed = new Variant(speed);
Variant[] params = new Variant[]{vButton, vX, vY, vClicks, vSpeed};
autoItX.invoke("MouseClick", params);
}
/**
* Perform a mouse click operation.
* @param button The button to click: "left", "right", "middle", "main",
* "menu", "primary", "secondary".
* @param clicks The number of times to click the mouse. Default is 1.
* @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.
*/
public void mouseClick(String button, int clicks, int speed) {
Variant vButton = new Variant(button);
Variant vClicks = new Variant(clicks);
Variant vSpeed = new Variant(speed);
Variant[] params = new Variant[]{vButton, vClicks, vSpeed};
autoItX.invoke("MouseClick", params);
}
/**
* Perform a mouse click and drag operation.
* @param button The button to click: "left", "right", "middle",
* "main", "menu", "primary", "secondary".
* @param x The x/y coords to start the drag operation from.
* @param y The x/y coords to start the drag operation from.
* @param x2 The x/y coords to start the drag operation to.
* @param y2 The x/y coords to start the drag operation to.
* @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.
*/
public void mouseClickDrag(String button, int x, int y, int x2, int y2, int speed) {
Variant vButton = new Variant(button);
Variant vX = new Variant(x);
Variant vY = new Variant(y);
Variant vX2 = new Variant(x2);
Variant vY2 = new Variant(y2);
Variant vSpeed = new Variant(speed);
Variant[] params = new Variant[]{vButton, vX, vY, vX2, vY2, vSpeed};
autoItX.invoke("MouseClickDrag", params);
}
/**
* Perform a mouse click and drag operation.
* @param button The button to click: "left", "right", "middle", "main",
* "menu", "primary", "secondary".
* @param x The x/y coords to start the drag operation from.
* @param y The x/y coords to start the drag operation from.
* @param x2 The x/y coords to start the drag operation to.
* @param y2 The x/y coords to start the drag operation to.
*/
public void mouseClickDrag(String button, int x, int y, int x2, int y2) {
mouseClickDrag(button, x, y, x2, y2, 10);
}
/**
* Perform a mouse down event at the current mouse position.
* @param button The button to click: "left", "right", "middle", "main",
* "menu", "primary", "secondary".
*/
public void mouseDown(String button) {
autoItX.invoke("MouseDown", button);
}
/**
* Returns a cursor ID Number of the current Mouse Cursor.
* @return 0 = UNKNOWN (this includes pointing and grabbing hand icons)
* <br/> 1 = APPSTARTING
* <br/> 2 = ARROW
* <br/> 3 = CROSS
* <br/> 4 = HELP
* <br/> 5 = IBEAM
* <br/> 6 = ICON
* <br/> 7 = NO
* <br/> 8 = SIZE
* <br/> 9 = SIZEALL
* <br/> 10 = SIZENESW
* <br/> 11 = SIZENS
* <br/> 12 = SIZENWSE
* <br/> 13 = SIZEWE
* <br/> 14 = UPARROW
* <br/> 15 = WAIT
*/
public int mouseGetCursor() {
return autoItX.invoke("MouseGetCursor").getInt();
}
/**
* Retrieves the current X position of the mouse cursor.
* @return The current X position of the mouse cursor.
*/
public int mouseGetPosX() {
return autoItX.invoke("MouseGetPosX").getInt();
}
/**
* Retrieves the current Y position of the mouse cursor.
* @return The current Y position of the mouse cursor.
*/
public int mouseGetPosY() {
return autoItX.invoke("MouseGetPosY").getInt();
}
/**
* Moves the mouse pointer.
* @param x The screen x coordinate to move the mouse to.
* @param y The screen y coordinate to move the mouse to.
* @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.
* @return true if success, false otherwise (is this correct)?
*/
public boolean mouseMove(int x, int y, int speed) {
Variant vX = new Variant(x);
Variant vY = new Variant(y);
Variant vSpeed = new Variant(speed);
Variant[] params = new Variant[]{vX, vY, vSpeed};
return oneToTrue(autoItX.invoke("MouseMove", params).getInt());
}
/**
* Moves the mouse pointer.
* @param x The screen x coordinate to move the mouse to.
* @param y The screen y coordinate to move the mouse to.
* @return true if success, false otherwise (is this correct)?
*/
public boolean mouseMove(int x, int y) {
return mouseMove(x, y, 10);
}
/**
* Perform a mouse up event at the current mouse position.
* @param button The button to click: "left", "right", "middle", "main",
* "menu", "primary", "secondary".
*/
public void mouseUp(String button) {
autoItX.invoke("MouseUp", button);
}
/**
* Moves the mouse wheel up or down. NT/2000/XP ONLY.
* @param direction "up" or "down"
* @param clicks The number of times to move the wheel. Default is 1.
*/
public void mouseWheel(String direction, int clicks) {
Variant vDirection = new Variant(direction);
Variant vClicks = new Variant(clicks);
Variant[] params = new Variant[]{vDirection, vClicks};
autoItX.invoke("MouseWheel", params);
}
/**
* Moves the mouse wheel up or down. NT/2000/XP ONLY.
* @param direction "up" or "down"
*/
public void mouseWheel(String direction) {
mouseWheel(direction, 1);
}
/**
* Terminates a named process.
* @param process The title or PID of the process to terminate.
*/
public void processClose(String process) {
autoItX.invoke("ProcessClose", process);
}
/**
* Checks to see if a specified process exists.
* @param process The name or PID of the process to check.
* @return The PID of the process. 0 if process does not exist.
*/
public int processExists(String process) {
return autoItX.invoke("ProcessExists", process).getInt();
}
/**
* Changes the priority of a process
* @param process The name or PID of the process to check.
* @param priority A flag which determines what priority to set
* <br/> 0 - Idle/Low
* <br/> 1 - Below Normal (Not supported on Windows 95/98/ME)
* <br/> 2 - Normal
* <br/> 3 - Above Normal (Not supported on Windows 95/98/ME)
* <br/> 4 - High
* <br/> 5 - Realtime (Use with caution, may make the system unstable)
* @return True if success, false otherwise.
*/
public boolean processSetPriority(String process, int priority) {
Variant vProcess = new Variant(process);
Variant vPriority = new Variant(priority);
Variant[] params = new Variant[]{vProcess, vPriority};
Variant result = autoItX.invoke("ProcessSetPriority", params);
return oneToTrue(result.getInt());
}
/**
* Pauses script execution until a given process exists.
* @param process The name of the process to check.
* @param timeout Specifies how long to wait (default is to wait indefinitely).
* @return True if success, false otherwise.
*/
public boolean processWait(String process, int timeout) {
Variant vProcess = new Variant(process);
Variant vTimeout = new Variant(timeout);
Variant[] params = new Variant[]{vProcess, vTimeout};
Variant result = autoItX.invoke("ProcessWait", params);
return oneToTrue(result.getInt());
}
/**
* Pauses script execution until a given process exists.
* @param process The name of the process to check.
* @return True if success, false otherwise.
*/
public boolean processWait(String process) {
Variant result = autoItX.invoke("ProcessWait", process);
return oneToTrue(result.getInt());
}
/**
* Pauses script execution until a given process exists.
* @param process The name of the process to check.
* @param timeout Specifies how long to wait (default is to wait indefinitely).
* @return True if success, false otherwise.
*/
public boolean processWaitClose(String process, int timeout) {
Variant vProcess = new Variant(process);
Variant vTimeout = new Variant(timeout);
Variant[] params = new Variant[]{vProcess, vTimeout};
Variant result = autoItX.invoke("ProcessWaitClose", params);
return oneToTrue(result.getInt());
}
/**
* Pauses script execution until a given process exists.
* @param process The name of the process to check.
* @return True if success, false otherwise.
*/
public boolean processWaitClose(String process) {
Variant result = autoItX.invoke("ProcessWaitClose", process);
return oneToTrue(result.getInt());
}
/**
* Runs an external program.
* @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
* @param workingDirectory The working directory.
* @param flag The "show" flag of the executed program:
* <br/>SW_HIDE = Hidden window
* <br/>SW_MINIMIZE = Minimized window
* <br/>SW_MAXIMIZE = Maximized window
* @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.
* The error property is set to 1 as an indication of failure.
*/
public int run(String filename, String workingDirectory, int flag) {
Variant vFilename = new Variant(filename);
Variant vWorkingDirectory = new Variant(workingDirectory);
Variant vFlag = new Variant(flag);
Variant[] params = new Variant[]{vFilename, vWorkingDirectory, vFlag};
return autoItX.invoke("Run", params).getInt();
}
/**
* Runs an external program.
* @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
* @param workingDirectory The working directory.
* @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.
* The error property is set to 1 as an indication of failure.
*/
public int run(String filename, String workingDirectory) {
Variant vFilename = new Variant(filename);
Variant vWorkingDirectory = new Variant(workingDirectory);
Variant[] params = new Variant[]{vFilename, vWorkingDirectory};
return autoItX.invoke("Run", params).getInt();
}
/**
* Runs an external program.
* @param filename The name of the executable (EXE, BAT, COM, or PIF) to run.
* @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.
* The error property is set to 1 as an indication of failure.
*/
public int run(String filename) {
return autoItX.invoke("Run", filename).getInt();
}
/**
* Initialize a set of user credentials to use during Run and RunWait
* operations. 2000/XP or later ONLY.
* @param username The user name to use.
* @param domain The domain name to use.
* @param password The password to use.
* @param options 0 = do not load the user profile, 1 = (default) load the
* user profile, 2 = use for net credentials only
* @return Returns 0 if the operating system does not support this function.
* Otherwise returns 1--regardless of success. (If the login information was
* invalid, subsequent Run/RunWait commands will fail....)
*/
public int runAsSet(String username, String domain, String password, int options) {
Variant vUsername = new Variant(username);
Variant vDomain = new Variant(domain);
Variant vPassword = new Variant(password);
Variant vOptions = new Variant(options);
Variant[] params = new Variant[]{vUsername, vDomain, vPassword, vOptions};
return autoItX.invoke("RunAsSet", params).getInt();
}
/**
* Initialize a set of user credentials to use during Run and RunWait
* operations. 2000/XP or later ONLY.
* @param username The user name to use.
* @param domain The domain name to use.
* @param password The password to use.
* @return Returns 0 if the operating system does not support this function.
* Otherwise returns 1--regardless of success. (If the login information was
* invalid, subsequent Run/RunWait commands will fail....)
*/
public int runAsSet(String username, String domain, String password) {
return runAsSet(username, domain, password, 1);
}
/**
* Runs an external program and pauses script execution until the program finishes.
* @param filename The name of the executable (EXE, BAT, COM, PIF) to run.
* @param workingDirectory The working directory.
* @param flag The "show" flag of the executed program:
* <br/> SW_HIDE = Hidden window
* <br/> SW_MINIMIZE = Minimized window
* <br/> SW_MAXIMIZE = Maximized window
* @return Returns the exit code of the program that was run.
* The error property is set to 1 as an indication of failure.
*/
public int runWait(String filename, String workingDirectory, int flag) {
Variant vFilename = new Variant(filename);
Variant vWorkingDirectory = new Variant(workingDirectory);
Variant vFlag = new Variant(flag);
Variant[] params = new Variant[]{vFilename, vWorkingDirectory, vFlag};
return autoItX.invoke("RunWait", params).getInt();
}
/**
* Runs an external program and pauses script execution until the program finishes.
* @param filename The name of the executable (EXE, BAT, COM, PIF) to run.
* @param workingDirectory The working directory.
* @return Returns the exit code of the program that was run.
* The error property is set to 1 as an indication of failure.
*/
public int runWait(String filename, String workingDirectory) {
Variant vFilename = new Variant(filename);
Variant vWorkingDirectory = new Variant(workingDirectory);
Variant[] params = new Variant[]{vFilename, vWorkingDirectory};
return autoItX.invoke("RunWait", params).getInt();
}