-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSUI.h
More file actions
139 lines (122 loc) · 3.53 KB
/
SUI.h
File metadata and controls
139 lines (122 loc) · 3.53 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
// Single-Header Library for Simulating user input
// Putting it on GitHub so i can always download
// it if I get a new computer
#pragma once
// Defines so you dont have to remember left and right click are 1 and 2
#define MOUSE_LEFT_CLICK 1
#define MOUSE_RIGHT_CLICK 2
// Include Windows.h, wont work on unix systems ¯\_(ツ)_/¯
#ifndef _WINDOWS_
#include <Windows.h>
#endif
#ifdef __cplusplus
class SUI {
private:
// Input variable, private so nobody changes it without Init().
INPUT _input;
public:
// Function for initializing SUI
void Init(int mode) {
if(mode>1) {
return;
}
_input.type = mode;
if(mode == 0) {
_input.mi.time = 0;
_input.mi.mouseData = 0;
_input.mi.dwExtraInfo = 0;
}
if(mode == 1) {
_input.ki.wScan = 0;
_input.ki.time = 0;
_input.ki.dwExtraInfo = 0;
}
}
// Moving cursor pos. its just SetCursorPos, but it would have been weird if we didnt have something for this ¯\_(ツ)_/¯
void MoveCursor(int x, int y) {
SetCursorPos(x, y);
}
// Click mouse button
void ClickMouse(int button) {
if(button == 1) {
_input.mi.dwFlags = 2;
SendInput(1, &_input, sizeof(INPUT));
_input.mi.dwFlags = 4;
SendInput(1, &_input, sizeof(INPUT));
}
else
if(button == 2) {
_input.mi.dwFlags = 8;
SendInput(1, &_input, sizeof(INPUT));
_input.mi.dwFlags = 10;
SendInput(1, &_input, sizeof(INPUT));
} else {
return;
}
}
// Keyboard input
void PressKey(int keycode) {
if(_input.type == 0) {
return;
}
_input.ki.wVk = keycode;
_input.ki.dwFlags = 0;
SendInput(1, &_input, sizeof(INPUT));
_input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &_input, sizeof(INPUT));
}
};
#else
// Input variable
INPUT _input;
// Function for initializing SUI
void SUIInit(int mode) {
if(mode>1) {
return;
}
_input.type = mode;
if(mode == 0) {
_input.mi.time = 0;
_input.mi.mouseData = 0;
_input.mi.dwExtraInfo = 0;
}
if(mode == 1) {
_input.ki.wScan = 0;
_input.ki.time = 0;
_input.ki.dwExtraInfo = 0;
}
}
// Moving cursor pos. its just SetCursorPos, but it would have been weird if we didnt have something for this ¯\_(ツ)_/¯
void SUIMoveCursor(int x, int y) {
SetCursorPos(x, y);
}
// Click mouse button
void SUIClickMouse(int button) {
if(button == 1) {
_input.mi.dwFlags = 2;
SendInput(1, &_input, sizeof(INPUT));
_input.mi.dwFlags = 4;
SendInput(1, &_input, sizeof(INPUT));
}
else
if(button == 2) {
_input.mi.dwFlags = 8;
SendInput(1, &_input, sizeof(INPUT));
_input.mi.dwFlags = 10;
SendInput(1, &_input, sizeof(INPUT));
} else {
return;
}
}
// Keyboard input
void SUIPressKey(int keycode) {
if(_input.type == 0) {
return;
}
_input.ki.wVk = keycode;
_input.ki.dwFlags = 0;
SendInput(1, &_input, sizeof(INPUT));
_input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &_input, sizeof(INPUT));
}
#endif