-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleMultiThreading.au3
129 lines (109 loc) · 4.37 KB
/
SimpleMultiThreading.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
#cs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SMT - Simple Multi Threading ;;;
;;;;;;;;; By NoCow AKA Mea ;;;;;;;;;
;;;;;;;;; Revised by Jack Chen ;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Functions
_CreateThread("Function", "Param1", "Param2", ...)
Creates a new thread of a function in the script
Return: $PID of the new thread
_KillThread($PID)
Destroy the target Thread
Return: 1 for success. 0 for failed
_SetVar("var","value")
Set Global var to the value, Can be get with _GetVar()
_GetVar("var")
Get a variable set by _SetVar()
Examples
;=========================================================================================================
; move the mouse random to 1-500,1-500 and sleep 10secounds for show its multitasking
;=========================================================================================================
#include "SimpleMultiThreading.au3" ; Include the multithreaded libary maded by Mea(Aka NoCow)
$pid = _CreateThread("hookmouse") ; Start new thread with the function hookmouse()
Sleep(10000) ; Sleep in 10secounds
_KillThread($pid) ; Close the thread hookmouse()
Func hookmouse() ; Function hookmouse() start
While 1
MouseMove(Random(1,500),Random(1,500)) ; Move Mouse random on the screen
WEnd
EndFunc ; Function hookmouse() end
;=========================================================================================================
;=========================================================================================================
; Tooltip every 50milisecounds the variable text on 0,0 while change it every 4secound
; For then force the thread to close
;=========================================================================================================
#include "SimpleMultiThreading.au3"
_SetVar("text","hello with a foo in a boo")
$pid = _CreateThread("showtooltip")
Sleep(4000)
_SetVar("text","lol this is too easy")
Sleep(4000)
_SetVar("text",InputBox("What you want to our tooltip message?","Text: "))
Sleep(10000)
_KillThread($pid)
Func showtooltip()
While 1
ToolTip(_GetVar("text"),0,0)
Sleep(50)
WEnd
EndFunc
;=========================================================================================================
#ce
#NoTrayIcon
Global $__hwnd_vars
If $cmdline[0] > 0 And $cmdline[1] = "child_thread_by" Then
;MsgBox(0, "$CmdLineRaw", $CmdLineRaw )
$__hwnd_vars = HWnd($cmdline[2])
Local $i, $p = ""
For $i = 4 To $cmdline[0]
$p &= '"' & $cmdline[$i] & '",'
Next
$p = StringTrimRight($p, 1)
Execute($cmdline[3] & '(' & $p & ')')
Exit
EndIf
$__hwnd_vars = GUICreate("threaded by mea")
GUICtrlCreateEdit("", 0, 0)
Func _StartThread($function, $p1 = "", $p2 = "", $p3 = "", $p4 = "", $p5 = "", $p6 = "", $p7 = "", $p8 = "", $p9 = "", $p10 = "")
Local $i, $p, $para
For $i = 1 to 10
$p = Eval("p" & $i)
If StringInStr($p, " ") Then ; ´ø¿Õ¸ñµÄ²ÎÊý¼ÓÉÏÒýºÅ
$p = '"' & $p & '"'
EndIf
$para &= ' ' & $p
Next
$para = StringStripWS($para, 3)
If @Compiled Then
Return Run('"' & @AutoItExe & '" child_thread_by ' & $__hwnd_vars & ' ' & $function & ' ' & $para)
Else
Return Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" child_thread_by ' & $__hwnd_vars & ' ' & $function & ' ' & $para)
EndIf
EndFunc
Func _KillThread($thread)
Local $i
For $i = 1 To 3
ProcessClose($thread)
Sleep(50)
If Not ProcessExists($thread) Then ExitLoop
Next
Return SetError(Not ProcessExists($thread))
EndFunc
Func _SetVar($var, $it = "")
Local $text = ControlGetText($__hwnd_vars, "", "Edit1")
$text = StringRegExpReplace($text, "(?i)(?m)^" & $var & " .*$", $var & " " & $it)
If Not @extended Then
$text &= @CRLF & $var & " " & $it
EndIf
ControlSetText($__hwnd_vars, "", "Edit1", $text)
EndFunc
Func _GetVar($var)
Local $text = ControlGetText($__hwnd_vars, "", "Edit1")
Local $match = StringRegExp($text, "(?i)(?m)^" & $var & " (.*)$", 1)
If Not @error Then
Return SetError(0, 0, $match[0])
Else
Return SetError(1, 0, "")
EndIf
EndFunc