OSDN Git Service

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