SendInput putting the system to sleep?

I'm at a loss to explain this one. 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.

1
2
3
4
5
6
7
8
9
10
11
12
#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?
Well, since one functionality has no relation to the other, I can only assume your PC has a virus or some anti-cheat software that detours calls to SendInput() and performs the undesirable action. That is the only explanation I can come up with. Try the executable in a 100% clean PC (a Windows PC with nothing installed except Windows).
Try zeroing the memory of the struct before using it.
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    INPUT joyInput;
    ZeroMemory(&joyInput, sizeof(joyInput));
    joyInput.type = INPUT_MOUSE;
    joyInput.mi.dx = 1000;
    joyInput.mi.dy = 100;
    joyInput.mi.dwFlags = MOUSEEVENTF_MOVE;
    SendInput(1, &joyInput, sizeof(INPUT));
    return 0;
}


Edit: Technically you just need to zero the time member joyInput.mi.time = 0;, but zero'ing all the memory is probably safer.
http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/19a23d53-2683-40c1-91c0-43cc2d330370
Last edited on
Hey, it seems to have worked! Thanks for the help.
Topic archived. No new replies allowed.