So basically what I'm trying to do is move my mouse smoothly to the center. What I have here works fine, but it teleports the cursor instantly to the center.
Also if I set input.mi.time
to a value larger than 0, it puts my PC to sleep. Can anyone explain a bit more on what it even does? The documentation didn't really clarify it for me.
#include <iostream>
#include <Windows.h>
int screenWidth;
int screenHeight;
void moveMouse(int x, int y)
{
POINT mouseCoords;
GetCursorPos(&mouseCoords);
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.dwExtraInfo = NULL;
input.mi.mouseData = NULL;
input.mi.dx = -mouseCoords.x + x;
input.mi.dy = -mouseCoords.y + y;
input.mi.time = NULL;
SendInput(1, &input, sizeof(INPUT));
}
void main()
{
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
int middleOfScreenX = screenWidth / 2;
int middleOfScreenY = screenHeight / 2;
moveMouse(middleOfScreenX, middleOfScreenY);
}