Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,628 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,030 people online right now. Registration is fast and FREE... Join Now!





Syncronize a mouse click

Using windows.h to click with another key other than the left mouse

Submitted By: DeeViLiSh
Actions:
Rating:
Views: 4,846

Language: C++

Last Modified: August 28, 2006

Snippet


  1. #include <iostream.h>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.    int n = 1;
  9.    int x; // Mouse coordinates needed for mouse_event()
  10.    int y; // Mouse coordinates needed for mouse_event()
  11.  
  12.    cout<<"Press numpad 0 to double click\nPress numpad 1 to stop";
  13.  
  14.    while (n != NULL)
  15.    {
  16.         if(GetAsyncKeyState(VK_NUMPAD0)) //Key to press in order to click
  17.         {
  18.            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); //Click Down
  19.            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); //Click Up
  20.         }
  21.  
  22.         if(GetAsyncKeyState(VK_NUMPAD1)) // Key that shuts program down
  23.         break;
  24.     }
  25.  
  26.     return 0;
  27. }

Copy & Paste


Comments


Pitufo 2008-07-23 12:57:39

I get this error Warning NULL used in Arithmetic


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month