Reputation: 1721
Im having trouble understanding the code bellow. and i cant fined a good explanation of it. I left comments next to the code segments i have questions for.
void LeftClick ( )
{
INPUT input = {0};
// left down
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
::SendInput(1,&input,sizeof(INPUT));
// left up
::ZeroMemory(&input,sizeof(INPUT)); // why zeroMemory? removing this code changes nothing that i can tell
input.type = INPUT_MOUSE; // why reset this variable? is it not already set?
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
::SendInput(1,&input,sizeof(INPUT));
}
i got this code at http://forums.codeguru.com/showthread.php?377394-Windows-SDK-User-Interface-How-can-I-emulate-mouse-events-in-an-application
Upvotes: 1
Views: 2820
Reputation: 229
The ZeroMemory function clears all the data in the struct named input
- that's why the code has to reset the input.type
variable.
Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366920(v=vs.85).aspx
I actually took a look at some old code I wrote, and I didn't use the ZeroMemory macro at all. It's really unnecessary, since both values that are set are reset again.
Upvotes: 4