1

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

1
  • Both of your speculations together would produce better code imo. Commented Jul 2, 2013 at 21:50

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.