-
Notifications
You must be signed in to change notification settings - Fork 71
/
class_UIAutomation.ahk
1992 lines (1612 loc) · 119 KB
/
class_UIAutomation.ahk
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
/************************************************************************
* @description UI Automation class wrapper, based on https://github.com/neptercn/UIAutomation/blob/master/UIA2.ahk
* @file UIAutomation.ahk
* @author thqby, neptercn(v1 version)
* @date 2021/10/21
* @version 1.0.12
***********************************************************************/
#Include <BSTR>
#Include <ComVar>
; NativeArray is C style array, zero-based index, it has `__Item` and `__Enum` property
class NativeArray {
__New(ptr, count, type := "ptr") {
static _ := DllCall("LoadLibrary", "str", "ole32.dll")
static bits := { UInt: 4, UInt64: 8, Int: 4, Int64: 8, Short: 2, UShort: 2, Char: 1, UChar: 1, Double: 8, Float: 4, Ptr: A_PtrSize, UPtr: A_PtrSize }
this.size := (this.count := count) * (bit := bits.%type%), this.ptr := ptr || DllCall("ole32\CoTaskMemAlloc", "uint", this.size, "ptr")
this.DefineProp("__Item", { get: (s, i) => NumGet(s, i * bit, type) })
this.DefineProp("__Enum", { call: (s, i) => (i = 1 ?
(i := 0, (&v) => i < count ? (v := NumGet(s, i * bit, type), ++i) : false) :
(i := 0, (&k, &v) => (i < count ? (k := i, v := NumGet(s, i * bit, type), ++i) : false))
) })
}
__Delete() => DllCall("ole32\CoTaskMemFree", "ptr", this)
}
class IUIABase {
__New(ptr) {
if !(this.ptr := ptr)
throw ValueError('Invalid IUnknown interface pointer', -2, this.__Class)
}
__Delete() => this.Release()
__Item => (ObjAddRef(this.ptr), ComValue(0xd, this.ptr))
AddRef() => ObjAddRef(this.ptr)
Release() => this.ptr ? ObjRelease(this.ptr) : 0
}
class UIA {
static ptr := ComObjValue(this.__ := ComObject("{ff48dba4-60ef-4201-aa87-54103eef594e}", "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}"))
static ControlType := { Button: 50000, Calendar: 50001, CheckBox: 50002, ComboBox: 50003, Edit: 50004, Hyperlink: 50005, Image: 50006, ListItem: 50007, List: 50008, Menu: 50009, MenuBar: 50010, MenuItem: 50011, ProgressBar: 50012, RadioButton: 50013, ScrollBar: 50014, Slider: 50015, Spinner: 50016, StatusBar: 50017, Tab: 50018, TabItem: 50019, Text: 50020, ToolBar: 50021, ToolTip: 50022, Tree: 50023, TreeItem: 50024, Custom: 50025, Group: 50026, Thumb: 50027, DataGrid: 50028, DataItem: 50029, Document: 50030, SplitButton: 50031, Window: 50032, Pane: 50033, Header: 50034, HeaderItem: 50035, Table: 50036, TitleBar: 50037, Separator: 50038, SemanticZoom: 50039, AppBar: 50040 }
static ControlPattern := { Invoke: 10000, Selection: 10001, Value: 10002, RangeValue: 10003, Scroll: 10004, ExpandCollapse: 10005, Grid: 10006, GridItem: 10007, MultipleView: 10008, Window: 10009, SelectionItem: 10010, Dock: 10011, Table: 10012, TableItem: 10013, Text: 10014, Toggle: 10015, Transform: 10016, ScrollItem: 10017, LegacyIAccessible: 10018, ItemContainer: 10019, VirtualizedItem: 10020, SynchronizedInput: 10021, ObjectModel: 10022, Annotation: 10023, Styles: 10025, Spreadsheet: 10026, SpreadsheetItem: 10027, TextChild: 10029, Drag: 10030, DropTarget: 10031, TextEdit: 10032, CustomNavigation: 10033,
10000: "Invoke", 10001: "Selection", 10002: "Value", 10003: "RangeValue", 10004: "Scroll", 10005: "ExpandCollapse", 10006: "Grid", 10007: "GridItem", 10008: "MultipleView", 10009: "Window", 10010: "SelectionItem", 10011: "Dock", 10012: "Table", 10013: "TableItem", 10014: "Text", 10015: "Toggle", 10016: "Transform", 10017: "ScrollItem", 10018: "LegacyIAccessible", 10019: "ItemContainer", 10020: "VirtualizedItem", 10021: "SynchronizedInput", 10022: "ObjectModel", 10023: "Annotation", 10025: "Styles", 10026: "Spreadsheet", 10027: "SpreadsheetItem", 10029: "TextChild", 10030: "Drag", 10031: "DropTarget", 10032: "TextEdit", 10033: "CustomNavigation" }
static Event := { ToolTipOpened: 20000, ToolTipClosed: 20001, StructureChanged: 20002, MenuOpened: 20003, AutomationPropertyChanged: 20004, AutomationFocusChanged: 20005, AsyncContentLoaded: 20006, MenuClosed: 20007, LayoutInvalidated: 20008, Invoke_Invoked: 20009, SelectionItem_ElementAddedToSelection: 20010, SelectionItem_ElementRemovedFromSelection: 20011, SelectionItem_ElementSelected: 20012, Selection_Invalidated: 20013, Text_TextSelectionChanged: 20014, Text_TextChanged: 20015, Window_WindowOpened: 20016, Window_WindowClosed: 20017, MenuModeStart: 20018, MenuModeEnd: 20019, InputReachedTarget: 20020, InputReachedOtherElement: 20021, InputDiscarded: 20022, SystemAlert: 20023, LiveRegionChanged: 20024, HostedFragmentRootsInvalidated: 20025, Drag_DragStart: 20026, Drag_DragCancel: 20027, Drag_DragComplete: 20028, DropTarget_DragEnter: 20029, DropTarget_DragLeave: 20030, DropTarget_Dropped: 20031, TextEdit_TextChanged: 20032, TextEdit_ConversionTargetChanged: 20033, Changes: 20034, Notification: 20035, ActiveTextPositionChanged: 20036 }
static Property := {
RuntimeId: 30000, ; VT_I4 | VT_ARRAY (VT_EMPTY)
BoundingRectangle: 30001, ; VT_R8 | VT_ARRAY ([0,0,0,0])
ProcessId: 30002, ; VT_I4 (0)
ControlType: 30003, ; VT_I4 (UIA_CustomControlTypeId)
LocalizedControlType: 30004, ; VT_BSTR (empty string) The string should contain only lowercase characters. Correct: "button", Incorrect: "Button"
Name: 30005, ; VT_BSTR (empty string)
AcceleratorKey: 30006, ; VT_BSTR (empty string)
AccessKey: 30007, ; VT_BSTR (empty string)
HasKeyboardFocus: 30008, ; VT_BOOL (FALSE)
IsKeyboardFocusable: 30009, ; VT_BOOL (FALSE)
IsEnabled: 30010, ; VT_BOOL (FALSE)
AutomationId: 30011, ; VT_BSTR (empty string)
ClassName: 30012, ; VT_BSTR (empty string)
HelpText: 30013, ; VT_BSTR (empty string)
ClickablePoint: 30014, ; VT_R8 | VT_ARRAY (VT_EMPTY)
Culture: 30015, ; VT_I4 (0)
IsControlElement: 30016, ; VT_BOOL (TRUE)
IsContentElement: 30017, ; VT_BOOL (TRUE)
LabeledBy: 30018, ; VT_UNKNOWN (NULL)
IsPassword: 30019, ; VT_BOOL (FALSE)
NativeWindowHandle: 30020, ; VT_I4 (0)
ItemType: 30021, ; VT_BSTR (empty string)
IsOffscreen: 30022, ; VT_BOOL (FALSE)
Orientation: 30023, ; VT_I4 (0 (OrientationType_None))
FrameworkId: 30024, ; VT_BSTR (empty string)
IsRequiredForForm: 30025, ; VT_BOOL (FALSE)
ItemStatus: 30026, ; VT_BSTR (empty string)
IsDockPatternAvailable: 30027, ; VT_BOOL
IsExpandCollapsePatternAvailable: 30028, ; VT_BOOL
IsGridItemPatternAvailable: 30029, ; VT_BOOL
IsGridPatternAvailable: 30030, ; VT_BOOL
IsInvokePatternAvailable: 30031, ; VT_BOOL
IsMultipleViewPatternAvailable: 30032, ; VT_BOOL
IsRangeValuePatternAvailable: 30033, ; VT_BOOL
IsScrollPatternAvailable: 30034, ; VT_BOOL
IsScrollItemPatternAvailable: 30035, ; VT_BOOL
IsSelectionItemPatternAvailable: 30036, ; VT_BOOL
IsSelectionPatternAvailable: 30037, ; VT_BOOL
IsTablePatternAvailable: 30038, ; VT_BOOL
IsTableItemPatternAvailable: 30039, ; VT_BOOL
IsTextPatternAvailable: 30040, ; VT_BOOL
IsTogglePatternAvailable: 30041, ; VT_BOOL
IsTransformPatternAvailable: 30042, ; VT_BOOL
IsValuePatternAvailable: 30043, ; VT_BOOL
IsWindowPatternAvailable: 30044, ; VT_BOOL
ValueValue: 30045, ; VT_BSTR (empty string)
ValueIsReadOnly: 30046, ; VT_BOOL (TRUE)
RangeValueValue: 30047, ; VT_R8 (0)
RangeValueIsReadOnly: 30048, ; VT_BOOL (TRUE)
RangeValueMinimum: 30049, ; VT_R8 (0)
RangeValueMaximum: 30050, ; VT_R8 (0)
RangeValueLargeChange: 30051, ; VT_R8 (0)
RangeValueSmallChange: 30052, ; VT_R8 (0)
ScrollHorizontalScrollPercent: 30053, ; VT_R8 (0)
ScrollHorizontalViewSize: 30054, ; VT_R8 (100)
ScrollVerticalScrollPercent: 30055, ; VT_R8 (0)
ScrollVerticalViewSize: 30056, ; VT_R8 (100)
ScrollHorizontallyScrollable: 30057, ; VT_BOOL (FALSE)
ScrollVerticallyScrollable: 30058, ; VT_BOOL (FALSE)
SelectionSelection: 30059, ; VT_UNKNOWN | VT_ARRAY (empty array)
SelectionCanSelectMultiple: 30060, ; VT_BOOL (FALSE)
SelectionIsSelectionRequired: 30061, ; VT_BOOL (FALSE)
GridRowCount: 30062, ; VT_I4 (0)
GridColumnCount: 30063, ; VT_I4 (0)
GridItemRow: 30064, ; VT_I4 (0)
GridItemColumn: 30065, ; VT_I4 (0)
GridItemRowSpan: 30066, ; VT_I4 (1)
GridItemColumnSpan: 30067, ; VT_I4 (1)
GridItemContainingGrid: 30068, ; VT_UNKNOWN (NULL)
DockDockPosition: 30069, ; VT_I4 (DockPosition_None)
ExpandCollapseExpandCollapseState: 30070, ; VT_I4 (ExpandCollapseState_LeafNode)
MultipleViewCurrentView: 30071, ; VT_I4 (0)
MultipleViewSupportedViews: 30072, ; VT_I4 | VT_ARRAY (empty array)
WindowCanMaximize: 30073, ; VT_BOOL (FALSE)
WindowCanMinimize: 30074, ; VT_BOOL (FALSE)
WindowWindowVisualState: 30075, ; VT_I4 (WindowVisualState_Normal)
WindowWindowInteractionState: 30076, ; VT_I4 (WindowInteractionState_Running)
WindowIsModal: 30077, ; VT_BOOL (FALSE)
WindowIsTopmost: 30078, ; VT_BOOL (FALSE)
SelectionItemIsSelected: 30079, ; VT_BOOL (FALSE)
SelectionItemSelectionContainer: 30080, ; VT_UNKNOWN (NULL)
TableRowHeaders: 30081, ; VT_UNKNOWN | VT_ARRAY (empty array)
TableColumnHeaders: 30082, ; VT_UNKNOWN | VT_ARRAY (empty array)
TableRowOrColumnMajor: 30083, ; VT_I4 (RowOrColumnMajor_Indeterminate)
TableItemRowHeaderItems: 30084, ; VT_UNKNOWN | VT_ARRAY (empty array)
TableItemColumnHeaderItems: 30085, ; VT_UNKNOWN | VT_ARRAY (empty array)
ToggleToggleState: 30086, ; VT_I4 (ToggleState_Indeterminate)
TransformCanMove: 30087, ; VT_BOOL (FALSE)
TransformCanResize: 30088, ; VT_BOOL (FALSE)
TransformCanRotate: 30089, ; VT_BOOL (FALSE)
IsLegacyIAccessiblePatternAvailable: 30090, ; VT_BOOL
LegacyIAccessibleChildId: 30091, ; VT_I4 (0)
LegacyIAccessibleName: 30092, ; VT_BSTR (empty string)
LegacyIAccessibleValue: 30093, ; VT_BSTR (empty string)
LegacyIAccessibleDescription: 30094, ; VT_BSTR (empty string)
LegacyIAccessibleRole: 30095, ; VT_I4 (0)
LegacyIAccessibleState: 30096, ; VT_I4 (0)
LegacyIAccessibleHelp: 30097, ; VT_BSTR (empty string)
LegacyIAccessibleKeyboardShortcut: 30098, ; VT_BSTR (empty string)
LegacyIAccessibleSelection: 30099, ; VT_UNKNOWN | VT_ARRAY (empty array)
LegacyIAccessibleDefaultAction: 30100, ; VT_BSTR (empty string)
AriaRole: 30101, ; VT_BSTR (empty string)
AriaProperties: 30102, ; VT_BSTR (empty string)
IsDataValidForForm: 30103, ; VT_BOOL (FALSE)
ControllerFor: 30104, ; VT_UNKNOWN | VT_ARRAY (empty array)
DescribedBy: 30105, ; VT_UNKNOWN | VT_ARRAY (empty array)
FlowsTo: 30106, ; VT_UNKNOWN | VT_ARRAY (empty array)
ProviderDescription: 30107, ; VT_BSTR (empty string)
IsItemContainerPatternAvailable: 30108, ; VT_BOOL
IsVirtualizedItemPatternAvailable: 30109, ; VT_BOOL
IsSynchronizedInputPatternAvailable: 30110, ; VT_BOOL
OptimizeForVisualContent: 30111, ; VT_BOOL (FALSE)
IsObjectModelPatternAvailable: 30112, ; VT_BOOL
AnnotationAnnotationTypeId: 30113, ; VT_I4 (0)
AnnotationAnnotationTypeName: 30114, ; VT_BSTR (empty string)
AnnotationAuthor: 30115, ; VT_BSTR (empty string)
AnnotationDateTime: 30116, ; VT_BSTR (empty string)
AnnotationTarget: 30117, ; VT_UNKNOWN (NULL)
IsAnnotationPatternAvailable: 30118, ; VT_BOOL
IsTextPattern2Available: 30119, ; VT_BOOL
StylesStyleId: 30120, ; VT_I4 (0)
StylesStyleName: 30121, ; VT_BSTR (empty string)
StylesFillColor: 30122, ; VT_I4 (0)
StylesFillPatternStyle: 30123, ; VT_BSTR (empty string)
StylesShape: 30124, ; VT_BSTR (empty string)
StylesFillPatternColor: 30125, ; VT_I4 (0)
StylesExtendedProperties: 30126, ; VT_BSTR (empty string)
IsStylesPatternAvailable: 30127, ; VT_BOOL
IsSpreadsheetPatternAvailable: 30128, ; VT_BOOL
SpreadsheetItemFormula: 30129, ; VT_BSTR (empty string)
SpreadsheetItemAnnotationObjects: 30130, ; VT_UNKNOWN | VT_ARRAY (empty array)
SpreadsheetItemAnnotationTypes: 30131, ; VT_I4 | VT_ARRAY (empty array)
IsSpreadsheetItemPatternAvailable: 30132, ; VT_BOOL
Transform2CanZoom: 30133, ; VT_BOOL (FALSE)
IsTransformPattern2Available: 30134, ; VT_BOOL
LiveSetting: 30135, ; VT_I4 (0)
IsTextChildPatternAvailable: 30136, ; VT_BOOL
IsDragPatternAvailable: 30137, ; VT_BOOL
DragIsGrabbed: 30138, ; VT_BOOL (FALSE)
DragDropEffect: 30139, ; VT_BSTR (empty string)
DragDropEffects: 30140, ; VT_BSTR | VT_ARRAY (empty array)
IsDropTargetPatternAvailable: 30141, ; VT_BOOL
DropTargetDropTargetEffect: 30142, ; VT_BSTR (empty string)
DropTargetDropTargetEffects: 30143, ; VT_BSTR | VT_ARRAY (empty array)
DragGrabbedItems: 30144, ; VT_UNKNOWN | VT_ARRAY (empty array)
Transform2ZoomLevel: 30145, ; VT_R8 (1)
Transform2ZoomMinimum: 30146, ; VT_R8 (1)
Transform2ZoomMaximum: 30147, ; VT_R8 (1)
FlowsFrom: 30148, ; VT_UNKNOWN | VT_ARRAY (empty array)
IsTextEditPatternAvailable: 30149, ; VT_BOOL
IsPeripheral: 30150, ; VT_BOOL (FALSE)
IsCustomNavigationPatternAvailable: 30151, ; VT_BOOL
PositionInSet: 30152, ; VT_I4 (0)
SizeOfSet: 30153, ; VT_I4 (0)
Level: 30154, ; VT_I4 (0)
AnnotationTypes: 30155, ; VT_I4 | VT_ARRAY (empty array)
AnnotationObjects: 30156, ; VT_I4 | VT_ARRAY (empty array)
LandmarkType: 30157, ; VT_I4 (0)
LocalizedLandmarkType: 30158, ; VT_BSTR (empty string)
FullDescription: 30159, ; VT_BSTR (empty string)
FillColor: 30160, ; VT_I4 (0)
OutlineColor: 30161, ; VT_I4 | VT_ARRAY (0)
FillType: 30162, ; VT_I4 (0)
VisualEffects: 30163, ; VT_I4 (0) VisualEffects_Shadow: 0x1 VisualEffects_Reflection: 0x2 VisualEffects_Glow: 0x4 VisualEffects_SoftEdges: 0x8 VisualEffects_Bevel: 0x10
OutlineThickness: 30164, ; VT_R8 | VT_ARRAY (VT_EMPTY)
CenterPoint: 30165, ; VT_R8 | VT_ARRAY (VT_EMPTY)
Rotation: 30166, ; VT_R8 (0)
Size: 30167, ; VT_R8 | VT_ARRAY (VT_EMPTY)
HeadingLevel: 30173, ; VT_I4 (HeadingLevel_None)
IsDialog: 30174 ; VT_BOOL (FALSE)
}
static PropertyConditionFlags := {
None: 0,
IgnoreCase: 1,
MatchSubstring: 2
}
static TextAttribute := {
AnimationStyle: 40000, ; VT_I4 (AnimationStyle_None)
BackgroundColor: 40001, ; VT_I4 (0)
BulletStyle: 40002, ; VT_I4 (BulletStyle_None)
CapStyle: 40003, ; VT_I4 (CapStyle_None)
Culture: 40004, ; VT_I4 (locale of the application UI)
FontName: 40005, ; VT_BSTR (empty string)
FontSize: 40006, ; VT_R8 (0)
FontWeight: 40007, ; VT_I4 (0)
ForegroundColor: 40008, ; VT_I4 (0)
HorizontalTextAlignment: 40009, ; VT_I4 (HorizontalTextAlignment_Left)
IndentationFirstLine: 40010, ; VT_R8 (0)
IndentationLeading: 40011, ; VT_R8 (0)
IndentationTrailing: 40012, ; VT_R8 (0)
IsHidden: 40013, ; VT_BOOL (FALSE)
IsItalic: 40014, ; VT_BOOL (FALSE)
IsReadOnly: 40015, ; VT_BOOL (FALSE)
IsSubscript: 40016, ; VT_BOOL (FALSE)
IsSuperscript: 40017, ; VT_BOOL (FALSE)
MarginBottom: 40018, ; VT_R8 (0)
MarginLeading: 40019, ; VT_R8 (0)
MarginTop: 40020, ; VT_R8
MarginTrailing: 40021, ; VT_R8 (0)
OutlineStyles: 40022, ; VT_I4 (OutlineStyles_None)
OverlineColor: 40023, ; VT_I4 (0)
OverlineStyle: 40024, ; VT_I4 (TextDecorationLineStyle_None)
StrikethroughColor: 40025, ; VT_I4 (0)
StrikethroughStyle: 40026, ; VT_I4 (TextDecorationLineStyle_None)
Tabs: 40027, ; VT_ARRAY VT_R8 (empty array)
TextFlowDirections: 40028, ; VT_I4 (FlowDirections_Default)
UnderlineColor: 40029, ; VT_I4 (0)
UnderlineStyle: 40030, ; VT_I4 (TextDecorationLineStyle_None)
AnnotationTypes: 40031, ; VT_ARRAY VT_I4 (empty array)
AnnotationObjects: 40032, ; VT_UNKNOWN (empty array)
StyleName: 40033, ; VT_BSTR (empty string)
StyleId: 40034, ; VT_I4 (0)
Link: 40035, ; VT_UNKNOWN (NULL)
IsActive: 40036, ; VT_BOOL (FALSE)
SelectionActiveEnd: 40037, ; VT_I4 (ActiveEnd_None)
CaretPosition: 40038, ; VT_I4 (CaretPosition_Unknown)
CaretBidiMode: 40039, ; VT_I4 (CaretBidiMode_LTR)
LineSpacing: 40040, ; VT_BSTR ("LineSpacingAttributeDefault")
BeforeParagraphSpacing: 40041, ; VT_R8 (0)
AfterParagraphSpacing: 40042, ; VT_R8 (0)
}
static TreeScope := {
None: 0,
Element: 1,
Children: 2,
Descendants: 4,
Subtree: 7,
Parent: 8,
Ancestors: 16
}
/**
* Create Property Condition from AHK Object
* @param obj Object or Map or Array contains multiple Property Conditions. default operator (Object, Map): `and`, default operator (Array): `or`, default flags: 0
* #### example
* `[{ControlType: 50000, Name: "edit"}, {ControlType: 50004, Name: "edit", flags: 3}]` is same as `{0:{ControlType: 50000, Name: "edit"}, 1:{ControlType: 50004, Name: "edit", flags: 3}, operator: "or"}`
*
* {0: {ControlType: 50004, Name: "edit"}, operator: "not"}
* @returns IUIAutomationCondition
*/
static PropertyCondition(obj) {
return conditionbuilder(obj)
conditionbuilder(obj) {
switch Type(obj) {
case "Object":
operator := obj.DeleteProp("operator") || "and"
flags := obj.DeleteProp("flags") || 0
count := ObjOwnPropCount(obj), obj := obj.OwnProps()
case "Array":
operator := "or", flags := 0, count := obj.Length
case "Map":
operator := obj.Delete("operator") || "and"
flags := obj.Delete("flags") || 0
count := obj.Count
default:
throw TypeError("Invalid parameter type", -3)
}
arr := ComObjArray(0xd, count), i := 0
for k, v in obj {
if (IsNumber(k))
k := Integer(k)
else
k := UIA.Property.%k%
if (k >= 30000) {
switch k {
case 30003:
if !(v is Integer)
try v := UIA.ControlType.%v%
}
t := flags ? UIA.CreatePropertyConditionEx(k, v, flags) : UIA.CreatePropertyCondition(k, v)
arr[i++] := t[]
} else
t := conditionbuilder(v), arr[i++] := t[]
}
if (count = 1) {
if (operator = "not")
return UIA.CreateNotCondition(t)
return t
} else {
switch operator, false {
case "and":
return UIA.CreateAndConditionFromArray(arr)
case "or":
return UIA.CreateOrConditionFromArray(arr)
default:
return UIA.CreateFalseCondition()
}
}
}
}
; Compares two UI Automation elements to determine whether they represent the same underlying UI element.
static CompareElements(el1, el2) => (ComCall(3, this, "ptr", el1, "ptr", el2, "int*", &areSame := 0), areSame)
; Compares two integer arrays containing run-time identifiers (IDs) to determine whether their content is the same and they belong to the same UI element.
static CompareRuntimeIds(runtimeId1, runtimeId2) => (ComCall(4, this, "ptr", runtimeId1, "ptr", runtimeId2, "int*", &areSame := 0), areSame)
; Retrieves the UI Automation element that represents the desktop.
static GetRootElement() => (ComCall(5, this, "ptr*", &root := 0), IUIAutomationElement(root))
; Retrieves a UI Automation element for the specified window.
static ElementFromHandle(hwnd) => (ComCall(6, this, "ptr", hwnd, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves the UI Automation element at the specified point on the desktop.
static ElementFromPoint(pt) => (ComCall(7, this, "int64", pt, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves the UI Automation element that has the input focus.
static GetFocusedElement() => (ComCall(8, this, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves the UI Automation element that has the input focus, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
static GetRootElementBuildCache(cacheRequest) => (ComCall(9, this, "ptr", cacheRequest, "ptr*", &root := 0), IUIAutomationElement(root))
; Retrieves a UI Automation element for the specified window, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
static ElementFromHandleBuildCache(hwnd, cacheRequest) => (ComCall(10, this, "ptr", hwnd, "ptr", cacheRequest, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves the UI Automation element at the specified point on the desktop, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
static ElementFromPointBuildCache(pt, cacheRequest) => (ComCall(11, this, "int64", pt, "ptr", cacheRequest, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves the UI Automation element that has the input focus, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
static GetFocusedElementBuildCache(cacheRequest) => (ComCall(12, this, "ptr", cacheRequest, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves a tree walker object that can be used to traverse the Microsoft UI Automation tree.
static CreateTreeWalker(pCondition) => (ComCall(13, this, "ptr", pCondition, "ptr*", &walker := 0), IUIAutomationTreeWalker(walker))
; Retrieves an IUIAutomationTreeWalker interface used to discover control elements.
static ControlViewWalker() => (ComCall(14, this, "ptr*", &walker := 0), IUIAutomationTreeWalker(walker))
; Retrieves an IUIAutomationTreeWalker interface used to discover content elements.
static ContentViewWalker() => (ComCall(15, this, "ptr*", &walker := 0), IUIAutomationTreeWalker(walker))
; Retrieves a tree walker object used to traverse an unfiltered view of the UI Automation tree.
static RawViewWalker() => (ComCall(16, this, "ptr*", &walker := 0), IUIAutomationTreeWalker(walker))
; Retrieves a predefined IUIAutomationCondition interface that selects all UI elements in an unfiltered view.
static RawViewCondition() => (ComCall(17, this, "ptr*", &condition := 0), IUIAutomationCondition(condition))
; Retrieves a predefined IUIAutomationCondition interface that selects control elements.
static ControlViewCondition() => (ComCall(18, this, "ptr*", &condition := 0), IUIAutomationCondition(condition))
; Retrieves a predefined IUIAutomationCondition interface that selects content elements.
static ContentViewCondition() => (ComCall(19, this, "ptr*", &condition := 0), IUIAutomationCondition(condition))
; Creates a cache request.
; After obtaining the IUIAutomationCacheRequest interface, use its methods to specify properties and control patterns to be cached when a UI Automation element is obtained.
static CreateCacheRequest() => (ComCall(20, this, "ptr*", &cacheRequest := 0), IUIAutomationCacheRequest(cacheRequest))
; Retrieves a predefined condition that selects all elements.
static CreateTrueCondition() => (ComCall(21, this, "ptr*", &newCondition := 0), IUIAutomationBoolCondition(newCondition))
; Creates a condition that is always false.
; This method exists only for symmetry with IUIAutomation,,CreateTrueCondition. A false condition will never enable a match with UI Automation elements, and it cannot usefully be combined with any other condition.
static CreateFalseCondition() => (ComCall(22, this, "ptr*", &newCondition := 0), IUIAutomationBoolCondition(newCondition))
; Creates a condition that selects elements that have a property with the specified value.
static CreatePropertyCondition(propertyId, value) {
if A_PtrSize = 4
v := ComVar(value, , true), ComCall(23, this, "int", propertyId, "int64", NumGet(v, 'int64'), "int64", NumGet(v, 8, "int64"), "ptr*", &newCondition := 0)
else
ComCall(23, this, "int", propertyId, "ptr", ComVar(value, , true), "ptr*", &newCondition := 0)
return IUIAutomationPropertyCondition(newCondition)
}
; Creates a condition that selects elements that have a property with the specified value, using optional flags.
static CreatePropertyConditionEx(propertyId, value, flags) {
if A_PtrSize = 4
v := ComVar(value, , true), ComCall(24, this, "int", propertyId, "int64", NumGet(v, 'int64'), "int64", NumGet(v, 8, "int64"), "int", flags, "ptr*", &newCondition := 0)
else
ComCall(24, this, "int", propertyId, "ptr", ComVar(value, , true), "int", flags, "ptr*", &newCondition := 0)
return IUIAutomationPropertyCondition(newCondition)
}
; The Create**Condition** method calls AddRef on each pointers. This means you can call Release on those pointers after the call to Create**Condition** returns without invalidating the pointer returned from Create**Condition**. When you call Release on the pointer returned from Create**Condition**, UI Automation calls Release on those pointers.
; Creates a condition that selects elements that match both of two conditions.
static CreateAndCondition(condition1, condition2) => (ComCall(25, this, "ptr", condition1, "ptr", condition2, "ptr*", &newCondition := 0), IUIAutomationAndCondition(newCondition))
; Creates a condition that selects elements based on multiple conditions, all of which must be true.
static CreateAndConditionFromArray(conditions) => (ComCall(26, this, "ptr", conditions, "ptr*", &newCondition := 0), IUIAutomationAndCondition(newCondition))
; Creates a condition that selects elements based on multiple conditions, all of which must be true.
static CreateAndConditionFromNativeArray(conditions, conditionCount) => (ComCall(27, this, "ptr", conditions, "int", conditionCount, "ptr*", &newCondition := 0), IUIAutomationAndCondition(newCondition))
; Creates a combination of two conditions where a match exists if either of the conditions is true.
static CreateOrCondition(condition1, condition2) => (ComCall(28, this, "ptr", condition1, "ptr", condition2, "ptr*", &newCondition := 0), IUIAutomationOrCondition(newCondition))
; Creates a combination of two or more conditions where a match exists if any of the conditions is true.
static CreateOrConditionFromArray(conditions) => (ComCall(29, this, "ptr", conditions, "ptr*", &newCondition := 0), IUIAutomationOrCondition(newCondition))
; Creates a combination of two or more conditions where a match exists if any one of the conditions is true.
static CreateOrConditionFromNativeArray(conditions, conditionCount) => (ComCall(30, this, "ptr", conditions, "ptr", conditionCount, "ptr*", &newCondition := 0), IUIAutomationOrCondition(newCondition))
; Creates a condition that is the negative of a specified condition.
static CreateNotCondition(condition) => (ComCall(31, this, "ptr", condition, "ptr*", &newCondition := 0), IUIAutomationNotCondition(newCondition))
; Note, Before implementing an event handler, you should be familiar with the threading issues described in Understanding Threading Issues. http,//msdn.microsoft.com/en-us/library/ee671692(v=vs.85).aspx
; A UI Automation client should not use multiple threads to add or remove event handlers. Unexpected behavior can result if one event handler is being added or removed while another is being added or removed in the same client process.
; It is possible for an event to be delivered to an event handler after the handler has been unsubscribed, if the event is received simultaneously with the request to unsubscribe the event. The best practice is to follow the Component Object Model (COM) standard and avoid destroying the event handler object until its reference count has reached zero. Destroying an event handler immediately after unsubscribing for events may result in an access violation if an event is delivered late.
; Registers a method that handles Microsoft UI Automation events.
static AddAutomationEventHandler(eventId, element, scope, cacheRequest, handler) => ComCall(32, this, "int", eventId, "ptr", element, "int", scope, "ptr", cacheRequest ? cacheRequest : 0, "ptr", handler)
; Removes the specified UI Automation event handler.
static RemoveAutomationEventHandler(eventId, element, handler) => ComCall(33, this, "int", eventId, "ptr", element, "ptr", handler)
; Registers a method that handles property-changed events.
; The UI item specified by element might not support the properties specified by the propertyArray parameter.
; This method serves the same purpose as IUIAutomation,,AddPropertyChangedEventHandler, but takes a normal array of property identifiers instead of a SAFEARRAY.
static AddPropertyChangedEventHandlerNativeArray(element, scope, cacheRequest, handler, propertyArray, propertyCount) => ComCall(34, this, "ptr", element, "int", scope, "ptr", cacheRequest, "ptr", handler, "ptr", propertyArray, "int", propertyCount)
; Registers a method that handles property-changed events.
; The UI item specified by element might not support the properties specified by the propertyArray parameter.
static AddPropertyChangedEventHandler(element, scope, cacheRequest, handler, propertyArray) => ComCall(35, this, "ptr", element, "int", scope, "ptr", cacheRequest, "ptr", handler, "ptr", propertyArray)
; Removes a property-changed event handler.
static RemovePropertyChangedEventHandler(element, handler) => ComCall(36, this, "ptr", element, "ptr", handler)
; Registers a method that handles structure-changed events.
static AddStructureChangedEventHandler(element, scope, cacheRequest, handler) => ComCall(37, this, "ptr", element, "int", scope, "ptr", cacheRequest ? cacheRequest : 0, "ptr", handler)
; Removes a structure-changed event handler.
static RemoveStructureChangedEventHandler(element, handler) => ComCall(38, this, "ptr", element, "ptr", handler)
; Registers a method that handles focus-changed events.
; Focus-changed events are system-wide; you cannot set a narrower scope.
static AddFocusChangedEventHandler(cacheRequest, handler) => ComCall(39, this, "ptr", cacheRequest ? cacheRequest : 0, "ptr", handler)
; Removes a focus-changed event handler.
static RemoveFocusChangedEventHandler(handler) => ComCall(40, this, "ptr", handler)
; Removes all registered Microsoft UI Automation event handlers.
static RemoveAllEventHandlers() => ComCall(41, this)
; Converts an array of integers to a SAFEARRAY.
static IntNativeArrayToSafeArray(array, arrayCount) => (ComCall(42, this, "ptr", array, "int", arrayCount, "ptr*", &safeArray := 0), ComValue(0x2003, safeArray))
; Converts a SAFEARRAY of integers to an array.
static IntSafeArrayToNativeArray(intArray) => (ComCall(43, this, "ptr", intArray, "ptr*", &array := 0, "int*", &arrayCount := 0), NativeArray(array, arrayCount, "int"))
; Creates a VARIANT that contains the coordinates of a rectangle.
; The returned VARIANT has a data type of VT_ARRAY | VT_R8.
static RectToVariant(rc) => (ComCall(44, this, "ptr", rc, "ptr", var := ComVar()), var)
; Converts a VARIANT containing rectangle coordinates to a RECT.
static VariantToRect(var) {
if A_PtrSize = 4
ComCall(45, this, "int64", NumGet(var, "int64"), "int64", NumGet(var, 8, "int64"), "ptr", rc := NativeArray(0, 4, "Int"))
else
ComCall(45, this, "ptr", var, "ptr", rc := NativeArray(0, 4, "Int"))
return rc
}
; Converts a SAFEARRAY containing rectangle coordinates to an array of type RECT.
static SafeArrayToRectNativeArray(rects) => (ComCall(46, this, "ptr", rects, "ptr*", &rectArray := 0, "int*", &rectArrayCount := 0), NativeArray(rectArray, rectArrayCount, "int"))
; Creates a instance of a proxy factory object.
; Use the IUIAutomationProxyFactoryMapping interface to enter the proxy factory into the table of available proxies.
static CreateProxyFactoryEntry(factory) => (ComCall(47, this, "ptr", factory, "ptr*", &factoryEntry := 0), IUIAutomationProxyFactoryEntry(factoryEntry))
; Retrieves an object that represents the mapping of Window classnames and associated data to individual proxy factories. This property is read-only.
static ProxyFactoryMapping() => (ComCall(48, this, "ptr*", &factoryMapping := 0), IUIAutomationProxyFactoryMapping(factoryMapping))
; The programmatic name is intended for debugging and diagnostic purposes only. The string is not localized.
; This property should not be used in string comparisons. To determine whether two properties are the same, compare the property identifiers directly.
; Retrieves the registered programmatic name of a property.
static GetPropertyProgrammaticName(property) => (ComCall(49, this, "int", property, "ptr*", &name := 0), BSTR(name))
; Retrieves the registered programmatic name of a control pattern.
static GetPatternProgrammaticName(pattern) => (ComCall(50, this, "int", pattern, "ptr*", &name := 0), BSTR(name))
; This method is intended only for use by Microsoft UI Automation tools that need to scan for properties. It is not intended to be used by UI Automation clients.
; There is no guarantee that the element will support any particular control pattern when asked for it later.
; Retrieves the control patterns that might be supported on a UI Automation element.
static PollForPotentialSupportedPatterns(pElement, &patternIds, &patternNames) {
ComCall(51, this, "ptr", pElement, "ptr*", &patternIds := 0, "ptr*", &patternNames := 0)
patternIds := ComValue(0x2003, patternIds), patternNames := ComValue(0x2008, patternNames)
}
; Retrieves the properties that might be supported on a UI Automation element.
static PollForPotentialSupportedProperties(pElement, &propertyIds, &propertyNames) {
ComCall(52, this, "ptr", pElement, "ptr*", &propertyIds := 0, "ptr*", &propertyNames := 0)
propertyIds := ComValue(0x2003, propertyIds), propertyNames := ComValue(0x2008, propertyNames)
}
; Checks a provided VARIANT to see if it contains the Not Supported identifier.
; After retrieving a property for a UI Automation element, call this method to determine whether the element supports the retrieved property. CheckNotSupported is typically called after calling a property retrieving method such as GetCurrentPropertyValue.
static CheckNotSupported(value) {
if A_PtrSize = 4
value := ComVar(value, , true), ComCall(53, this, "int64", NumGet(value, "int64"), "int64", NumGet(value, 8, "int64"), "int*", &isNotSupported := 0)
else
ComCall(53, this, "ptr", ComVar(value, , true), "int*", &isNotSupported := 0)
return isNotSupported
}
; Retrieves a static token object representing a property or text attribute that is not supported. This property is read-only.
; This object can be used for comparison with the results from IUIAutomationElement,,GetCurrentPropertyValue or IUIAutomationTextRange,,GetAttributeValue.
static ReservedNotSupportedValue() => (ComCall(54, this, "ptr*", ¬SupportedValue := 0), ComValue(0xd, notSupportedValue))
; Retrieves a static token object representing a text attribute that is a mixed attribute. This property is read-only.
; The object retrieved by IUIAutomation,,ReservedMixedAttributeValue can be used for comparison with the results from IUIAutomationTextRange,,GetAttributeValue to determine if a text range contains more than one value for a particular text attribute.
static ReservedMixedAttributeValue() => (ComCall(55, this, "ptr*", &mixedAttributeValue := 0), ComValue(0xd, mixedAttributeValue))
; This method enables UI Automation clients to get IUIAutomationElement interfaces for accessible objects implemented by a Microsoft Active Accessiblity server.
; This method may fail if the server implements UI Automation provider interfaces alongside Microsoft Active Accessibility support.
; The method returns E_INVALIDARG if the underlying implementation of the Microsoft UI Automation element is not a native Microsoft Active Accessibility server; that is, if a client attempts to retrieve the IAccessible interface for an element originally supported by a proxy object from Oleacc.dll, or by the UIA-to-MSAA Bridge.
; Retrieves a UI Automation element for the specified accessible object from a Microsoft Active Accessibility server.
static ElementFromIAccessible(accessible, childId) => (ComCall(56, this, "ptr", accessible, "int", childId, "ptr*", &element := 0), IUIAutomationElement(element))
; Retrieves a UI Automation element for the specified accessible object from a Microsoft Active Accessibility server, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
static ElementFromIAccessibleBuildCache(accessible, childId, cacheRequest) => (ComCall(57, this, "ptr", accessible, "int", childId, "ptr", cacheRequest, "ptr*", &element := 0), IUIAutomationElement(element))
}
class IUIAutomationAndCondition extends IUIAutomationCondition {
ChildCount => (ComCall(3, this, "int*", &childCount := 0), childCount)
GetChildrenAsNativeArray() => (ComCall(4, this, "ptr*", &childArray := 0, "int*", &childArrayCount := 0), NativeArray(childArray, childArrayCount))
GetChildren() => (ComCall(5, this, "ptr*", &childArray := 0), ComValue(0x200d, childArray))
}
class IUIAutomationAnnotationPattern extends IUIABase {
CurrentAnnotationTypeId => (ComCall(3, this, "int*", &retVal := 0), retVal)
CurrentAnnotationTypeName => (ComCall(4, this, "ptr*", &retVal := 0), BSTR(retVal))
CurrentAuthor => (ComCall(5, this, "ptr*", &retVal := 0), BSTR(retVal))
CurrentDateTime => (ComCall(6, this, "ptr*", &retVal := 0), BSTR(retVal))
CurrentTarget => (ComCall(7, this, "ptr*", &retVal := 0), IUIAutomationElement(retVal))
CachedAnnotationTypeId => (ComCall(8, this, "int*", &retVal := 0), retVal)
CachedAnnotationTypeName => (ComCall(9, this, "ptr*", &retVal := 0), BSTR(retVal))
CachedAuthor => (ComCall(10, this, "ptr*", &retVal := 0), BSTR(retVal))
CachedDateTime => (ComCall(11, this, "ptr*", &retVal := 0), BSTR(retVal))
CachedTarget => (ComCall(11, this, "ptr*", &retVal := 0), IUIAutomationElement(retVal))
}
class IUIAutomationBoolCondition extends IUIAutomationCondition {
Value => (ComCall(3, this, "int*", &boolVal := 0), boolVal)
}
class IUIAutomationCacheRequest extends IUIABase {
; Adds a property to the cache request.
AddProperty(propertyId) => ComCall(3, this, "int", propertyId)
; Adds a control pattern to the cache request. Adding a control pattern that is already in the cache request has no effect.
AddPattern(patternId) => ComCall(4, this, "int", patternId)
; Creates a copy of the cache request.
Clone() => (ComCall(5, this, "ptr*", &clonedRequest := 0), IUIAutomationCacheRequest(clonedRequest))
TreeScope {
get => (ComCall(6, this, "int*", &scope := 0), scope)
set => ComCall(7, this, "int", Value)
}
TreeFilter {
get => (ComCall(8, this, "ptr*", &filter := 0), IUIAutomationCondition(filter))
set => ComCall(9, this, "ptr", Value)
}
AutomationElementMode {
get => (ComCall(10, this, "int*", &mode := 0), mode)
set => ComCall(11, this, "int", Value)
}
}
class IUIAutomationCondition extends IUIABase {
}
class IUIAutomationCustomNavigationPattern extends IUIABase {
Navigate(direction) => (ComCall(3, this, "int", direction, "ptr*", &pRetVal := 0), IUIAutomationElement(pRetVal))
}
class IUIAutomationDockPattern extends IUIABase {
; Sets the dock position of this element.
SetDockPosition(dockPos) => ComCall(3, this, "int", dockPos)
; Retrieves the `dock position` of this element within its docking container.
CurrentDockPosition => (ComCall(4, this, "int*", &retVal := 0), retVal)
; Retrieves the `cached dock` position of this element within its docking container.
CachedDockPosition => (ComCall(5, this, "int*", &retVal := 0), retVal)
}
class IUIAutomationDragPattern extends IUIABase {
CurrentIsGrabbed => (ComCall(3, this, "int*", &retVal := 0), retVal)
CachedIsGrabbed => (ComCall(4, this, "int*", &retVal := 0), retVal)
CurrentDropEffect => (ComCall(5, this, "ptr*", &retVal := 0), BSTR(retVal))
CachedDropEffect => (ComCall(6, this, "ptr*", &retVal := 0), BSTR(retVal))
CurrentDropEffects => (ComCall(7, this, "ptr*", &retVal := 0), ComValue(0x2008, retVal))
CachedDropEffects => (ComCall(8, this, "ptr*", &retVal := 0), ComValue(0x2008, retVal))
GetCurrentGrabbedItems() => (ComCall(9, this, "ptr*", &retVal := 0), IUIAutomationElementArray(retVal))
GetCachedGrabbedItems() => (ComCall(10, this, "ptr*", &retVal := 0), IUIAutomationElementArray(retVal))
}
class IUIAutomationDropTargetPattern extends IUIABase {
CurrentDropTargetEffect => (ComCall(3, this, "ptr*", &retVal := 0), BSTR(retVal))
CachedDropTargetEffect => (ComCall(4, this, "ptr*", &retVal := 0), BSTR(retVal))
CurrentDropTargetEffects => (ComCall(5, this, "ptr*", &retVal := 0), ComValue(0x2008, retVal))
CachedDropTargetEffects => (ComCall(6, this, "ptr*", &retVal := 0), ComValue(0x2008, retVal))
}
class IUIAutomationElement extends IUIABase {
/**
* Find or wait target control element.
* @param ControlType target control type, such as 'button' or UIA.ControlType.Button
* @param propertys The property object or 'Name' property.
* @param propertyId The property identifier. `Name`(default)
* @param waittime Waiting time for control element to appear.
*/
FindControl(ControlID, propertys := unset, waittime := 0) {
index := 1
if !IsNumber(ControlID) {
if RegExMatch(ControlID, "i)^([a-z]+)(\d+)$", &m)
index := Integer(m[2]), ControlID := m[1]
try ControlID := UIA.ControlType.%ControlID%
catch
throw ValueError("ControlType invalid")
}
if (!IsSet(propertys))
propertys := {}
switch Type(propertys) {
case "String":
propertys := { Name: propertys }
case "Array":
propertys := { 0: propertys }
case "Object":
default:
throw ValueError("invalid param")
}
propertys.ControlType := ControlID
cond := UIA.PropertyCondition(propertys)
endtime := A_TickCount + waittime
loop {
try {
if (index = 1)
return this.FindFirst(cond)
else {
eles := this.FindAll(cond)
if (index <= eles.Length)
return eles.GetElement(index)
throw TargetError("Target element not found.")
}
} catch TargetError {
if (A_TickCount > endtime)
return
}
}
}
GetAllCurrentPropertyValue() {
infos := {}
for k, v in UIA.Property.OwnProps() {
v := this.GetCurrentPropertyValue(v)
if (v is ComObjArray) {
arr := []
for t in v
arr.Push(t)
v := arr
}
infos.%k% := v
}
return infos
}
GetControlID() {
cond := UIA.CreatePropertyCondition(UIA.Property.ControlType, controltype := this.GetCurrentPropertyValue(UIA.Property.ControlType))
runtimeid := IUIA_RuntimeIdToString(this.GetRuntimeId())
runtimeid := RegExReplace(runtimeid, "^(\w+\.\w+)\..*$", "$1")
rootele := UIA.GetRootElement().FindFirst(UIA.CreatePropertyCondition(UIA.Property.RuntimeId, IUIA_RuntimeIdFromString(runtimeid)))
eles := rootele.FindAll(cond)
for i in UIA.ControlType
if (UIA.ControlType.%i% == controltype) {
controltype := i
break
}
loop eles.Length {
if (UIA.CompareElements(this, eles.GetElement(A_Index - 1)))
return controltype A_Index
}
}
; Sets the keyboard focus to this UI Automation element.
SetFocus() => ComCall(3, this)
; Retrieves the unique identifier assigned to the UI element.
; The identifier is only guaranteed to be unique to the UI of the desktop on which it was generated. Identifiers can be reused over time.
; The format of run-time identifiers might change in the future. The returned identifier should be treated as an opaque value and used only for comparison; for example, to determine whether a Microsoft UI Automation element is in the cache.
GetRuntimeId() => (ComCall(4, this, "ptr*", &runtimeId := 0), ComValue(0x2003, runtimeId))
; The scope of the search is relative to the element on which the method is called. Elements are returned in the order in which they are encountered in the tree.
; This function cannot search for ancestor elements in the Microsoft UI Automation tree; that is, TreeScope_Ancestors is not a valid value for the scope parameter.
; When searching for top-level windows on the desktop, be sure to specify TreeScope_Children in the scope parameter, not TreeScope_Descendants. A search through the entire subtree of the desktop could iterate through thousands of items and lead to a stack overflow.
; If your client application might try to find elements in its own user interface, you must make all UI Automation calls on a separate thread.
; Retrieves the first child or descendant element that matches the specified condition.
FindFirst(condition, scope := 4) {
if (ComCall(5, this, "int", scope, "ptr", condition, "ptr*", &found := 0), found)
return IUIAutomationElement(found)
throw TargetError("Target element not found.")
}
; Returns all UI Automation elements that satisfy the specified condition.
FindAll(condition, scope := 4) {
if (ComCall(6, this, "int", scope, "ptr", condition, "ptr*", &found := 0), found)
return IUIAutomationElementArray(found)
throw TargetError("Target elements not found.")
}
; Retrieves the first child or descendant element that matches the specified condition, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
FindFirstBuildCache(condition, cacheRequest, scope := 4) {
if (ComCall(7, this, "int", scope, "ptr", condition, "ptr", cacheRequest, "ptr*", &found := 0), found)
return IUIAutomationElement(found)
throw TargetError("Target element not found.")
}
; Returns all UI Automation elements that satisfy the specified condition, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
FindAllBuildCache(condition, cacheRequest, scope := 4) {
if (ComCall(8, this, "int", scope, "ptr", condition, "ptr", cacheRequest, "ptr*", &found := 0), found)
return IUIAutomationElementArray(found)
throw TargetError("Target elements not found.")
}
; Retrieves a UI Automation element with an updated cache.
; The original UI Automation element is unchanged. The IUIAutomationElement interface refers to the same element and has the same runtime identifier.
BuildUpdatedCache(cacheRequest) => (ComCall(9, this, "ptr", cacheRequest, "ptr*", &updatedElement := 0), IUIAutomationElement(updatedElement))
; Microsoft UI Automation properties of the double type support Not a Number (NaN) values. When retrieving a property of the double type, a client can use the _isnan function to determine whether the property is a NaN value.
; Retrieves the current value of a property for this UI Automation element.
GetCurrentPropertyValue(propertyId) => (ComCall(10, this, "int", propertyId, "ptr", val := ComVar()), val[])
; Retrieves a property value for this UI Automation element, optionally ignoring any default value.
; Passing FALSE in the ignoreDefaultValue parameter is equivalent to calling IUIAutomationElement,,GetCurrentPropertyValue.
; If the Microsoft UI Automation provider for the element itself supports the property, the value of the property is returned. Otherwise, if ignoreDefaultValue is FALSE, a default value specified by UI Automation is returned.
; This method returns a failure code if the requested property was not previously cached.
GetCurrentPropertyValueEx(propertyId, ignoreDefaultValue) => (ComCall(11, this, "int", propertyId, "int", ignoreDefaultValue, "ptr", val := ComVar()), val[])
; Retrieves a property value from the cache for this UI Automation element.
GetCachedPropertyValue(propertyId) => (ComCall(12, this, "int", propertyId, "ptr", val := ComVar()), val[])
; Retrieves a property value from the cache for this UI Automation element, optionally ignoring any default value.
GetCachedPropertyValueEx(propertyId, ignoreDefaultValue, retVal) => (ComCall(13, this, "int", propertyId, "int", ignoreDefaultValue, "ptr", val := ComVar()), val[])
; Retrieves the control pattern interface of the specified pattern on this UI Automation element.
GetCurrentPatternAs(patternId, riid) { ; not completed
try {
if IsNumber(patternId)
name := UIA.ControlPattern.%patternId%
else
patternId := UIA.ControlPattern.%(name := patternId)%
ComCall(14, this, "int", patternId, "ptr", riid, "ptr*", &patternObject := 0)
return IUIAutomation%name%Pattern(patternObject)
}
}
; Retrieves the control pattern interface of the specified pattern from the cache of this UI Automation element.
GetCachedPatternAs(patternId, riid) { ; not completed
try {
if IsNumber(patternId)
name := UIA.ControlPattern.%patternId%
else
patternId := UIA.ControlPattern.%(name := patternId)%
ComCall(15, this, "int", patternId, "ptr", riid, "ptr*", &patternObject := 0)
return IUIAutomation%name%Pattern(patternObject)
}
}
; Retrieves the IUnknown interface of the specified control pattern on this UI Automation element.
; This method gets the specified control pattern based on its availability at the time of the call.
; For some forms of UI, this method will incur cross-process performance overhead. Applications can reduce overhead by caching control patterns and then retrieving them by using IUIAutomationElement,,GetCachedPattern.
GetCurrentPattern(patternId) {
try {
if IsNumber(patternId)
name := UIA.ControlPattern.%patternId%
else
patternId := UIA.ControlPattern.%(name := patternId)%
ComCall(16, this, "int", patternId, "ptr*", &patternObject := 0)
return IUIAutomation%name%Pattern(patternObject)
}
}
; Retrieves from the cache the IUnknown interface of the specified control pattern of this UI Automation element.
GetCachedPattern(patternId) {
try {
if IsNumber(patternId)
name := UIA.ControlPattern.%patternId%
else
patternId := UIA.ControlPattern.%(name := patternId)%
ComCall(17, this, "int", patternId, "ptr*", &patternObject := 0)
return IUIAutomation%name%Pattern(patternObject)
}
}
; Retrieves from the cache the parent of this UI Automation element.
GetCachedParent() => (ComCall(18, this, "ptr*", &parent := 0), IUIAutomationElement(parent))
; Retrieves the cached child elements of this UI Automation element.
; The view of the returned collection is determined by the TreeFilter property of the IUIAutomationCacheRequest that was active when this element was obtained.
; Children are cached only if the scope of the cache request included TreeScope_Subtree, TreeScope_Children, or TreeScope_Descendants.
; If the cache request specified that children were to be cached at this level, but there are no children, the value of this property is 0. However, if no request was made to cache children at this level, an attempt to retrieve the property returns an error.
GetCachedChildren() => (ComCall(19, this, "ptr*", &children := 0), IUIAutomationElementArray(children))
; Retrieves the identifier of the process that hosts the element.
CurrentProcessId => (ComCall(20, this, "int*", &retVal := 0), retVal)
; Retrieves the control type of the element.
; Control types describe a known interaction model for UI Automation elements without relying on a localized control type or combination of complex logic rules. This property cannot change at run time unless the control supports the IUIAutomationMultipleViewPattern interface. An example is the Win32 ListView control, which can change from a data grid to a list, depending on the current view.
CurrentControlType => (ComCall(21, this, "int*", &retVal := 0), retVal)
; Retrieves a localized description of the control type of the element.
CurrentLocalizedControlType => (ComCall(22, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the name of the element.
CurrentName => (ComCall(23, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the accelerator key for the element.
CurrentAcceleratorKey => (ComCall(24, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the access key character for the element.
; An access key is a character in the text of a menu, menu item, or label of a control such as a button that activates the attached menu function. For example, the letter "O" is often used to invoke the Open file common dialog box from a File menu. Microsoft UI Automation elements that have the access key property set always implement the Invoke control pattern.
CurrentAccessKey => (ComCall(25, this, "ptr*", &retVal := 0), BSTR(retVal))
; Indicates whether the element has keyboard focus.
CurrentHasKeyboardFocus => (ComCall(26, this, "int*", &retVal := 0), retVal)
; Indicates whether the element can accept keyboard focus.
CurrentIsKeyboardFocusable => (ComCall(27, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates whether the element is enabled.
CurrentIsEnabled => (ComCall(28, this, "int*", &retVal := 0), retVal)
; Retrieves the Microsoft UI Automation identifier of the element.
; The identifier is unique among sibling elements in a container, and is the same in all instances of the application.
CurrentAutomationId => (ComCall(29, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the class name of the element.
; The value of this property is implementation-defined. The property is useful in testing environments.
CurrentClassName => (ComCall(30, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the help text for the element. This information is typically obtained from tooltips.
; Caution Do not retrieve the CachedHelpText property from a control that is based on the SysListview32 class. Doing so could cause the system to become unstable and data to be lost. A client application can discover whether a control is based on SysListview32 by retrieving the CachedClassName or CurrentClassName property from the control.
CurrentHelpText => (ComCall(31, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the culture identifier for the element.
CurrentCulture => (ComCall(32, this, "int*", &retVal := 0), retVal)
; Indicates whether the element is a control element.
CurrentIsControlElement => (ComCall(33, this, "int*", &retVal := 0), retVal)
; Indicates whether the element is a content element.
; A content element contains data that is presented to the user. Examples of content elements are the items in a list box or a button in a dialog box. Non-content elements, also called peripheral elements, are typically used to manipulate the content in a composite control; for example, the button on a drop-down control.
CurrentIsContentElement => (ComCall(34, this, "int*", &retVal := 0), retVal)
; Indicates whether the element contains a disguised password.
; This property enables applications such as screen-readers to determine whether the text content of a control should be read aloud.
CurrentIsPassword => (ComCall(35, this, "int*", &retVal := 0), retVal)
; Retrieves the window handle of the element.
CurrentNativeWindowHandle => (ComCall(36, this, "ptr*", &retVal := 0), retVal)
; Retrieves a description of the type of UI item represented by the element.
; This property is used to obtain information about items in a list, tree view, or data grid. For example, an item in a file directory view might be a "Document File" or a "Folder".
CurrentItemType => (ComCall(37, this, "ptr*", &retVal := 0), BSTR(retVal))
; Indicates whether the element is off-screen.
CurrentIsOffscreen => (ComCall(38, this, "int*", &retVal := 0), retVal)
; Retrieves a value that indicates the orientation of the element.
; This property is supported by controls such as scroll bars and sliders that can have either a vertical or a horizontal orientation.
CurrentOrientation => (ComCall(39, this, "int*", &retVal := 0), retVal)
; Retrieves the name of the underlying UI framework. The name of the UI framework, such as "Win32", "WinForm", or "DirectUI".
CurrentFrameworkId => (ComCall(40, this, "ptr*", &retVal := 0), BSTR(retVal))
; Indicates whether the element is required to be filled out on a form.
CurrentIsRequiredForForm => (ComCall(41, this, "int*", &retVal := 0), retVal)
; Retrieves the description of the status of an item in an element.
; This property enables a client to ascertain whether an element is conveying status about an item. For example, an item associated with a contact in a messaging application might be "Busy" or "Connected".
CurrentItemStatus => (ComCall(42, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the coordinates of the rectangle that completely encloses the element, in screen coordinates.
CurrentBoundingRectangle => (ComCall(43, this, "ptr", retVal := NativeArray(0, 4, "int")), { left: retVal[0], top: retVal[1], right: retVal[2], bottom: retVal[3] })
; This property maps to the Accessible Rich Internet Applications (ARIA) property.
; Retrieves the element that contains the text label for this element.
; This property could be used to retrieve, for example, the static text label for a combo box.
CurrentLabeledBy => (ComCall(44, this, "ptr*", &retVal := 0), IUIAutomationElement(retVal))
; Retrieves the Accessible Rich Internet Applications (ARIA) role of the element.
CurrentAriaRole => (ComCall(45, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the ARIA properties of the element.
CurrentAriaProperties => (ComCall(46, this, "ptr*", &retVal := 0), BSTR(retVal))
; Indicates whether the element contains valid data for a form.
CurrentIsDataValidForForm => (ComCall(47, this, "int*", &retVal := 0), retVal)
; Retrieves an array of elements for which this element serves as the controller.
CurrentControllerFor => (ComCall(48, this, "ptr*", &retVal := 0), IUIAutomationElementArray(retVal))
; Retrieves an array of elements that describe this element.
CurrentDescribedBy => (ComCall(49, this, "ptr*", &retVal := 0), IUIAutomationElementArray(retVal))
; Retrieves an array of elements that indicates the reading order after the current element.
CurrentFlowsTo => (ComCall(50, this, "ptr*", &retVal := 0), IUIAutomationElementArray(retVal))
; Retrieves a description of the provider for this element.
CurrentProviderDescription => (ComCall(51, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached ID of the process that hosts the element.
CachedProcessId => (ComCall(52, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates the control type of the element.
CachedControlType => (ComCall(53, this, "int*", &retVal := 0), retVal)
; Retrieves the cached localized description of the control type of the element.
CachedLocalizedControlType => (ComCall(54, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached name of the element.
CachedName => (ComCall(55, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached accelerator key for the element.
CachedAcceleratorKey => (ComCall(56, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached access key character for the element.
CachedAccessKey => (ComCall(57, this, "ptr*", &retVal := 0), BSTR(retVal))
; A cached value that indicates whether the element has keyboard focus.
CachedHasKeyboardFocus => (ComCall(58, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates whether the element can accept keyboard focus.
CachedIsKeyboardFocusable => (ComCall(59, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates whether the element is enabled.
CachedIsEnabled => (ComCall(60, this, "int*", &retVal := 0), retVal)
; Retrieves the cached UI Automation identifier of the element.
CachedAutomationId => (ComCall(61, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached class name of the element.
CachedClassName => (ComCall(62, this, "ptr*", &retVal := 0), BSTR(retVal))
;
CachedHelpText => (ComCall(63, this, "ptr*", &retVal := 0), BSTR(retVal))
; Retrieves the cached help text for the element.
CachedCulture => (ComCall(64, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates whether the element is a control element.
CachedIsControlElement => (ComCall(65, this, "int*", &retVal := 0), retVal)
; A cached value that indicates whether the element is a content element.
CachedIsContentElement => (ComCall(66, this, "int*", &retVal := 0), retVal)
; Retrieves a cached value that indicates whether the element contains a disguised password.
CachedIsPassword => (ComCall(67, this, "int*", &retVal := 0), retVal)