Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <cstdio> // printf
- #include <cstdlib> // atoi
- #include <unistd.h> // getopt
- bool KeyIsPressed ( unsigned char k )
- {
- USHORT status = GetAsyncKeyState(k);
- return (((status & 0x8000) >> 15) == 1) || ((status & 1) == 1);
- }
- int click ( INPUT input, int sleep ) {
- input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
- SendInput( 1, &input, sizeof( INPUT ) );
- ZeroMemory( &input, sizeof( INPUT ) );
- input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
- SendInput( 1, &input, sizeof( INPUT ) );
- printf( "." );
- Sleep( sleep );
- return 0;
- }
- int click ( unsigned char key, bool toggle, int sleep ) {
- INPUT input;
- input.type = INPUT_MOUSE;
- while ( true ) {
- if ( toggle ) {
- while ( !KeyIsPressed( key ) ) {
- Sleep( 100 );
- }
- while ( KeyIsPressed( key ) ) {}
- while ( !KeyIsPressed( key ) ) {
- click( input, sleep );
- }
- while ( KeyIsPressed( key ) ) {}
- } else {
- while ( KeyIsPressed( key ) ) {
- click( input, sleep );
- }
- }
- Sleep( sleep );
- }
- return 0;
- }
- // Using main in favor of winmain to allow easier use of command line options
- int __cdecl main( int argc, char *argv[] ) {
- char key = 0x45;
- bool toggle = false;
- int sleep = 10;
- int opt;
- while ( ( opt = getopt( argc, argv, "k:s:t" ) ) != -1 ) {
- switch (opt) {
- case 'k': // KEY
- key = optarg[0];
- if ( key > 0x60 && key < 0x7b ) {
- key -= 0x20;
- }
- break;
- case 's': // SLEEP
- sleep = atoi( optarg );
- if ( sleep < 1) {
- sleep = 1;
- }
- break;
- case 't': // TOGGLE
- toggle = true;
- break;
- default:
- break;
- }
- }
- printf( "Key: %c\n", key);
- printf( "Toggle: %s\n", toggle ? "yes" : "no" );
- printf( "Sleep: %i\n", sleep );
- click( key, toggle, sleep );
- return 0;
- }
Add Comment
Please, Sign In to add comment