-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_cursor_windows.c
More file actions
213 lines (178 loc) · 6.39 KB
/
Copy pathmove_cursor_windows.c
File metadata and controls
213 lines (178 loc) · 6.39 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <windows.h>
#include <commctrl.h>
#include <shellapi.h>
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void ShowNotification(const char* title, const char* message) {
NOTIFYICONDATAA nid = {0};
nid.cbSize = sizeof(NOTIFYICONDATAA);
nid.hWnd = GetDesktopWindow();
nid.uID = 1001;
nid.uFlags = NIF_INFO | NIF_ICON | NIF_TIP;
nid.dwInfoFlags = NIIF_INFO;
nid.hIcon = LoadIconA(GetModuleHandle(NULL), MAKEINTRESOURCEA(1));
if (!nid.hIcon) {
nid.hIcon = LoadIcon(NULL, IDI_INFORMATION);
}
snprintf(nid.szTip, sizeof(nid.szTip), "%s", title);
snprintf(nid.szInfoTitle, sizeof(nid.szInfoTitle), "%s", title);
snprintf(nid.szInfo, sizeof(nid.szInfo), "%s", message);
Shell_NotifyIconA(NIM_ADD, &nid);
Sleep(2500);
Shell_NotifyIconA(NIM_DELETE, &nid);
}
int is_esc_pressed() {
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_HOTKEY && msg.wParam == 1) {
return 1;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (GetAsyncKeyState(VK_ESCAPE) & 0x8000) != 0;
}
int is_mouse_clicked(POINT *pt_out) {
if ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) ||
(GetAsyncKeyState(VK_RBUTTON) & 0x8000) ||
(GetAsyncKeyState(VK_MBUTTON) & 0x8000)) {
if (pt_out) {
GetCursorPos(pt_out);
}
return 1;
}
return 0;
}
static HRESULT CALLBACK TaskDialogCallbackProc(HWND hwnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData) {
if (uNotification == TDN_CREATED) {
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetForegroundWindow(hwnd);
BringWindowToTop(hwnd);
}
return S_OK;
}
int select_mode_dialog() {
INITCOMMONCONTROLSEX icex = {0};
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_STANDARD_CLASSES | ICC_WIN95_CLASSES;
InitCommonControlsEx(&icex);
int button = 0;
TASKDIALOGCONFIG config = {0};
config.cbSize = sizeof(config);
config.pszWindowTitle = L"IdleGuard - Merke Software";
config.pszMainInstruction = L"Selecciona el modo de funcionamiento:";
config.pszContent = L"IdleGuard mantendrá tu sesión activa según el modo elegido:";
config.pszMainIcon = TD_INFORMATION_ICON;
config.pfCallback = TaskDialogCallbackProc;
TASKDIALOG_BUTTON buttons[] = {
{ 101, L"1. Modo Giratorio\nMovimiento circular continuo alrededor del clic.\n(Se detiene haciendo Clic o presionando la tecla ESC)" },
{ 102, L"2. Modo Inactividad (Segundo Plano)\nMicro-movimiento sutil tras 15 segundos de inactividad.\n(Se detiene únicamente presionando la tecla ESC)" }
};
config.pButtons = buttons;
config.cButtons = 2;
config.nDefaultButton = 101;
config.dwFlags = TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION;
HRESULT hr = TaskDialogIndirect(&config, &button, NULL, NULL);
if (SUCCEEDED(hr)) {
if (button == 101) return 1;
if (button == 102) return 2;
return 0;
}
// Fallback con MessageBox de respaldo en primer plano
int result = MessageBoxA(
NULL,
"Selecciona el modo de funcionamiento de IdleGuard:\n\n"
"[Sí] -> 1. Modo Giratorio (Movimiento circular alrededor del clic)\n"
"[No] -> 2. Modo Inactividad (Micro-movimiento sutil en segundo plano)\n"
"[Cancelar] -> Salir",
"IdleGuard - Merke Software",
MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1 | MB_TOPMOST | MB_SETFOREGROUND
);
if (result == IDYES) return 1;
if (result == IDNO) return 2;
return 0;
}
int sleep_check_esc_win(int ms) {
for (int i = 0; i < ms / 10; i++) {
if (is_esc_pressed()) return 1;
Sleep(10);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
RegisterHotKey(NULL, 1, 0, VK_ESCAPE);
int mode = select_mode_dialog();
if (mode == 0) {
UnregisterHotKey(NULL, 1);
return 0;
}
if (mode == 1) {
// MODO 1: GIRATORIO
ShowNotification("IdleGuard", "Modo Giratorio: Haz clic en la pantalla para tomar la posición inicial.");
Sleep(250);
POINT pt = {0, 0};
while (1) {
if (is_esc_pressed()) {
UnregisterHotKey(NULL, 1);
return 0;
}
if (is_mouse_clicked(&pt)) break;
Sleep(15);
}
int click_x = pt.x;
int click_y = pt.y;
while (is_mouse_clicked(NULL)) Sleep(20);
Sleep(100);
ShowNotification("IdleGuard", "Girando... Haz clic o presiona ESC para detener.");
int radius = 100;
int steps = 120;
DWORD interval = 25;
while (1) {
for (int step = 0; step < steps; step++) {
if (is_esc_pressed() || is_mouse_clicked(NULL)) {
goto cleanup;
}
double angle = step * 2.0 * M_PI / steps;
int x = (int)(click_x + radius * cos(angle));
int y = (int)(click_y + radius * sin(angle));
SetCursorPos(x, y);
Sleep(interval);
}
}
} else if (mode == 2) {
// MODO 2: INACTIVIDAD (SEGUNDO PLANO)
ShowNotification("IdleGuard", "Modo Inactividad activo. Micro-movimiento en inactividad (Detener con ESC).");
Sleep(250);
int last_x = -1, last_y = -1;
int idle_seconds = 0;
while (1) {
if (is_esc_pressed()) goto cleanup;
POINT cur = {0, 0};
GetCursorPos(&cur);
if (cur.x != last_x || cur.y != last_y) {
last_x = cur.x;
last_y = cur.y;
idle_seconds = 0;
} else {
idle_seconds++;
}
if (idle_seconds >= 15) {
SetCursorPos(cur.x + 1, cur.y);
if (sleep_check_esc_win(50)) goto cleanup;
SetCursorPos(cur.x, cur.y);
GetCursorPos(&cur);
last_x = cur.x;
last_y = cur.y;
idle_seconds = 0;
}
if (sleep_check_esc_win(1000)) goto cleanup;
}
}
cleanup:
ShowNotification("IdleGuard", "Movimiento detenido.");
UnregisterHotKey(NULL, 1);
return 0;
}