Zuckerjunkie

Clicker

Sep 11th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <cstdio> // printf
  3. #include <cstdlib> // atoi
  4. #include <unistd.h> // getopt
  5.  
  6. bool KeyIsPressed ( unsigned char k )
  7. {
  8.     USHORT status = GetAsyncKeyState(k);
  9.     return (((status & 0x8000) >> 15) == 1) || ((status & 1) == 1);
  10. }
  11.  
  12. int click ( INPUT input, int sleep ) {
  13.     input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
  14.     SendInput( 1, &input, sizeof( INPUT ) );
  15.  
  16.     ZeroMemory( &input, sizeof( INPUT ) );
  17.  
  18.     input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
  19.     SendInput( 1, &input, sizeof( INPUT ) );
  20.  
  21.     printf( "." );
  22.  
  23.     Sleep( sleep );
  24.  
  25.     return 0;
  26. }
  27.  
  28. int click ( unsigned char key, bool toggle, int sleep ) {
  29.     INPUT input;
  30.     input.type = INPUT_MOUSE;
  31.  
  32.     while ( true ) {
  33.         if ( toggle ) {
  34.             while ( !KeyIsPressed( key ) ) {
  35.                 Sleep( 100 );
  36.             }
  37.             while ( KeyIsPressed( key ) ) {}
  38.             while ( !KeyIsPressed( key ) ) {
  39.                 click( input, sleep );
  40.             }
  41.             while ( KeyIsPressed( key ) ) {}
  42.         } else {
  43.             while ( KeyIsPressed( key ) ) {
  44.                 click( input, sleep );
  45.             }
  46.         }
  47.  
  48.         Sleep( sleep );
  49.     }
  50.  
  51.     return 0;
  52. }
  53.  
  54. // Using main in favor of winmain to allow easier use of command line options
  55. int __cdecl main( int argc, char *argv[] ) {
  56.     char key    = 0x45;
  57.     bool toggle = false;
  58.     int sleep   = 10;
  59.     int opt;
  60.  
  61.     while ( ( opt = getopt( argc, argv, "k:s:t" ) ) != -1 ) {
  62.         switch (opt) {
  63.             case 'k': // KEY
  64.                 key = optarg[0];
  65.                 if ( key > 0x60 && key < 0x7b ) {
  66.                     key -= 0x20;
  67.                 }
  68.                 break;
  69.             case 's': // SLEEP
  70.                 sleep = atoi( optarg );
  71.                 if ( sleep < 1) {
  72.                     sleep = 1;
  73.                 }
  74.                 break;
  75.             case 't': // TOGGLE
  76.                 toggle = true;
  77.                 break;
  78.             default:
  79.                 break;
  80.         }
  81.     }
  82.  
  83.     printf( "Key:    %c\n", key);
  84.     printf( "Toggle: %s\n", toggle ? "yes" : "no" );
  85.     printf( "Sleep:  %i\n", sleep );
  86.  
  87.     click( key, toggle, sleep );
  88.  
  89.     return 0;
  90. }
Add Comment
Please, Sign In to add comment