I'm trying to figure out the proper use of the SendInput function so I can directly manipulate the cursor on the screen, so for a basic test to see how things work, I made this short snippet that should move the cursor 10 pixels to the right. In theory.
#include <windows.h>
#include <winable.h>
int main()
{
INPUT joyInput;
joyInput.type = INPUT_MOUSE;
joyInput.mi.dx = 10;
joyInput.mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(1, &joyInput, sizeof(INPUT));
return 0;
}
However, in practice, the SendInput function is either putting my computer to sleep, or at least shutting off my monitors, which is certainly an unwanted effect! Commenting out that line prevents the issue from happening, but obviously I need it to perform the task. What am I doing wrong?
The MOUSEINPUT structure has three members that you aren't initializing - dy
, mouseData
, and time
. Since the documentation doesn't mention default values, I assume the program is free to initially fill those members with whatever junk it wants. You should explicitly set the values to avoid this.
#include <windows.h>
#include <winable.h>
int main()
{
INPUT joyInput;
joyInput.type = INPUT_MOUSE;
joyInput.mi.dx = 10;
joyInput.mi.dwFlags = MOUSEEVENTF_MOVE;
joyInput.mi.dy = 0;
joyInput.mi.mouseData = 0;
joyInput.mi.time = 0;
SendInput(1, &joyInput, sizeof(INPUT));
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With