-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzjb-helper.ahk
388 lines (306 loc) · 9.95 KB
/
zjb-helper.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
; Note: This file is saved with UTF8 with BOM, which is the best encoding choice to write Unicode chars here.
; API:
; zjb_DelaySendInput(delay_sec, input_chars, is_fast_send:=true)
; Dsi_ShowGui()
AUTOEXEC_zjbhelper: ; Workaround for Autohotkey's ugly auto-exec feature. Must be first line.
; MUST DO: Change the above ahk label to a specific one, such as AUTOEXEC_foobar_ahk
; User can override this mapping in customize.ahk . Each element has three fields:
; [ "资金保登录帐号" , "登录密码" , "助记提示文字" ]
global g_zjb_UsrPwd_list := [ ["16688886666" , "123456" , "共享体验帐号" ]
, ["13700054321" , "" , "我的手机号" ] ; If you leave password empty, then the Ahk will prompt you for password.
, [ "" ] ]
global g_HwndDsi ; Dsi: Delay Send Input
global g_dsiDelaySec
global g_dsiDelayText
global g_dsiIsFastSend
global g_amstr_zjbMonitorKey := "ZJB: Monitor my keys"
global _g_zjb_UsrPwdMap := {} ; internal use
global zjb_OCR := Func("OCR")
; -- The function OCR() is available when you `#include <Vis2>` in _more_includes_.ahk
zjb_InitMonitorCommonKeys()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
return ; End of auto-execute section.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
zjb_DelaySendInput(delay_sec, input_chars, is_fast_send:=true)
{
static counter := new CDelayedSendInput
; Using `static` to ensure there is only one CDelayedSendInput object,
; so that there will be only one pending delayed input at any given time.
counter.Start(delay_sec, input_chars, is_fast_send)
}
;
; A class working with SetTimer... modified from an example from AHK chm `SecondCounter`
class CDelayedSendInput {
__New() {
this.count_down := 0
this.timer := ObjBindMethod(this, "Tick")
}
Start(delay_sec, input_chars, is_fast_send:=true) {
if(delay_sec<1) {
MsgBox, % Format("Wrong parameter: delay_sec={}", delay_sec)
return
}
if(!input_chars) {
MsgBox, % "input_chars is empty"
return
}
this.count_down := delay_sec
this.input_chars := input_chars
this.is_fast_send := is_fast_send
; Known limitation: SetTimer requires a plain variable reference.
timer := this.timer
SetTimer, % timer, 1000
dev_TooltipAutoClear(Format("zjb_DelaySendInput() counting down {} seconds.", this.count_down), 1000)
}
Stop() {
; To turn off the timer, we must pass the same object as before:
timer := this.timer
SetTimer, % timer, Off
}
; In this example, the timer calls this method:
Tick() {
--this.count_down
if(this.count_down>0) {
dev_TooltipAutoClear(Format("counting down: {}", this.count_down))
}
else {
if(this.is_fast_send) {
; dev_TooltipAutoClear("counting DONE")
SendInput, % "{Raw}" . this.input_chars
}
else {
Send, % "{Raw}" . this.input_chars
}
this.Stop()
}
}
}
;
; AHK GUI for launching zjb_DelaySendInput()
;
Dsi_ShowGui()
{
if(!g_HwndDsi) {
Dsi_CreateGui()
}
Gui, Dsi:Show, , % "zjb - Delay Send Input"
}
Dsi_HideGui()
{
Gui, Dsi:Hide
tooltip ; turn off possible dangling tooltip
}
Dsi_CreateGui()
{
Gui, Dsi:New ;Destroy old window if any
Gui, Dsi:+Hwndg_HwndDsi
Gui, Dsi:Font, s9 cBlack, Tahoma
Gui, Dsi:Add, Text, xm, % "&Delay seconds:"
Gui, Dsi:Add, Edit, x120 w160 yp vg_dsiDelaySec, % "3"
Gui, Dsi:Add, Text, xm, % "&Text to send:"
Gui, Dsi:Add, Edit, x120 w160 yp vg_dsiDelayText, % "abc"
Gui, Dsi:Add, Text, xm, % "Is fast-send:"
Gui, Dsi:Add, Radio, x120 yp Group Checked vg_dsiIsFastSend , % "&Yes (SendInput)"
Gui, Dsi:Add, Radio, x+10 yp , % "&No"
Gui, Dsi:Add, Button, xm y+10 w40 Default gDsi_BtnOK, % "OK"
}
Dsi_BtnOK()
{
; dev_TooltipAutoClear("Dsi_BtnOK", 1000)
Gui, Dsi:Submit
; MsgBox, % Format("Delay sec: {} | Text: {} | isFastSend: {}" , g_dsiDelaySec, g_dsiDelayText, g_dsiIsFastSend)
zjb_DelaySendInput(g_dsiDelaySec, g_dsiDelayText, g_dsiIsFastSend)
Dsi_HideGui()
}
DsiGuiEscape()
{
Dsi_HideGui()
}
;=========================================================================================
zjb_InitMonitorCommonKeys()
{
Menu, tray, add ; Creates a separator line.
Menu, TRAY, add, %g_amstr_zjbMonitorKey%, zjb_ToggleMonitorKey ; Creates a new menu item.
Menu, TRAY, add, % "ZJB: Show Delay-send-input GUI", Dsi_ShowGui
zjb_ToggleMonitorKey()
}
zjb_HookCommonKeys(is_hook)
{
commonkeys = abcdefghijklmnopqrstuvwxyz1234567890
Loop, parse, commonkeys
{
if(is_hook)
{
dev_DefineHotkey("~$" . A_LoopField , "zjb_HintMyKey", A_LoopField)
; This comon-key hooking looks something brutal and exclusive.
; Hope others don't do the same thing.
}
else
{
dev_UnDefineHotkey("~$" . A_LoopField , "zjb_HintMyKey")
}
}
}
zjb_HintMyKey(now_key)
{
dev_TooltipAutoClear(" " . now_key . " ")
Am_PlaySound("ding.wav")
}
zjb_ToggleMonitorKey()
{
static is_monitor := true
is_monitor := !is_monitor ; so the first time it is false
if(is_monitor) {
Menu, TRAY, Check, %g_amstr_zjbMonitorKey%
zjb_HookCommonKeys(true)
}
else {
Menu, TRAY, Uncheck, %g_amstr_zjbMonitorKey%
zjb_HookCommonKeys(false)
}
}
#If IsWinTitleMatchRegex("^(资金保)?登录$") ; 资金保 PC 登录窗口, "资金保登录" since 3.4.0+
_zjb_LoginFillerInit()
{
menu_title := "== 资金保登录自动填充 =="
Menu, ZJB_LoginFiller, Add, % menu_title, zjb_menu_null ; this acts as menu title
Menu, ZJB_LoginFiller, Disable, % menu_title
Menu, ZJB_LoginFiller, Add ; separator
n := g_zjb_UsrPwd_list.Length()
Loop, % n
{
usr := g_zjb_UsrPwd_list[A_Index][1]
pwd := g_zjb_UsrPwd_list[A_Index][2]
memo := g_zjb_UsrPwd_list[A_Index][3]
if(usr=="")
continue
menutext := Format("[ &{1} ] {2}", A_Index, usr)
if(memo) {
menutext .= Format("( {1} )", memo)
}
Menu, ZJB_LoginFiller, Add, % menutext, zjb_FillLoginNamePwd
obj := {}
obj.usr := usr
obj.pwd := pwd
_g_zjb_UsrPwdMap[menutext] := obj
; MsgBox, % usr . " | " . pwd
; MsgBox, % _g_zjb_UsrPwdMap[menutext].usr . " | " . _g_zjb_UsrPwdMap[menutext].pwd
}
}
zjb_menu_null()
{
}
F1:: zjb_LoginFiller_Launch()
zjb_LoginFiller_Launch()
{
static is_init_done := false
if(!is_init_done) {
_zjb_LoginFillerInit() ; Late init so that customize.ahk can override g_zjb_UsrPwd_list
is_init_done := true
}
; If only one user is present, just fill it.
; If 2+ users are present, pop up a menu to have user select one.
first_menutext := ""
count := 0
for key, obj in _g_zjb_UsrPwdMap
{
if(not first_menutext) {
first_menutext := key
}
count++
}
if(count==0) {
MsgBox, % "g_zjb_UsrPwd_list is empty. Nothing to fill for you."
}
else if(count==1) {
zjb_FillLoginNamePwd(first_menutext, 0, 0)
usr := _g_zjb_UsrPwdMap[first_menutext].usr
dev_TooltipAutoClear(Format("{1} 的帐号密码已自动填充", usr))
}
else {
Menu, ZJB_LoginFiller, Show
}
}
zjb_FillLoginNamePwd(ItemName, ItemPos, MenuName)
{
WinGet, Awinid, ID, A ; Get ZJB login UI hwnd first.
wintitle := "ahk_id " . Awinid
menutext := ItemName
username := _g_zjb_UsrPwdMap[menutext].usr
password := _g_zjb_UsrPwdMap[menutext].pwd
if(!password)
{
text := Format("请告知资金保帐号 {1} 的密码。此处输入的密码将只存放于内存中。", username)
InputBox, password, % "请设置密码", % text, HIDE
if(password) {
_g_zjb_UsrPwdMap[menutext].pwd := password
}
else {
return ; do nothing
}
}
; To make it solid, we need to wait until ZJB login UI becomes the active window again.
; This usually takes some or tens of milliseconds.
WinWaitActive, % wintitle, , 500
; But strange, I still need to sleep for some seconds, otherwise, arctls[] below will be empty.
Sleep, 100
/*
; Sample classNN for the (only) three editbox:
classnn_usr := "WindowsForms10.EDIT.app.0.202c6663"
classnn_pwd := "WindowsForms10.EDIT.app.0.202c6662"
classnn_humancode := "WindowsForms10.EDIT.app.0.202c6661"
classnn_ocrimage := "WindowsForms10.Window.8.app.0.202c6663"
But the actual trailing numbers may not be 202c666x, so I need to enumerate them.
*/
arctls := RegexClassnnFindControls("^WindowsForms10\.EDIT\.app.+")
nctls := arctls.Length()
; As observed, Autohotkey will return editbox-classNN in the order of small suffix number to big suffix number.
; So arctls[1].classnn=...202c6661 , arctls[2].classnn=...202c6662 , arctls[3].classnn=...202c6663 .
if(nctls!=3) {
MsgBox, % Format("zjb-helper.ahk : Fail to detect EDIT controls on this UI. nctls={1}", nctls)
return
}
classnn_usr := arctls[3].classnn
ControlFocus, % classnn_usr, % wintitle
ControlSetText, % classnn_usr, % username, % wintitle
classnn_pwd := arctls[2].classnn
ControlFocus, % classnn_pwd, % wintitle
ControlSetText, % classnn_pwd, % password, % wintitle
classnn_ocrimage := StrReplace(classnn_usr, "EDIT.app", "Window.8.app")
;Msgbox, % "classnn_ocrimage = " . classnn_ocrimage
ControlGet, hwnd_ocrimage, HWND, , % classnn_ocrimage, % wintitle ; output: hwnd_ocrimage
;Msgbox, % "ahkid_ocrimage = " . hwnd_ocrimage
if(zjb_OCR) {
ocrtext := zjb_OCR.Call("ahk_id " . hwnd_ocrimage)
;Msgbox, % "ocrtext = " . ocrtext
}
classnn_humancode := arctls[1].classnn
ControlFocus, % classnn_humancode, % wintitle
ControlSetText, % classnn_humancode, % ocrtext, % wintitle
;
}
/* Dead code
zjb_LoginOCR(input_spec)
{
; input_spec: "ahk_id 0x12345678"
fp_image := "ocr.bmp"
fp_screenshot := Vis2.stdlib.toFile(input_spec, fp_image)
this.convert_best(this.file, this.fileConvertedText)
text := this.getText(this.fileConvertedText)
}
*/
^F1:: zjb_ProbeEditClassnn() ; for debugging purpose
zjb_ProbeEditClassnn()
{
; Enumerate all EDIT controls, fill them with their respective classnn-s.
arctls := RegexClassnnFindControls("^WindowsForms10\.EDIT\.app.+")
nctls := arctls.Length()
Loop, % nctls
{
classnn := arctls[A_Index].classnn
text := RegExReplace(classnn, "^WindowsForms10\.", "")
ControlSetText, % classnn, % text, A
; dev_WriteLogFile("nctls.txt", . "`n")
}
}
#If