OSDN Git Service

v0.0.1 release
[winautomata/winautomata.git] / click.c
1 #include <windows.h>
2
3 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
4             PSTR lpCmdLine, int nCmdShow)
5 {
6     int button = 0; // 0:left 1:right 2:middle
7
8     char buf[256];
9     char* p2 = buf;
10     char* p = lpCmdLine;
11     while(1) {
12         if(*p == ' ' || *p == 0) {
13             *p2 = 0;
14             
15             if(strcmp(buf, "-left") == 0) {
16                 button = 0;
17             }
18             else if(strcmp(buf, "-right") == 0) {
19                 button = 1;
20             }
21             else if(strcmp(buf, "-middle") == 0) {
22                 button = 2;
23             }
24
25             if(*p == 0) break;
26
27             p++;
28             p2 = buf;
29         }
30         else {
31             if(p2 - buf < 255) {
32                 *p2++ = *p++;
33             }
34             else {
35                 p++;
36             }
37         }
38     }
39
40     INPUT inputs[2];
41
42     if(button == 2) {
43         inputs[0].type = INPUT_MOUSE;
44
45         inputs[0].mi.dx = 0;
46         inputs[0].mi.dy = 0;
47         inputs[0].mi.mouseData = 0;
48         inputs[0].mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
49         inputs[0].mi.time = 0;
50         inputs[0].mi.dwExtraInfo = 0;
51         
52         inputs[1].type = INPUT_MOUSE;
53
54         inputs[1].mi.dx = 0;
55         inputs[1].mi.dy = 0;
56         inputs[1].mi.mouseData = 0;
57         inputs[1].mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
58         inputs[1].mi.time = 0;
59         inputs[1].mi.dwExtraInfo = 0;
60     }
61     else if(button == 1) {
62         inputs[0].type = INPUT_MOUSE;
63
64         inputs[0].mi.dx = 0;
65         inputs[0].mi.dy = 0;
66         inputs[0].mi.mouseData = 0;
67         inputs[0].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
68         inputs[0].mi.time = 0;
69         inputs[0].mi.dwExtraInfo = 0;
70         
71         inputs[1].type = INPUT_MOUSE;
72
73         inputs[1].mi.dx = 0;
74         inputs[1].mi.dy = 0;
75         inputs[1].mi.mouseData = 0;
76         inputs[1].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
77         inputs[1].mi.time = 0;
78         inputs[1].mi.dwExtraInfo = 0;
79     }
80     else {
81         inputs[0].type = INPUT_MOUSE;
82
83         inputs[0].mi.dx = 0;
84         inputs[0].mi.dy = 0;
85         inputs[0].mi.mouseData = 0;
86         inputs[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
87         inputs[0].mi.time = 0;
88         inputs[0].mi.dwExtraInfo = 0;
89         
90         inputs[1].type = INPUT_MOUSE;
91
92         inputs[1].mi.dx = 0;
93         inputs[1].mi.dy = 0;
94         inputs[1].mi.mouseData = 0;
95         inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
96         inputs[1].mi.time = 0;
97         inputs[1].mi.dwExtraInfo = 0;
98     }
99
100     SendInput(2, inputs, sizeof(INPUT));
101
102     return 0;
103 }
104