-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMY_API.pas
More file actions
695 lines (592 loc) · 16.2 KB
/
Copy pathMY_API.pas
File metadata and controls
695 lines (592 loc) · 16.2 KB
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
unit MY_API;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs,Lua,MyWindows,ActiveX,MSScriptControl_TLB, MMSystem,shellapi;
//MSScriptControl_TLB
procedure GetInt2(S:String; var x,y:Integer);
function CheckExit:boolean;
/////////////////////////////////////////////////////////
function API_print(L: plua_State): Integer; cdecl;
function API_stoprun(L: plua_State): Integer; cdecl;
//==键盘==
function API_KeyPress(L: plua_State): Integer; cdecl;
function API_KeyDown(L: plua_State): Integer; cdecl;
function API_KeyUp(L: plua_State): Integer; cdecl;
//==鼠标==
function API_LeftClick(L: plua_State): Integer; cdecl;
function API_RightClick(L: plua_State): Integer; cdecl;
function API_MiddleClick(L: plua_State): Integer; cdecl;
function API_LeftDoubleClick(L: plua_State): Integer; cdecl;
function API_LeftDown(L: plua_State): Integer; cdecl;
function API_LeftUp(L: plua_State): Integer; cdecl;
function API_RightDown(L: plua_State): Integer; cdecl;
function API_RightUp(L: plua_State): Integer; cdecl;
function API_MoveTo(L: plua_State): Integer; cdecl;
function API_MoveR(L: plua_State): Integer; cdecl;
//==其它===
function API_Sleep(L: plua_State): Integer; cdecl;
function API_Beep(L: plua_State): Integer; cdecl;
function API_messagebox(L: plua_State): Integer; cdecl;
function API_saystring(L: plua_State): Integer; cdecl;
function API_findpic(L: plua_State): Integer; cdecl;
function API_getpixelcolor(L: plua_State): Integer; cdecl;
function API_findcolor(L: plua_State): Integer; cdecl;
function API_findcolorex(L: plua_State): Integer; cdecl;
function API_comparecolore(L: plua_State): Integer; cdecl; //比较颜色
function API_readmemory(L: plua_State): Integer; cdecl;
//==API========
function API_FindWindow(L: plua_State): Integer; cdecl;
function API_SetWindowPos(L: plua_State): Integer; cdecl;
function API_GetTickCount(L: plua_State): Integer; cdecl;
function API_PlaySound(L: plua_State): Integer; cdecl;
function API_PostMessage(L: plua_State): Integer; cdecl;
function API_SendMessage(L: plua_State): Integer; cdecl;
function API_Execute(L: plua_State): Integer; cdecl;
implementation
uses Unit1,Run_script;
function CheckExit:boolean; {退出检测}
begin
result:=False;
if not Running then
begin
lua_error(L);
result:=True;
end;
end;
procedure GetInt2(S:String; var x,y:Integer);
var
i,_pos:Integer;
begin
_pos:=Pos(',',S);
i:=strtoint(Copy(s,1,_pos-1));
x:=i;
Delete(s,1,(_pos));
i:=strtoint(s);
Y:=i;
end;
//////////////////////////////////////////////
function API_stoprun(L: plua_State): Integer; cdecl;
begin
Running:=False;
CheckExit;
result := 0;
end;
function API_print(L: plua_State): Integer; cdecl;
var
I, N: Integer;
nr:pchar;
begin
N := lua_gettop(L);
for I := 1 to N do
log(lua_tostring(L, I),clLime);
result := 0;
end;
function API_KeyPress(L: plua_State): Integer; cdecl;
var
i,KEY,_count,t: Integer;
begin
KEY:=Trunc(lua_tonumber(L,1));
_count:=Trunc(lua_tonumber(L,2));
lua_pop(L,2); //移除栈顶的值。
for i:=1 to _count do
begin
if CheckExit then exit;
if Hardwork then
begin
KeyPressH(KEY);
end
else
begin
keybd_event(KEY,MapVirtualKey(KEY,0),0,0);
Sleep(20);
keybd_event(KEY,MapVirtualKey(KEY,0),KEYEVENTF_KEYUP,0);
end;
end;
// log(Format('按键: %d %d 次',[Key,_count]),clWhite);
result := 0;
end;
function API_KeyDown(L: plua_State): Integer; cdecl;
var
i,KEY,_count: Integer;
begin
KEY:=Trunc(lua_tonumber(L,1));
_count:=Trunc(lua_tonumber(L,2));
lua_pop(L,2); //移除栈顶的值。
if CheckExit then exit;
if Hardwork then
begin
KeyDownH(KEY);
end
else
begin
keybd_event(KEY,MapVirtualKey(KEY,0),0,0);
end;
//log(Format('按住键: %d %d 次',[Key,_count]),clWhite);
result := 0;
end;
function API_KeyUp(L: plua_State): Integer; cdecl;
var
i,KEY,_count: Integer;
begin
KEY:=Trunc(lua_tonumber(L,1));
_count:=Trunc(lua_tonumber(L,2));
lua_pop(L,2); //移除栈顶的值。
if CheckExit then exit;
if Hardwork then
begin
KeyUPH(KEY);
end
else
begin
keybd_event(KEY,MapVirtualKey(KEY,0),KEYEVENTF_KEYUP,0);
end;
//log(Format('弹起键: %d %d 次',[Key,_count]),clWhite);
result := 0;
end;
function API_LeftClick(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
for i:=1 to _count do
begin
if CheckExit then exit;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
sleep(10);
end;
//log(Format('左键单击: %d 次',[_count]),clWhite);
result := 0;
end;
function API_RightClick(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
for i:=1 to _count do
begin
if CheckExit then exit;
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
sleep(10);
end;
//log(Format('右键单击: %d 次',[_count]),clWhite);
result := 0;
end;
function API_MiddleClick(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
for i:=1 to _count do
begin
if CheckExit then exit;
mouse_event( MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
mouse_event( MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
sleep(10);
end;
//log(Format('中键单击: %d 次',[_count]),clWhite);
result := 0;
end;
function API_LeftDoubleClick(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
for i:=1 to _count do
begin
if CheckExit then exit;
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
sleep(10);
end;
// log(Format('左键双击: %d 次',[_count]),clWhite);
result := 0;
end;
function API_LeftDown(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
if CheckExit then exit;
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
// log(Format('左键按下: %d 次',[_count]),clWhite);
result := 0;
end;
function API_LeftUp(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
if CheckExit then exit;
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
//log(Format('左键弹起: %d 次',[_count]),clWhite);
result := 0;
end;
function API_RightDown(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
if CheckExit then exit;
mouse_event( MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
//log(Format('右键按下: %d 次',[_count]),clWhite);
result := 0;
end;
function API_RightUp(L: plua_State): Integer; cdecl;
var
i,_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
if CheckExit then exit;
mouse_event( MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
//log(Format('右键弹起: %d 次',[_count]),clWhite);
result := 0;
end;
function API_MoveTo(L: plua_State): Integer; cdecl;
var
X,Y: Integer;
begin
x:=Trunc(lua_tonumber(L,1));
y:=Trunc(lua_tonumber(L,2));
lua_pop(L,2);
if CheckExit then exit;
SetCursorPos(x,y);
// log(Format('鼠标移到到: %d,%d ',[X,Y]),clWhite);
result := 0;
end;
function API_MoveR(L: plua_State): Integer; cdecl;
var
_NOWPoint:Tpoint;
X,Y: Integer;
begin
x:=Trunc(lua_tonumber(L,1));
y:=Trunc(lua_tonumber(L,2));
lua_pop(L, 2);
if CheckExit then exit;
GetCursorPos(_NOWPoint); //得到当前鼠标坐标
SetCursorPos(_NOWPoint.X+x,_NOWPoint.Y+y);
//log(Format('相对鼠标移到: %d,%d ',[X,Y]),clWhite);
result := 0;
end;
function API_Sleep(L: plua_State): Integer; cdecl;
var
_count: Integer;
begin
_count:=Trunc(lua_tonumber(L,1));
lua_pop(L, 1);
if CheckExit then exit;
sleep(_count);
// log(Format('延时 %d 毫秒',[_count]),clWhite);
result := 0;
end;
function API_Beep(L: plua_State): Integer; cdecl;
begin
Beep;
result := 0;
end;
function API_messagebox(L: plua_State): Integer; cdecl;
var
_string:string;
i,n:Integer;
begin
N := lua_gettop(L);
for I := 1 to N do _string:=_string+' '+ lua_tostring(L, I) ;
if CheckExit then exit;
// log(Format('显示消息:%s',[_string]),clWhite);
MessageBox(0, PChar(_string), '提示', MB_OK + MB_ICONINFORMATION +
MB_TOPMOST);
result := 0;
end;
{procedure MYvbsInput(nr:string);
var
scr: TScriptControl;
begin
if CheckExit then exit;
CoInitialize(nil) ;
scr := TScriptControl.Create(nil);
scr.Language := 'VBScript';
scr.AddCode('dim obj');
scr.AddCode('set obj = createobject("WScript.Shell")');
scr.AddCode(format('call obj.SendKeys("%s")',[nr]));
CoUninitialize;
end; }
function API_saystring(L: plua_State): Integer; cdecl;
var
I, N: Integer;
_string:string;
begin
N := lua_gettop(L);
for I := 1 to N do
begin
if i=1 then _string:=lua_tostring(L, I) else
_string:=_string+ lua_tostring(L, I)
end;
// MYinput(_string);
// MYvbsInput(_string);
SendKeys(_string);
if CheckExit then exit;
//log(Format('输入:%s',[_string]),clWhite);
result := 0;
end;
procedure findpic(_string:string);
var
scr: TScriptControl;
FoundX,FoundY:integer;
begin
if CheckExit then exit;
CoInitialize(nil) ;
scr := TScriptControl.Create(nil);
scr.Language := 'VBScript';
scr.AddCode('dim x');
scr.AddCode('dim y');
scr.AddCode('dim obj');
scr.AddCode('set obj = createobject("QMDispatch.QMFunction")');
scr.AddCode(format('FoundPixel = obj.FindPic(%s)',[_string]));
scr.AddCode('x = CInt(FoundPixel / 8192)');
scr.AddCode('y = FoundPixel Mod 8192');
FoundX:=(scr.Eval('x'));
FoundY:=(scr.Eval('y'));
// showmessage(format('%d,%d',[FoundX,FoundY]))
// SetCursorPos(FoundX,FoundY);
lua_pushnumber(L,FoundX);
lua_pushnumber(L,FoundY);
CoUninitialize;
end;
function API_findpic(L: plua_State): Integer; cdecl;
var
scr: TScriptControl;
FoundX,FoundY:integer;
iLeft,iTop,iRight,iBottom:Integer;
szFileName:string;
fSimilar:Double;
begin
if CheckExit then exit;
iLeft:=Trunc(lua_tonumber(L,1));
iTop:=Trunc(lua_tonumber(L,2));
iRight:=Trunc(lua_tonumber(L,3));
iBottom:=Trunc(lua_tonumber(L,4));
szFileName:=lua_tostring(L,5);
fSimilar:=lua_tonumber(L,6);
lua_pop(L, 6);
findpic(Format('%d,%d,%d,%d,"%s",%s',[iLeft,iTop,iRight,iBottom,szFileName,FloatToStr(fSimilar)]));
// findpic('0,0,1024,768,"C:\神盾.bmp",1');
// scr.Free;
// CoUninitialize;
// log(Format('找图:%s',[_string]),clWhite);
result := 2;
end;
function API_getpixelcolor(L: plua_State): Integer; cdecl;
var
x,y: Integer;
DesktopDC: HDC;
TmpColor: integer;
begin
x:=Trunc(lua_tonumber(L,1));
y:=Trunc(lua_tonumber(L,2));
lua_pop(L,2); //移除栈顶的值。
if CheckExit then exit;
DesktopDC := GetWindowDC(GetDesktopWindow);
TmpColor := GetPixel(DesktopDC,x,y);
//log(Format('取色:%s',[_string]),clWhite);
lua_pushstring(L,pchar(inttohex(TmpColor,6)));
result := 1;
end;
function API_findcolor(L: plua_State): Integer; cdecl;
var
_string,cmd:string;
scr: TScriptControl;
FoundX,FoundY:integer;
Left,iTop,iRight,iBottom,rnd:Integer;
begin
CoInitialize(nil) ;
Left:=Trunc(lua_tonumber(L,1));
iTop:=Trunc(lua_tonumber(L,2));
iRight:=Trunc(lua_tonumber(L,3));
iBottom:=Trunc(lua_tonumber(L,4));
_string:=lua_tostring(L, 5);
rnd:=Trunc(lua_tonumber(L,6));
lua_pop(L, 6);
cmd:=format('%d,%d,%d,%d,"%s",%d',[Left,iTop,iRight,iBottom,_string,rnd]);
if CheckExit then exit;
scr := TScriptControl.Create(nil);
scr.Language := 'VBScript';
scr.AddCode('dim x');
scr.AddCode('dim y');
scr.AddCode('dim obj');
scr.AddCode('set obj = createobject("QMDispatch.QMFunction")');
scr.AddCode(format('FoundPixel = obj.FindColor(%s)',[cmd]));
scr.AddCode('x = CInt(FoundPixel / 8192)');
scr.AddCode('y = FoundPixel Mod 8192');
FoundX:=(scr.Eval('x'));
FoundY:=(scr.Eval('y'));
lua_pushnumber(L,FoundX);
lua_pushnumber(L,FoundY);
scr.Free;
CoUninitialize;
//log(Format('找色:%s',[_string]),clWhite);
result := 2;
end;
function API_findcolorex(L: plua_State): Integer; cdecl;
var
_string,cmd:string;
scr: TScriptControl;
FoundX,FoundY:integer;
Left,iTop,iRight,iBottom,rnd:Integer;
fSimilar:Double;
begin
CoInitialize(nil) ;
Left:=Trunc(lua_tonumber(L,1));
iTop:=Trunc(lua_tonumber(L,2));
iRight:=Trunc(lua_tonumber(L,3));
iBottom:=Trunc(lua_tonumber(L,4));
_string:=lua_tostring(L, 5);
rnd:=Trunc(lua_tonumber(L,6));
fSimilar:=lua_tonumber(L,7);
lua_pop(L,7);
cmd:=format('%d,%d,%d,%d,"%s",%d,%.1f',[Left,iTop,iRight,iBottom,_string,rnd,fSimilar]);
if CheckExit then exit;
scr := TScriptControl.Create(nil);
scr.Language := 'VBScript';
scr.AddCode('dim x');
scr.AddCode('dim y');
scr.AddCode('dim obj');
scr.AddCode('set obj = createobject("QMDispatch.QMFunction")');
scr.AddCode(format('FoundPixel = obj.FindColor(%s)',[cmd]));
scr.AddCode('x = CInt(FoundPixel / 8192)');
scr.AddCode('y = FoundPixel Mod 8192');
FoundX:=(scr.Eval('x'));
FoundY:=(scr.Eval('y'));
lua_pushnumber(L,FoundX);
lua_pushnumber(L,FoundY);
scr.Free;
CoUninitialize;
//log(Format('模糊找色:%s',[_string]),clWhite);
result := 2;
end;
function API_comparecolore(L: plua_State): Integer; cdecl; //比较颜色
var
r1,r2,g1,g2,b1,b2:byte;
Q1:word;
_string:string ;
c1,c2:TColor;
begin
_string:=lua_tostring(L,1) ;
c1:=StrToInt('$'+_string);
_string:=lua_tostring(L,2) ;
c2:=StrToInt('$'+_string);
lua_pop(L,2);
r1:=GetRValue(c1);
r2:=GetRValue(c2);
g1:=GetGValue(c1);
g2:=GetGValue(c2);
b1:=GetBValue(c1);
b2:=GetBValue(c2);
Q1:=abs(r1-r2)+abs(g1-g2)+abs(b1-b2);
lua_pushnumber(L,Q1);
result := 1;
end;
function API_readmemory(L: plua_State): Integer; cdecl;
var
_string:string;
begin
_string:=lua_tostring(L, 1);
lua_pop(L, 1);
if CheckExit then exit;
// log(Format('读内存:%s',[_string]),clWhite);
result := 0;
end;
//==============API==================
function API_FindWindow(L: plua_State): Integer; cdecl;
var
AWnd: Integer;
_string:string;
begin
AWnd:=0;
_string:=lua_tostring(L, 1);
lua_pop(L, 1);
if CheckExit then exit;
AWnd:=FindWindow(nil,PChar(_string));
lua_pushnumber(L,AWnd);
Result:=1;
end;
function API_SetWindowPos(L: plua_State): Integer; cdecl;
var
x,y: Integer;
AWnd: Integer;
begin
AWnd:=Trunc(lua_tonumber(L,1));
x:=Trunc(lua_tonumber(L,2));
y:=Trunc(lua_tonumber(L,3));
lua_pop(L,3); //移除栈顶的值。
if CheckExit then exit;
SetWindowPos(AWnd,0,x,y,0,0,1);
Result:=0;
end;
function API_GetTickCount(L: plua_State): Integer; cdecl;
begin
if CheckExit then exit;
lua_pushnumber(L,GetTickCount);
Result:=1;
end;
function API_PlaySound(L: plua_State): Integer; cdecl;
var
_string:string;
begin
_string:=lua_tostring(L, 1);
lua_pop(L, 1);
sndPlaySound(PChar(_string),SND_ASYNC);
Result:=0;
end;
function API_PostMessage(L: plua_State): Integer; cdecl;
var
_hWnd: HWND;
_Msg: UINT;
_wParam: WPARAM;
_lParam: LPARAM;
begin
_hWnd:=Trunc(lua_tonumber(L,1));
_Msg:=Trunc(lua_tonumber(L,2));
_wParam:=Trunc(lua_tonumber(L,3));
_lParam:=Trunc(lua_tonumber(L,4));
lua_pop(L,4); //移除栈顶的值。
PostMessage(_hWnd,_Msg,_wParam,_lParam);
Result:=0;
end;
function API_SendMessage(L: plua_State): Integer; cdecl;
var
_hWnd: HWND;
_Msg: UINT;
_wParam: WPARAM;
_lParam: LPARAM;
begin
_hWnd:=Trunc(lua_tonumber(L,1));
_Msg:=Trunc(lua_tonumber(L,2));
_wParam:=Trunc(lua_tonumber(L,3));
_lParam:=Trunc(lua_tonumber(L,4));
lua_pop(L,4); //移除栈顶的值。
SendMessage(_hWnd,_Msg,_wParam,_lParam);
Result:=0;
end;
function API_Execute(L: plua_State): Integer; cdecl;
var
_string:string;
begin
_string:=lua_tostring(L, 1);
lua_pop(L, 1);
// winexec
ShellExecute(0, pchar('open'), pchar(_string),'','',SW_SHOW);
result:=0;
end;
end.