-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathmain.mm
85 lines (69 loc) · 3.33 KB
/
main.mm
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
/*
* Name: libSimulateTouch
* Author: iolate <[email protected]>
*
*/
#import <CoreGraphics/CoreGraphics.h>
#import "SimulateTouch.h"
#define PRINT_USAGE printf("[Usage]\n 1. Touch:\n %s touch x y [orientation]\n\n 2. Swipe:\n %s swipe fromX fromY toX toY [duration(0.3)] [orientation]\n\n 3. Button: \n %s button Type State\n\n[Example]\n # %s touch 50 100\n # %s swipe 50 100 100 200 0.5\n # %s button 0 1\n # %s button 1 0\n\n[Orientation]\n Portrait:1 UpsideDown:2 Right:3 Left:4\n\n[Button]\n Power:0 Home:1\n\n[State]\n Up/Raise:0 Down/Press:1\n\n", argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]);
int main(int argc, char **argv, char **envp) {
if (argc == 1) {
PRINT_USAGE;
return 0;
}
if (!strcmp(argv[1], "touch")) {
if (argc != 4 && argc != 5) {
PRINT_USAGE;
return 0;
}
if (argc == 4) {
int x = atoi(argv[2]);
int y = atoi(argv[3]);
int r = [SimulateTouch simulateTouch:0 atPoint:CGPointMake(x, y) withType:STTouchDown];
[SimulateTouch simulateTouch:r atPoint:CGPointMake(x, y) withType:STTouchUp];
}else if (argc == 5) {
int px = atoi(argv[2]);
int py = atoi(argv[3]);
CGPoint p = CGPointMake(px, py);
CGPoint rp = [SimulateTouch STWindowToScreenPoint:p withOrientation:atoi(argv[4])];
int r = [SimulateTouch simulateTouch:0 atPoint:rp withType:STTouchDown];
[SimulateTouch simulateTouch:r atPoint:rp withType:STTouchUp];
}
}else if (!strcmp(argv[1], "swipe")) {
if (argc < 6 || argc > 8) {
PRINT_USAGE;
return 0;
}
float duration = 0.3f;
if (argc == 6) {
CGPoint fromPoint = CGPointMake(atoi(argv[2]), atoi(argv[3]));
CGPoint toPoint = CGPointMake(atoi(argv[4]), atoi(argv[5]));
[SimulateTouch simulateSwipeFromPoint:fromPoint toPoint:toPoint duration:duration];
}else if (argc == 7) {
CGPoint fromPoint = CGPointMake(atoi(argv[2]), atoi(argv[3]));
CGPoint toPoint = CGPointMake(atoi(argv[4]), atoi(argv[5]));
duration = atof(argv[6]);
[SimulateTouch simulateSwipeFromPoint:fromPoint toPoint:toPoint duration:duration];
}else if (argc == 8) {
CGPoint pfromPoint = CGPointMake(atoi(argv[2]), atoi(argv[3]));
CGPoint ptoPoint = CGPointMake(atoi(argv[4]), atoi(argv[5]));
CGPoint fromPoint = [SimulateTouch STWindowToScreenPoint:pfromPoint withOrientation:atoi(argv[7])];
CGPoint toPoint = [SimulateTouch STWindowToScreenPoint:ptoPoint withOrientation:atoi(argv[7])];
duration = atof(argv[6]);
[SimulateTouch simulateSwipeFromPoint:fromPoint toPoint:toPoint duration:duration];
}
CFRunLoopRunInMode(kCFRunLoopDefaultMode , duration+0.1f, NO);
}else if (!strcmp(argv[1], "button")) {
if (argc != 4) {
PRINT_USAGE;
return 0;
}
int button = atoi(argv[2]);
int state = atoi(argv[3]);
[SimulateTouch simulateButton:button state:state];
}else{
PRINT_USAGE;
return 0;
}
return 0;
}