sendinput函数模拟相对移动鼠标 会受到哪些因素影响 要怎么获取这些因素 获取到之后我又要如何用代码计算 让任何一台电脑都能移动到我预设的位置 C++代码演示一下
sendinput函数模拟相对移动鼠标受到以下因素影响:
- 操作系统的鼠标速度设置
- 鼠标的分辨率和灵敏度
- 鼠标的物理尺寸和形状
- 鼠标的驱动程序和硬件
要获取这些因素,可以使用GetSystemMetrics函数获取操作系统鼠标速度设置和鼠标分辨率,使用GetCursorInfo函数获取鼠标的物理尺寸和形状,使用GetDeviceCaps函数获取鼠标的灵敏度和驱动程序信息。
获取到这些因素之后,可以根据以下公式计算鼠标移动的相对距离:
dx = (mouse_x * 65536) / screen_width; dy = (mouse_y * 65536) / screen_height;
其中,dx和dy分别为鼠标的水平和垂直相对移动距离,mouse_x和mouse_y为鼠标移动的像素数,screen_width和screen_height为屏幕的宽度和高度。
下面是C++代码示例:
#include <Windows.h>
int main()
{
int mouse_x = 100; // 鼠标水平移动像素数
int mouse_y = 100; // 鼠标垂直移动像素数
int screen_width = GetSystemMetrics(SM_CXSCREEN);
int screen_height = GetSystemMetrics(SM_CYSCREEN);
double dx = (mouse_x * 65536) / screen_width;
double dy = (mouse_y * 65536) / screen_height;
INPUT input = { 0 };
input.type = INPUT_MOUSE;
input.mi.dx = (LONG)dx;
input.mi.dy = (LONG)dy;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
SendInput(1, &input, sizeof(input));
return 0;
}
该示例会将鼠标相对移动到屏幕的左上角
原文地址: https://www.cveoy.top/t/topic/eOtK 著作权归作者所有。请勿转载和采集!