forked from sgharvey/pakon-tlx-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLX_Controller.au3
385 lines (346 loc) · 12.6 KB
/
TLX_Controller.au3
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
#include <MsgBoxConstants.au3>
#Include <GuiSlider.au3>
Const $hotkeyTerminate = "+{ESC}" ; Shift + Escape
Const $hotkeyNextImage = "{RIGHT}" ; Right arrow
Const $hotkeyPrevImage = "{LEFT}" ; Left arrow
Const $hotkeyRotateLeft = "z" ; Plain lowercase z
Const $hotkeyRotateRight = "x" ; Plain lowercase x
Const $hotkeyPicSelected = "{DOWN}" ; Down arrow
Const $hotkeyPicNotSelected = "{UP}" ; Up arrow
Const $hotkeyRedPlus = "{INS}" ; Insert
Const $hotkeyRedMinus = "{DEL}" ; Delete
Const $hotkeyGreenPlus = "{HOME}"
Const $hotkeyGreenMinus = "{END}"
Const $hotkeyBluePlus = "{PGUP}" ; Page Up
Const $hotkeyBlueMinus = "{PGDN}" ; Page Down
Const $hotkeyBrightPlus = "u" ; Plain lowercase u
Const $hotkeyBrightMinus = "j" ; Plain lowercase j
Const $hotkeyContrastPlus = "i" ; Plain lowercase i ("eye")
Const $hotkeyContrastMinus = "k" ; Plain lowercase k
Const $hotkeySharpPlus = "o" ; Plain lowercase o ("oh" not number zero)
Const $hotkeySharpMinus = "l" ; Plain lowercase l ("ell" not number one)
;; Change adjustment sizes here.
;; The ranges of these slider is 2000 units.
Const $iAdjLg = 100 ; How much is a Large slider adjustment?
Const $iAdjMd = 50 ; How much is a Medium slider adjustment?
Const $iAdjSm = 10 ; How much is a Small slider adjustment?
Const $titleTLX = "TLXClientDemo"
Const $idRotateComboList = 1020
Const $textRotateLeft = "90 Left"
Const $textRotateRight = "90 Right"
Const $textRotate180 = "180"
Const $textRotateMirror = "Mirror"
Const $idRotateButton = 1018
Const $titleColor = "Color Adjustment"
Const $idColorButton = 1074
Const $idColorRedSlider = 1072
Const $instColorRedSlider = 1
Const $idColorGreenSlider = 1076
Const $instColorGreenSlider = 2
Const $idColorBlueSlider = 1078
Const $instColorBlueSlider = 3
Const $idColorBrightSlider = 1080
Const $instColorBrightSlider = 4
Const $idColorContrastSlider = 1082
Const $instColorContrastSlider = 5
Const $idColorSharpSlider = 1083
Const $instColorSharpSlider = 6
Const $idColorOkButton = 1
Const $idPrevButton = 1007
Const $idNextButton = 1006
Const $idPicNotSelectedRadio = 1060
Const $idPicSelectedRadio = 1061
Const $idPicHiddenRadio = 1062
; Get necessary handles and ranges for adjustment sliders.
$hColorRedSlider = 0
$aColorRedRange = 0
$hColorGreenSlider = 0
$aColorGreenRange = 0
$hColorBlueSlider = 0
$aColorBlueRange = 0
$hColorBrightSlider = 0
$aColorBrightRange = 0
$hColorContrastSlider = 0
$aColorContrastRange = 0
$hColorSharpSlider = 0
$aColorSharpRange = 0
HotKeySet($hotkeyTerminate, "Terminate") ; Press this key to terminate the controller.
Func Terminate()
Exit
EndFunc
; Previous / Next image
; Left arrow: Previous
; Right arrow: Next
HotKeySet($hotkeyNextImage, "NextImage")
Func NextImage()
ControlClick ($titleTLX, "", $idNextButton, "primary")
closeAdjustmentWindow()
openAdjustmentWindow()
EndFunc
HotKeySet($hotkeyPrevImage, "PrevImage")
Func PrevImage()
ControlClick ($titleTLX, "", $idPrevButton, "primary")
closeAdjustmentWindow()
openAdjustmentWindow()
EndFunc
; Rotation HotKeys.
; The 'z' key rotates anti-clockwise,
; The 'x' key rotates clockwise.
HotKeySet($hotkeyRotateLeft, RotateLeft)
Func RotateLeft()
Rotate($textRotateLeft)
EndFunc
HotKeySet($hotkeyRotateRight, RotateRight)
Func RotateRight()
Rotate($textRotateRight)
EndFunc
; Picture selection HotKeys
; Up arrow: Selected
; Down arrow: Not selected
HotKeySet($hotkeyPicSelected, "PicSelected")
Func PicSelected()
ControlClick($titleTLX, "", $idPicSelectedRadio, "primary")
EndFunc
HotKeySet($hotkeyPicNotSelected, "PicNotSelected")
Func PicNotSelected()
ControlClick($titleTLX, "", $idPicNotSelectedRadio, "primary")
EndFunc
; Color correction HotKeys.
; Color : +, -
; Red : Insert, Delete
; Green : Home, End
; Blue : Page Up, Page Down
HotKeySet($hotkeyRedPlus, "RedPlusLarge")
Func RedPlusLarge()
SetSliderPosRel($hColorRedSlider, $iAdjLg, $aColorRedRange)
EndFunc
HotKeySet("+" & $hotkeyRedPlus, "RedPlusMedium")
Func RedPlusMedium()
SetSliderPosRel($hColorRedSlider, $iAdjMd, $aColorRedRange)
EndFunc
HotKeySet("^" & $hotkeyRedPlus, "RedPlusSmall")
Func RedPlusSmall()
SetSliderPosRel($hColorRedSlider, $iAdjSm, $aColorRedRange)
EndFunc
HotKeySet($hotkeyRedMinus, "RedMinusLarge")
Func RedMinusLarge()
SetSliderPosRel($hColorRedSlider, $iAdjLg * -1, $aColorRedRange)
EndFunc
HotKeySet("+" & $hotkeyRedMinus, "RedMinusMedium")
Func RedMinusMedium()
SetSliderPosRel($hColorRedSlider, $iAdjMd * -1, $aColorRedRange)
EndFunc
HotKeySet("^" & $hotkeyRedMinus, "RedMinusSmall")
Func RedMinusSmall()
SetSliderPosRel($hColorRedSlider, $iAdjSm * -1, $aColorRedRange)
EndFunc
HotKeySet($hotkeyGreenPlus, "GreenPlusLarge")
Func GreenPlusLarge()
SetSliderPosRel($hColorGreenSlider, $iAdjLg, $aColorGreenRange)
EndFunc
HotKeySet("+" & $hotkeyGreenPlus, "GreenPlusMedium")
Func GreenPlusMedium()
SetSliderPosRel($hColorGreenSlider, $iAdjMd, $aColorGreenRange)
EndFunc
HotKeySet("^" & $hotkeyGreenPlus, "GreenPlusSmall")
Func GreenPlusSmall()
SetSliderPosRel($hColorGreenSlider, $iAdjSm, $aColorGreenRange)
EndFunc
HotKeySet($hotkeyGreenMinus, "GreenMinusLarge")
Func GreenMinusLarge()
SetSliderPosRel($hColorGreenSlider, $iAdjLg * -1, $aColorGreenRange)
EndFunc
HotKeySet("+" & $hotkeyGreenMinus, "GreenMinusMedium")
Func GreenMinusMedium()
SetSliderPosRel($hColorGreenSlider, $iAdjMd * -1, $aColorGreenRange)
EndFunc
HotKeySet("^" & $hotkeyGreenMinus, "GreenMinusSmall")
Func GreenMinusSmall()
SetSliderPosRel($hColorGreenSlider, $iAdjSm * -1, $aColorGreenRange)
EndFunc
HotKeySet($hotkeyBluePlus, "BluePlusLarge")
Func BluePlusLarge()
SetSliderPosRel($hColorBlueSlider, $iAdjLg, $aColorBlueRange)
EndFunc
HotKeySet("+" & $hotkeyBluePlus, "BluePlusMedium")
Func BluePlusMedium()
SetSliderPosRel($hColorBlueSlider, $iAdjMd, $aColorBlueRange)
EndFunc
HotKeySet("^" & $hotkeyBluePlus, "BluePlusSmall")
Func BluePlusSmall()
SetSliderPosRel($hColorBlueSlider, $iAdjSm, $aColorBlueRange)
EndFunc
HotKeySet($hotkeyBlueMinus, "BlueMinusLarge")
Func BlueMinusLarge()
SetSliderPosRel($hColorBlueSlider, $iAdjLg * -1, $aColorBlueRange)
EndFunc
HotKeySet("+" & $hotkeyBlueMinus, "BlueMinusMedium")
Func BlueMinusMedium()
SetSliderPosRel($hColorBlueSlider, $iAdjMd * -1, $aColorBlueRange)
EndFunc
HotKeySet("^" & $hotkeyBlueMinus, "BlueMinusSmall")
Func BlueMinusSmall()
SetSliderPosRel($hColorBlueSlider, $iAdjSm * -1, $aColorBlueRange)
EndFunc
;Brightness
HotKeySet($hotkeyBrightPlus, "BrightPlusLarge")
Func BrightPlusLarge()
SetSliderPosRel($hColorBrightSlider, $iAdjLg, $aColorBrightRange)
EndFunc
HotKeySet("+" & $hotkeyBrightPlus, "BrightPlusMedium")
Func BrightPlusMedium()
SetSliderPosRel($hColorBrightSlider, $iAdjMd, $aColorBrightRange)
EndFunc
HotKeySet("^" & $hotkeyBrightPlus, "BrightPlusSmall")
Func BrightPlusSmall()
SetSliderPosRel($hColorBrightSlider, $iAdjSm, $aColorBrightRange)
EndFunc
HotKeySet($hotkeyBrightMinus, "BrightMinusLarge")
Func BrightMinusLarge()
SetSliderPosRel($hColorBrightSlider, $iAdjLg * -1, $aColorBrightRange)
EndFunc
HotKeySet("+" & $hotkeyBrightMinus, "BrightMinusMedium")
Func BrightMinusMedium()
SetSliderPosRel($hColorBrightSlider, $iAdjMd * -1, $aColorBrightRange)
EndFunc
HotKeySet("^" & $hotkeyBrightMinus, "BrightMinusSmall")
Func BrightMinusSmall()
SetSliderPosRel($hColorBrightSlider, $iAdjSm * -1, $aColorBrightRange)
EndFunc
;Contrast
HotKeySet($hotkeyContrastPlus, "ContrastPlusLarge")
Func ContrastPlusLarge()
SetSliderPosRel($hColorContrastSlider, $iAdjLg, $aColorContrastRange)
EndFunc
HotKeySet("+" & $hotkeyContrastPlus, "ContrastPlusMedium")
Func ContrastPlusMedium()
SetSliderPosRel($hColorContrastSlider, $iAdjMd, $aColorContrastRange)
EndFunc
HotKeySet("^" & $hotkeyContrastPlus, "ContrastPlusSmall")
Func ContrastPlusSmall()
SetSliderPosRel($hColorContrastSlider, $iAdjSm, $aColorContrastRange)
EndFunc
HotKeySet($hotkeyContrastMinus, "ContrastMinusLarge")
Func ContrastMinusLarge()
SetSliderPosRel($hColorContrastSlider, $iAdjLg * -1, $aColorContrastRange)
EndFunc
HotKeySet("+" & $hotkeyContrastMinus, "ContrastMinusMedium")
Func ContrastMinusMedium()
SetSliderPosRel($hColorContrastSlider, $iAdjMd * -1, $aColorContrastRange)
EndFunc
HotKeySet("^" & $hotkeyContrastMinus, "ContrastMinusSmall")
Func ContrastMinusSmall()
SetSliderPosRel($hColorContrastSlider, $iAdjSm * -1, $aColorContrastRange)
EndFunc
;Sharpness
HotKeySet($hotkeySharpPlus, "SharpPlusLarge")
Func SharpPlusLarge()
SetSliderPosRel($hColorSharpSlider, $iAdjLg, $aColorSharpRange)
EndFunc
HotKeySet("+" & $hotkeySharpPlus, "SharpPlusMedium")
Func SharpPlusMedium()
SetSliderPosRel($hColorSharpSlider, $iAdjMd, $aColorSharpRange)
EndFunc
HotKeySet("^" & $hotkeySharpPlus, "SharpPlusSmall")
Func SharpPlusSmall()
SetSliderPosRel($hColorSharpSlider, $iAdjSm, $aColorSharpRange)
EndFunc
HotKeySet($hotkeySharpMinus, "SharpMinusLarge")
Func SharpMinusLarge()
SetSliderPosRel($hColorSharpSlider, $iAdjLg * -1, $aColorSharpRange)
EndFunc
HotKeySet("+" & $hotkeySharpMinus, "SharpMinusMedium")
Func SharpMinusMedium()
SetSliderPosRel($hColorSharpSlider, $iAdjMd * -1, $aColorSharpRange)
EndFunc
HotKeySet("^" & $hotkeySharpMinus, "SharpMinusSmall")
Func SharpMinusSmall()
SetSliderPosRel($hColorSharpSlider, $iAdjSm * -1, $aColorSharpRange)
EndFunc
Func openAdjustmentWindow()
If Not WinExists($titleColor) Then
; Make TLX window active.
WinActivate($titleTLX)
; Open the Color Adjustment window.
ControlClick($titleTLX, "", $idColorButton, "primary")
Else
WinActivate($titleColor)
EndIf
WinWaitActive($titleColor)
; Move the Color Adjustment window into the upper left corner.
$posColor = WinGetPos($titleColor)
If $posColor[0] <> 0 Or $posColor[1] <> 0 Then
WinMove($titleColor, "", 0, 0)
EndIf
; Get necessary handles and ranges for adjustment sliders.
$hColorRedSlider = GetSliderHandle($titleColor, $instColorRedSlider)
$aColorRedRange = GetSliderRange($hColorRedSlider)
$hColorGreenSlider = GetSliderHandle($titleColor, $instColorGreenSlider)
$aColorGreenRange = GetSliderRange($hColorGreenSlider)
$hColorBlueSlider = GetSliderHandle($titleColor, $instColorBlueSlider)
$aColorBlueRange = GetSliderRange($hColorBlueSlider)
$hColorBrightSlider = GetSliderHandle($titleColor, $instColorBrightSlider)
$aColorBrightRange = GetSliderRange($hColorBrightSlider)
$hColorContrastSlider = GetSliderHandle($titleColor, $instColorContrastSlider)
$aColorContrastRange = GetSliderRange($hColorContrastSlider)
$hColorSharpSlider = GetSliderHandle($titleColor, $instColorSharpSlider)
$aColorSharpRange = GetSliderRange($hColorSharpSlider)
EndFunc
Func closeAdjustmentWindow()
If Not WinExists($titleColor) Then
Return
EndIf
WinActivate($titleColor)
ControlClick($titleColor, "OK", $idColorOkButton, "primary")
EndFunc
openAdjustmentWindow()
; main() where all the action happens until termination HotKey is pressed.
While 1
Sleep(50)
WEnd
; Rotate current image ($textRotate...)
Func Rotate($textRotationDirection)
ControlCommand($titleTLX, "", $idRotateComboList, "SelectString", $textRotationDirection) ; select combobox option
ControlClick($titleTLX, "", $idRotateButton) ; activate selection
EndFunc
; Set position of a slider, then send an arrow key to trip the signal.
; If you don't fake a bit of user input, the app won't acknowledge the slider position change.
Func SetSliderPosAbs($hSlider, $iPos)
If $iPos > 0 Then
_GUICtrlSlider_SetPos($hSlider, $iPos - 1)
ControlSend($titleColor, "", $hSlider, "{RIGHT}")
Else
_GUICtrlSlider_SetPos($hSlider, $iPos)
ControlSend($titleColor, "", $hSlider, "{LEFT}")
EndIf
EndFunc
; Get handle of a msctls_trackbar32 slider by window title and instance number.
Func GetSliderHandle($titleWindow, $instSlider)
Return ControlGetHandle($titleWindow, "", "[CLASS:msctls_trackbar32;INSTANCE:" & $instSlider & "]")
EndFunc
; Adds $relPos to current position of $hSlider.
Func SetSliderPosRel($hSlider, $relPos, $aRange)
$curPos = GetSliderPos($hSlider)
$filteredRelPos = FilterRelPos($relPos, $curPos, $aRange)
SetSliderPosAbs($hSlider, $filteredRelPos)
EndFunc
; Combines current value and relative adjustment,
; then forces the new value to be inside the given range.
; (Int, Int, Int[2])
Func FilterRelPos($relPos, $curPos, $aRange)
$newPos = $relPos + $curPos
If $newPos < $aRange[0] Then
return $aRange[0]
ElseIf $newPos > $aRange[1] Then
return $aRange[1]
Else
return $newPos
EndIf
EndFunc
;; Convenience / sugar
Func GetSliderPos($hSlider)
Return _GUICtrlSlider_GetPos($hSlider)
EndFunc
Func GetSliderRange($hSlider)
Return _GUICtrlSlider_GetRange($hSlider)
EndFunc