-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.cpp
More file actions
60 lines (47 loc) · 1.73 KB
/
user.cpp
File metadata and controls
60 lines (47 loc) · 1.73 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
#include "serial.h"
#include <stdio.h>
int main()
{
//serial init
Serial* serial = new Serial("COM9", 115200); // must change to yours
if (!serial->isConnected()) return 0;
char buf[255];
while (1) {
serial->readLine(buf, 255);
short ax, ay, az, cmd;
//파싱에 성공한 변수 return
int parsed = sscanf(buf, "%d,%d,%d,%d", &ax, &ay, &az, &cmd);
//if (parsed != 4) {
// continue; // If parsing failed or incomplete, skip to the next iteration
//}
int off_x = -(ax / 1000) * 3;
int off_y = (ay / 1000) * 3;
printf("mouse position: %d, %d, %d, %d\n", off_x, off_y, az, cmd);
if (az == 1) {
mouse_event(MOUSEEVENTF_LEFTDOWN, 10, 10, 0, 0); //왼쪽 누르기
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, 10, 10, 0, 0); //왼쪽 떼기
Sleep(500);
}
else if (az == 2) {
mouse_event(MOUSEEVENTF_RIGHTDOWN, 10, 10, 0, 0); //오른쪽 누르기
Sleep(100);
mouse_event(MOUSEEVENTF_RIGHTUP, 10, 10, 0, 0); //오른쪽 떼기
Sleep(500);
}
else if (az == 3) {
mouse_event(MOUSEEVENTF_LEFTDOWN, 10, 10, 0, 0); //왼쪽 누르기
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, 10, 10, 0, 0); //왼쪽 떼기
Sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN, 10, 10, 0, 0); //왼쪽 누르기
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP, 10, 10, 0, 0); //왼쪽 떼기
Sleep(500);
}
POINT p;
GetCursorPos(&p);
SetCursorPos(p.x + off_x, p.y + off_y);
}
return 0;
}