Created
October 5, 2023 20:00
-
-
Save polaco1782/8cd2ddbedc3d6fd4ef0f4dce3495f880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <time.h> | |
HWND findWindow(HWND hwnd, const char *name) { | |
char windowName[256]; | |
GetWindowText(hwnd, windowName, sizeof(windowName)); | |
if (strcmp(windowName, name) == 0) { | |
return hwnd; | |
} | |
HWND child = GetWindow(hwnd, GW_CHILD); | |
while (child != NULL) { | |
HWND found = findWindow(child, name); | |
if (found != NULL) { | |
return found; | |
} | |
child = GetWindow(child, GW_HWNDNEXT); | |
} | |
return NULL; | |
} | |
HWND findXfreerdpWindow() { | |
HWND desktop = GetDesktopWindow(); | |
return findWindow(desktop, "FreeRDP: 172.16.1.20:2021"); | |
} | |
void sendMouseMovementEvent(HWND hwnd, int x, int y) { | |
LPARAM lParam = MAKELPARAM(x, y); | |
PostMessage(hwnd, WM_MOUSEMOVE, 0, lParam); | |
} | |
void sendKeyPress(HWND hwnd, WPARAM wParam) { | |
PostMessage(hwnd, WM_KEYDOWN, wParam, 0); | |
PostMessage(hwnd, WM_KEYUP, wParam, 0); | |
} | |
int main() { | |
HWND xfreerdpWindow = findXfreerdpWindow(); | |
if (xfreerdpWindow == NULL) { | |
printf("xfreerdp window not found\n"); | |
return 1; | |
} | |
for (;;) { | |
// Get the current mouse position | |
POINT cursorPos; | |
GetCursorPos(&cursorPos); | |
// Add a random offset to the coordinates | |
srand(time(NULL)); | |
int offsetX = rand() % 10; | |
int offsetY = rand() % 10; | |
int newX = cursorPos.x + offsetX; | |
int newY = cursorPos.y + offsetY; | |
// Send the new mouse position to the window | |
sendMouseMovementEvent(xfreerdpWindow, newX, newY); | |
Sleep(100); | |
// Send mouse position back to the window | |
sendMouseMovementEvent(xfreerdpWindow, cursorPos.x, cursorPos.y); | |
Sleep(60000); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment