Created
November 29, 2025 08:08
-
-
Save alessandromrc/4e3a3e1372315dda1b045ce56519f725 to your computer and use it in GitHub Desktop.
A totally useless but funny script that spams Windows cursors on your screen (lol)
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 <gdiplus.h> | |
| #include <iostream> | |
| #include <vector> | |
| #include <cstdlib> | |
| #include <ctime> | |
| #pragma comment(lib, "gdiplus.lib") | |
| #pragma comment(lib, "user32.lib") | |
| #pragma comment(lib, "msimg32.lib") | |
| using namespace Gdiplus; | |
| ULONG_PTR gdipToken; | |
| bool running = true; | |
| struct MousePoint { | |
| int X; | |
| int Y; | |
| MousePoint() : X(0), Y(0) {} | |
| MousePoint(int x, int y) : X(x), Y(y) {} | |
| }; | |
| struct MouseCursor { | |
| MousePoint location; | |
| MousePoint velocity; | |
| }; | |
| HWND hwndOverlay = NULL; | |
| HDC hdcMem = NULL; | |
| HBITMAP hBitmap = NULL; | |
| HBITMAP hBitmapOld = NULL; | |
| HBITMAP hMouseBitmap = NULL; | |
| int mouseCursorWidth = 32; | |
| int mouseCursorHeight = 32; | |
| int screenWidth = 0; | |
| int screenHeight = 0; | |
| std::vector<MouseCursor> mouses; | |
| int mouseCount = 1000; | |
| bool extreme = false; | |
| HBITMAP CreateMouseBitmap() { | |
| HCURSOR hCursor = LoadCursor(NULL, IDC_ARROW); | |
| if (!hCursor) { | |
| mouseCursorWidth = 32; | |
| mouseCursorHeight = 32; | |
| return NULL; | |
| } | |
| ICONINFO iconInfo = {0}; | |
| if (!GetIconInfo((HICON)hCursor, &iconInfo)) { | |
| mouseCursorWidth = 32; | |
| mouseCursorHeight = 32; | |
| return NULL; | |
| } | |
| BITMAP bmp = {0}; | |
| if (iconInfo.hbmColor) { | |
| GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bmp); | |
| mouseCursorWidth = bmp.bmWidth; | |
| mouseCursorHeight = bmp.bmHeight; | |
| } else if (iconInfo.hbmMask) { | |
| GetObject(iconInfo.hbmMask, sizeof(BITMAP), &bmp); | |
| mouseCursorWidth = bmp.bmWidth; | |
| mouseCursorHeight = bmp.bmHeight / 2; | |
| } else { | |
| mouseCursorWidth = 32; | |
| mouseCursorHeight = 32; | |
| if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor); | |
| if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask); | |
| return NULL; | |
| } | |
| HDC hdc = GetDC(NULL); | |
| HDC memDC = CreateCompatibleDC(hdc); | |
| HBITMAP hBmp = CreateCompatibleBitmap(hdc, mouseCursorWidth, mouseCursorHeight); | |
| HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC, hBmp); | |
| RECT rect = {0, 0, mouseCursorWidth, mouseCursorHeight}; | |
| HBRUSH magentaBrush = CreateSolidBrush(RGB(255, 0, 255)); | |
| FillRect(memDC, &rect, magentaBrush); | |
| DeleteObject(magentaBrush); | |
| DrawIconEx(memDC, 0, 0, (HICON)hCursor, mouseCursorWidth, mouseCursorHeight, 0, NULL, DI_NORMAL); | |
| BITMAPINFO bmi = {0}; | |
| bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
| bmi.bmiHeader.biWidth = mouseCursorWidth; | |
| bmi.bmiHeader.biHeight = -mouseCursorHeight; | |
| bmi.bmiHeader.biPlanes = 1; | |
| bmi.bmiHeader.biBitCount = 32; | |
| bmi.bmiHeader.biCompression = BI_RGB; | |
| int stride = ((mouseCursorWidth * 32 + 31) / 32) * 4; | |
| BYTE* pixels = new BYTE[stride * mouseCursorHeight]; | |
| GetDIBits(memDC, hBmp, 0, mouseCursorHeight, pixels, &bmi, DIB_RGB_COLORS); | |
| for (int y = 0; y < mouseCursorHeight; y++) { | |
| for (int x = 0; x < mouseCursorWidth; x++) { | |
| if (x == 0 || x == mouseCursorWidth - 1 || y == 0 || y == mouseCursorHeight - 1) { | |
| int offset = y * stride + x * 4; | |
| BYTE b = pixels[offset]; | |
| BYTE g = pixels[offset + 1]; | |
| BYTE r = pixels[offset + 2]; | |
| if (r == 0 && g == 0 && b == 0) { | |
| pixels[offset] = 255; | |
| pixels[offset + 1] = 0; | |
| pixels[offset + 2] = 255; | |
| } | |
| } | |
| } | |
| } | |
| SetDIBits(memDC, hBmp, 0, mouseCursorHeight, pixels, &bmi, DIB_RGB_COLORS); | |
| delete[] pixels; | |
| SelectObject(memDC, hOldBmp); | |
| if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor); | |
| if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask); | |
| DeleteDC(memDC); | |
| ReleaseDC(NULL, hdc); | |
| return hBmp; | |
| } | |
| LRESULT CALLBACK OverlayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { | |
| switch (msg) { | |
| case WM_PAINT: | |
| { | |
| PAINTSTRUCT ps; | |
| HDC hdc = BeginPaint(hwnd, &ps); | |
| if (hdcMem && hBitmap) { | |
| BitBlt(hdc, 0, 0, screenWidth, screenHeight, hdcMem, 0, 0, SRCCOPY); | |
| } | |
| EndPaint(hwnd, &ps); | |
| } | |
| return 0; | |
| case WM_CLOSE: | |
| running = false; | |
| return 0; | |
| default: | |
| return DefWindowProc(hwnd, msg, wParam, lParam); | |
| } | |
| } | |
| void SpawnMouses() { | |
| mouses.clear(); | |
| mouses.resize(mouseCount); | |
| for (int i = 0; i < mouseCount; i++) { | |
| mouses[i].location = MousePoint(rand() % screenWidth, rand() % screenHeight); | |
| } | |
| } | |
| void InitializeVelocities() { | |
| for (int i = 0; i < mouseCount; i++) { | |
| int x = 5 + rand() % 5; | |
| int y = 5 + rand() % 5; | |
| if (rand() % 2 == 0) | |
| x *= -1; | |
| if (rand() % 2 == 0) | |
| y *= -1; | |
| mouses[i].velocity = MousePoint(x, y); | |
| } | |
| } | |
| void MoveMouses() { | |
| for (int i = 0; i < (int)mouses.size(); i++) { | |
| mouses[i].location.X += mouses[i].velocity.X; | |
| mouses[i].location.Y += mouses[i].velocity.Y; | |
| if (mouses[i].location.X > screenWidth || mouses[i].location.X < 0) | |
| mouses[i].location = MousePoint(rand() % screenWidth, rand() % screenHeight); | |
| if (mouses[i].location.Y > screenHeight || mouses[i].location.Y < 0) | |
| mouses[i].location = MousePoint(rand() % screenWidth, rand() % screenHeight); | |
| } | |
| } | |
| void DrawMouses() { | |
| if (!hdcMem || !hBitmap || !hMouseBitmap || !hwndOverlay) return; | |
| RECT rect = {0, 0, screenWidth, screenHeight}; | |
| HBRUSH magentaBrush = CreateSolidBrush(RGB(255, 0, 255)); | |
| FillRect(hdcMem, &rect, magentaBrush); | |
| DeleteObject(magentaBrush); | |
| HDC hMouseDC = CreateCompatibleDC(hdcMem); | |
| HBITMAP hOldMouseBmp = (HBITMAP)SelectObject(hMouseDC, hMouseBitmap); | |
| for (size_t i = 0; i < mouses.size(); i++) { | |
| TransparentBlt(hdcMem, mouses[i].location.X, mouses[i].location.Y, mouseCursorWidth, mouseCursorHeight, | |
| hMouseDC, 0, 0, mouseCursorWidth, mouseCursorHeight, RGB(255, 0, 255)); | |
| } | |
| SelectObject(hMouseDC, hOldMouseBmp); | |
| DeleteDC(hMouseDC); | |
| POINT ptSrc = {0, 0}; | |
| SIZE sizeWnd = {screenWidth, screenHeight}; | |
| BLENDFUNCTION blend = {0}; | |
| blend.BlendOp = AC_SRC_OVER; | |
| blend.SourceConstantAlpha = 255; | |
| blend.AlphaFormat = 0; | |
| HDC hdcScreen = GetDC(NULL); | |
| UpdateLayeredWindow(hwndOverlay, hdcScreen, NULL, &sizeWnd, hdcMem, &ptSrc, RGB(255, 0, 255), &blend, ULW_COLORKEY); | |
| ReleaseDC(NULL, hdcScreen); | |
| } | |
| BOOL WINAPI ConsoleHandler(DWORD dwType) { | |
| if (dwType == CTRL_C_EVENT || dwType == CTRL_CLOSE_EVENT || dwType == CTRL_BREAK_EVENT) { | |
| running = false; | |
| return TRUE; | |
| } | |
| return FALSE; | |
| } | |
| void Run() { | |
| screenWidth = GetSystemMetrics(SM_CXSCREEN); | |
| screenHeight = GetSystemMetrics(SM_CYSCREEN); | |
| WNDCLASSEXW wc = {0}; | |
| wc.cbSize = sizeof(WNDCLASSEXW); | |
| wc.style = CS_HREDRAW | CS_VREDRAW; | |
| wc.lpfnWndProc = OverlayWndProc; | |
| wc.hInstance = GetModuleHandle(NULL); | |
| wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
| wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); | |
| wc.lpszClassName = L"MouseSpamOverlay"; | |
| RegisterClassExW(&wc); | |
| hwndOverlay = CreateWindowExW( | |
| WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, | |
| L"MouseSpamOverlay", | |
| L"", | |
| WS_POPUP, | |
| 0, 0, screenWidth, screenHeight, | |
| NULL, NULL, GetModuleHandle(NULL), NULL | |
| ); | |
| if (!hwndOverlay) { | |
| std::cout << "Failed to create overlay window!" << std::endl; | |
| return; | |
| } | |
| HDC hdc = GetDC(hwndOverlay); | |
| hdcMem = CreateCompatibleDC(hdc); | |
| hBitmap = CreateCompatibleBitmap(hdc, screenWidth, screenHeight); | |
| hBitmapOld = (HBITMAP)SelectObject(hdcMem, hBitmap); | |
| RECT rect = {0, 0, screenWidth, screenHeight}; | |
| HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255)); | |
| FillRect(hdcMem, &rect, whiteBrush); | |
| DeleteObject(whiteBrush); | |
| ReleaseDC(hwndOverlay, hdc); | |
| hMouseBitmap = CreateMouseBitmap(); | |
| SpawnMouses(); | |
| InitializeVelocities(); | |
| POINT ptSrcInit = {0, 0}; | |
| SIZE sizeWndInit = {screenWidth, screenHeight}; | |
| BLENDFUNCTION blendInit = {0}; | |
| blendInit.BlendOp = AC_SRC_OVER; | |
| blendInit.SourceConstantAlpha = 255; | |
| blendInit.AlphaFormat = 0; | |
| HDC hdcScreenInit = GetDC(NULL); | |
| UpdateLayeredWindow(hwndOverlay, hdcScreenInit, NULL, &sizeWndInit, hdcMem, &ptSrcInit, RGB(255, 0, 255), &blendInit, ULW_COLORKEY); | |
| ReleaseDC(NULL, hdcScreenInit); | |
| ShowWindow(hwndOverlay, SW_SHOW); | |
| SetWindowPos(hwndOverlay, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | |
| UpdateWindow(hwndOverlay); | |
| std::cout << "Window created: " << (hwndOverlay ? "Yes" : "No") << std::endl; | |
| std::cout << "Screen size: " << screenWidth << "x" << screenHeight << std::endl; | |
| std::cout << "Mouse count: " << mouseCount << std::endl; | |
| MSG msg; | |
| for (int i = 0; i < 10000 && running; i++) { | |
| while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { | |
| TranslateMessage(&msg); | |
| DispatchMessage(&msg); | |
| } | |
| MoveMouses(); | |
| DrawMouses(); | |
| } | |
| if (hMouseBitmap) DeleteObject(hMouseBitmap); | |
| if (hBitmapOld) SelectObject(hdcMem, hBitmapOld); | |
| if (hBitmap) DeleteObject(hBitmap); | |
| if (hdcMem) DeleteDC(hdcMem); | |
| if (hwndOverlay) DestroyWindow(hwndOverlay); | |
| } | |
| void RunExtreme() { | |
| extreme = true; | |
| mouseCount = 5000; | |
| Run(); | |
| } | |
| int main() { | |
| srand((unsigned int)time(NULL)); | |
| SetConsoleCtrlHandler(ConsoleHandler, TRUE); | |
| GdiplusStartupInput gdiStart; | |
| GdiplusStartup(&gdipToken, &gdiStart, NULL); | |
| std::cout << "Starting mouse spam effect..." << std::endl; | |
| std::cout << "Press Ctrl+C to stop." << std::endl; | |
| RunExtreme(); | |
| GdiplusShutdown(gdipToken); | |
| std::cout << "Effect ended!" << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment