-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouselib.h
151 lines (128 loc) · 4.29 KB
/
mouselib.h
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
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include <windows.h>
#include "Lua/lua.hpp"
namespace MouseLibs {
INPUT Inputs[1] = { 0 };
int Mouse1Down(lua_State* LS) {
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int Mouse1Up(lua_State* L) {
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int Mouse2Down(lua_State* L) {
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTDOWN;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int Mouse2Up(lua_State* L) {
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_RIGHTUP;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int Mouse1Click(lua_State* L) {
float n = lua_tonumber(L, -1);
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
SendInput(1, Inputs, sizeof(INPUT));
Sleep(n);
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int Mouse2Click(lua_State* L) {
float n = lua_tonumber(L, -1);
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
SendInput(1, Inputs, sizeof(INPUT));
Sleep(n);
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
SendInput(1, Inputs, sizeof(INPUT));
return 0;
}
int MouseScroll(lua_State* L) {
int amount = lua_tonumber(L, -1);
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_HWHEEL;
Inputs[0].mi.mouseData = amount;
SendInput(1, Inputs, sizeof(INPUT));
Inputs[0].mi.mouseData = NULL;
return 0;
}
int MouseMoveRelative(lua_State* L) {
LONG x = lua_tonumber(L, -2);
LONG y = lua_tonumber(L, -1);
POINT p;
if (GetCursorPos(&p))
{
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
Inputs[0].mi.dx = ((p.x + x) * 0xFFFF / GetSystemMetrics(SM_CXSCREEN) + 1);
Inputs[0].mi.dy = ((p.y + y) * 0xFFFF / GetSystemMetrics(SM_CYSCREEN) + 1);
SendInput(1, Inputs, sizeof(INPUT));
}
return 0;
}
void RegisterMouseLibs(lua_State* LS) {
Inputs[0].type = INPUT_MOUSE;
lua_register(LS, "mousemoverel", MouseMoveRelative);
lua_register(LS, "MouseMoveRel", MouseMoveRelative);
lua_register(LS, "mousemoverelative", MouseMoveRelative);
lua_register(LS, "MouseMoveRelative", MouseMoveRelative);
lua_register(LS, "MouseScroll", MouseScroll);
lua_register(LS, "mousescroll", MouseScroll);
lua_register(LS, "MouseButton1Click", Mouse1Click);
lua_register(LS, "MouseButton1Press", Mouse1Down);
lua_register(LS, "MouseButton1Release", Mouse1Up);
lua_register(LS, "MouseButton2Click", Mouse2Click);
lua_register(LS, "MouseButton2Press", Mouse2Down);
lua_register(LS, "MouseButton2Release", Mouse2Up);
lua_register(LS, "MouseButton1Down", Mouse1Down);
lua_register(LS, "MouseButton1Up", Mouse1Up);
lua_register(LS, "MouseButton2Down", Mouse2Down);
lua_register(LS, "MouseButton2Up", Mouse2Up);
}
}
namespace KeyBoardLibs {
INPUT Inputs[1] = { 0 };
int KeyPress(lua_State* L) {
WORD key = lua_tonumber(L, -1);
Inputs[0].ki.wVk = key;
SendInput(1, Inputs, sizeof(INPUT));
Inputs[0].ki.wVk = NULL;
return 0;
}
int KeyRelease(lua_State* L) {
WORD key = lua_tonumber(L, -1);
Inputs[0].ki.wVk = key;
Inputs[0].mi.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, Inputs, sizeof(INPUT));
Inputs[0].mi.dwFlags = NULL;
Inputs[0].ki.wVk = NULL;
return 0;
}
int KeyTap(lua_State* L) {
WORD key = lua_tonumber(L, -2);
int delay = lua_tonumber(L, -1);
Inputs[0].ki.wVk = key;
SendInput(1, Inputs, sizeof(INPUT));
Sleep(delay);
Inputs[0].mi.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, Inputs, sizeof(INPUT));
Inputs[0].mi.dwFlags = NULL;
Inputs[0].ki.wVk = NULL;
return 0;
}
void RegisterKeyBoardLibs(lua_State* LS) {
Inputs[0].type = INPUT_KEYBOARD;
lua_register(LS, "keypress", KeyPress);
lua_register(LS, "keyrelease", KeyRelease);
lua_register(LS, "keytap", KeyTap);
lua_register(LS, "KeyPress", KeyPress);
lua_register(LS, "KeyRelease", KeyRelease);
lua_register(LS, "KeyTap", KeyTap);
}
}
void RegisterMouseAndKeyBoardLibs(lua_State* LS) {
KeyBoardLibs::RegisterKeyBoardLibs(LS);
MouseLibs::RegisterMouseLibs(LS);
}