-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path4. Async.ahk
50 lines (43 loc) · 1.3 KB
/
4. Async.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
; In my country, the connection to deepl is very unstable, it usually takes 5-30 seconds to get result.
; This means that your code will be stuck for 5-30 seconds at the same time (because it is waiting for the result).
; Using asynchronous mode, you can avoid this situation.
; If you don't use asynchronous mode, the program will get stuck on the next line for 5-30 seconds before it can run the code that follows.
DeepLTranslator.init(,,,"async")
; Get initialization result.
loop
{
; Because asynchronous mode is used, you can do whatever you want first, and then check the result.
; Here we will display some information dynamically.
ellipsis.="."
; By the way, there is a library called BTT, which is as easy to use as ToolTip but more powerful.
; https://github.com/telppa/BeautifulToolTip
ToolTip, Initializing%ellipsis%
if (DeepLTranslator.getInitResult())
{
MsgBox, Initialization succeeded
break
}
else
Sleep, 1000
}
ret := DeepLTranslator.translate("Hello my love",,,"async")
if (ret.Error)
{
MsgBox, % ret.Error
ExitApp
}
; Get translation result.
loop
{
ellipsis2.="."
ToolTip, Translating%ellipsis2%
if (DeepLTranslator.getTransResult())
{
MsgBox, % DeepLTranslator.getTransResult()
break
}
else
Sleep, 1000
}
ExitApp
#Include <DeepLTranslator>