#include 'mousemoni.h' #include <Windows.h> #include <winuser.h> #include <ntddmou.h>

// 定义鼠标输入数据结构 typedef struct _MOUSE_INPUT_DATA { USHORT UnitId; USHORT Flags; ULONG ButtonData; ULONG RawButtons; LONG LastX; LONG LastY; ULONG ExtraInformation; } MOUSE_INPUT_DATA;

int test() { // 打开鼠标设备句柄 HANDLE mouseHandle = CreateFile(L"\.\mouse", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (mouseHandle == INVALID_HANDLE_VALUE) { // 处理错误 return 1; }

// 设置鼠标输入数据
MOUSE_INPUT_DATA mouseData;
mouseData.UnitId = 0;
mouseData.Flags = MOUSE_LEFT_BUTTON_DOWN;
mouseData.ButtonData = 0;
mouseData.RawButtons = 0;
mouseData.LastX = 0;
mouseData.LastY = 0;
mouseData.ExtraInformation = 0;

DWORD bytesWritten;
BOOL result;

// 模拟鼠标左键按下
result = WriteFile(mouseHandle, &mouseData, sizeof(MOUSE_INPUT_DATA), &bytesWritten, NULL);
if (!result) {
    // 处理错误
    CloseHandle(mouseHandle);
    return 1;
}

// 模拟鼠标左键释放
mouseData.Flags = MOUSE_LEFT_BUTTON_UP;
result = WriteFile(mouseHandle, &mouseData, sizeof(MOUSE_INPUT_DATA), &bytesWritten, NULL);
if (!result) {
    // 处理错误
    CloseHandle(mouseHandle);
    return 1;
}

// 关闭鼠标设备句柄
CloseHandle(mouseHandle);

return 0;

}

#ifndef MOUSEMONI_H #define MOUSEMONI_H

#include <Windows.h> #include <winuser.h> #include <ntddmou.h>

typedef struct _MOUSE_INPUT_DATA { USHORT UnitId; USHORT Flags; ULONG ButtonData; ULONG RawButtons; LONG LastX; LONG LastY; ULONG ExtraInformation; } MOUSE_INPUT_DATA;

int test();

#endif


原文地址: https://www.cveoy.top/t/topic/o5C6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录