2013-07-02 341 views
1

我無法理解下面的代碼。我不能對此做出很好的解釋。 我在我有疑問的代碼段旁邊留下了評論。C++鼠標點擊模擬代碼

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)); 
     } 

我得到這個代碼在http://forums.codeguru.com/showthread.php?377394-Windows-SDK-User-Interface-How-can-I-emulate-mouse-events-in-an-application

+0

您的兩個猜測一起會產生更好的代碼imo。 – chris

回答