-
Notifications
You must be signed in to change notification settings - Fork 64
/
publicAPI.ahk
155 lines (125 loc) · 3.64 KB
/
publicAPI.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
/*
This function file helps any AHK script to use Clipjump API functions from its side.
Just include this file in your script.
Note that API.text2binary() is not supported currently.
The ClipjumpCommunicator.ahk file is already included in this file.
v 15.5.17
*/
/*
EXAMPLES
(It is necessary to initialize the object with "new")
cj := new Clipjump()
cj.IncognitoMode(1)
cj.pasteText("some text")
msgbox % cj.getClipLoc(1, 5)
cj.Paste("","")
cj["CALLER"] := 0
cj["STORE.somevar"] := "abc value"
msgbox % cj.getVar("version")
msgbox % cj.version
*/
;cj := new Clipjump()
;cj.runFunction("set_pformat(NO-FORMATTING)")
;cj.getClipAt(0, 7)
;msgbox % cj.author_page
class Clipjump
{
__New(){
}
__Call(funcname, parameters*){
cbF := A_temp "\cjcb.txt"
rFuncs := "|getClipAt|getClipLoc|getVar|runFunction|"
resChar := "`r"
ps := ""
for key,val in parameters
{
StringReplace, val, val, % "`r`n", % "`n", All
StringReplace, val, val, % "`r", % "`n", All
ps .= resChar val
}
FileDelete, % cbF
returned := CjControl("API:" funcName ps)
if (returned>0) && Instr(rFuncs, "|" funcName "|")
{
Clipjump_wait4file()
Fileread, out, % cbF
FileDelete, % cbF
return out
}
else return ""
}
/*
Use -
cj := new Clipjump()
msgbox % cj.version
*/
__Get(var){
return this.getVar(var)
}
/*
Use -
cj := new Clipjump()
cj["pastemodekey.z"] := "y"
cj.MYVAR := "value"
*/
__Set(var, value){
this.setVar(var, value)
}
;-----------------------------------------------------------------------------------------
;------------------------------------------- END -----------------------------------------
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
Clipjump_wait4file(){
while !FileExist(A_temp "\cjcb.txt")
sleep 15
}
;---------------------- Clipjump Communicator.ahk ---------------------------------------------
CjControl(ByRef Code)
{
global
local IsExe, TargetScriptTitle, CopyDataStruct, Prev_DetectHiddenWindows, Prev_TitleMatchMode, Z, S
if ! (IsExe := CjControl_check())
return -1 ;Clipjump doesn't exist
TargetScriptTitle := "Clipjump" (IsExe==1 ? ".ahk ahk_class AutoHotkey" : ".exe ahk_class AutoHotkey")
VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
SizeInBytes := (StrLen(Code) + 1) * (A_IsUnicode ? 2 : 1)
NumPut(SizeInBytes, CopyDataStruct, A_PtrSize)
NumPut(&Code, CopyDataStruct, 2*A_PtrSize)
Prev_DetectHiddenWindows := A_DetectHiddenWindows
Prev_TitleMatchMode := A_TitleMatchMode
DetectHiddenWindows On
SetTitleMatchMode 2
Z := 0
while !Z
{
SendMessage, 0x4a, 0, &CopyDataStruct,, %TargetScriptTitle%
Z := ErrorLevel
if (Z == "FAIL")
Z := ""
if A_index>100
return -1 ;Timeout..
}
DetectHiddenWindows %Prev_DetectHiddenWindows%
SetTitleMatchMode %Prev_TitleMatchMode%
while !FileExist(A_temp "\clipjumpcom.txt")
{
if (A_index>40) ;2 secs total
if !CjControl_check()
return -1
sleep 50
;Tooltip, % "waiting for clipjumpcom"
}
FileDelete % A_temp "\clipjumpcom.txt"
;ToolTip
return 1 ;True
}
CjControl_check(){
HW := A_DetectHiddenWindows , TM := A_TitleMatchMode
DetectHiddenWindows, On
SetTitleMatchMode, 2
A := WinExist("\Clipjump.ahk - ahk_class AutoHotkey")
E := WinExist("\Clipjump.exe - ahk_class AutoHotkey")
DetectHiddenWindows,% HW
SetTitleMatchMode,% TM
return A ? 1 : (E ? 2 : 0)
}