From 536eeef23fd03dee4cf7919a5e6898c75e0e9129 Mon Sep 17 00:00:00 2001 From: Irakli Chkhitunidze Date: Thu, 21 Sep 2023 06:02:26 +0400 Subject: [PATCH 1/3] added -s Speed option --- Actions/MouseBaseAction.h | 1 + Actions/MouseBaseAction.m | 4 +++- ExecutionOptions.h | 1 + cliclick.m | 12 +++++++++--- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Actions/MouseBaseAction.h b/Actions/MouseBaseAction.h index b492232..8970c67 100644 --- a/Actions/MouseBaseAction.h +++ b/Actions/MouseBaseAction.h @@ -86,6 +86,7 @@ typedef enum { withOptions:(struct ExecutionOptions)options; - (void)postHumanizedMouseEventsWithEasingFactor:(unsigned)easing + speedFactor:(unsigned)speed toX:(float)endX toY:(float)endY; diff --git a/Actions/MouseBaseAction.m b/Actions/MouseBaseAction.m index 4aa0e05..d243bdd 100644 --- a/Actions/MouseBaseAction.m +++ b/Actions/MouseBaseAction.m @@ -131,6 +131,7 @@ - (void)performActionWithData:(NSString *)data if (options.easing) { // Eased move [self postHumanizedMouseEventsWithEasingFactor:options.easing + speedFactor:options.speed toX:(float)p.x toY:(float)p.y]; } else { @@ -148,6 +149,7 @@ - (uint32_t)getMoveEventConstant { } - (void)postHumanizedMouseEventsWithEasingFactor:(unsigned)easing + speedFactor:(unsigned)speed toX:(float)endX toY:(float)endY { @@ -159,7 +161,7 @@ - (void)postHumanizedMouseEventsWithEasingFactor:(unsigned)easing float startY = currentLocation.y; float distance = [self distanceBetweenPoint:NSPointFromCGPoint(currentLocation) andPoint:NSMakePoint(endX, endY)]; - unsigned steps = ((int)(distance * easing / 100)) + 1; + unsigned steps = (((int)(distance * easing / (100 / speed))) + 1); float xDiff = (endX - startX); float yDiff = (endY - startY); float stepSize = (float)1.0 / (float)steps; diff --git a/ExecutionOptions.h b/ExecutionOptions.h index 1c55fea..d4f567b 100644 --- a/ExecutionOptions.h +++ b/ExecutionOptions.h @@ -34,6 +34,7 @@ struct ExecutionOptions { unsigned mode; unsigned easing; + unsigned speed; unsigned waitTime; BOOL isFirstAction; BOOL isLastAction; diff --git a/cliclick.m b/cliclick.m index 31158e4..cf87668 100644 --- a/cliclick.m +++ b/cliclick.m @@ -47,6 +47,7 @@ int main (int argc, const char * argv[]) { struct ExecutionOptions executionOptions; executionOptions.easing = 0; + executionOptions.speed = 1; executionOptions.waitTime = 0; executionOptions.mode = MODE_REGULAR; NSArray *modeOptionArg; @@ -64,7 +65,7 @@ int main (int argc, const char * argv[]) { fprintf(stderr, " System Preferences → Security & Privacy → Accessibility\n"); } - while ((optchar = getopt(argc, (char * const *)argv, "horVne:f:d:m:w:")) != -1) { + while ((optchar = getopt(argc, (char * const *)argv, "horVne:f:d:m:w:s:")) != -1) { switch(optchar) { case 'h': help(); @@ -112,6 +113,10 @@ int main (int argc, const char * argv[]) { case 'w': executionOptions.waitTime = atoi(optarg) > 0 ? atoi(optarg) : 0; break; + case 's': + executionOptions.easing = 0; + executionOptions.speed = atoi(optarg) > 1 ? atoi(optarg) : 1; + break; default: [pool release]; return EXIT_FAILURE; @@ -217,12 +222,12 @@ int main (int argc, const char * argv[]) { return [commands autorelease]; } -void error() { +void error(void) { fprintf(stderr, "You did not pass any commands as argument to cliclick.\n"); fprintf(stderr, "Call cliclick with option -h to see usage instructions.\n"); } -void help() { +void help(void) { NSArray *actionClasses = [ActionExecutor actionClasses]; NSUInteger i, count = [actionClasses count]; @@ -250,6 +255,7 @@ void help() { " on the distance between the start and the end position, i.e.\n" " the time needed for moving will be higher if the distance\n" " is larger.\n" + " -s You can change speed of movement by changing this value\n" " -f Instead of passing commands as arguments, you may instead\n" " specify a file from which cliclick will read the commands\n" " (or stdin, when - is given as filename).\n" From 24ca82f05944e1aa6e907dd4dd57ed8363f1fbf0 Mon Sep 17 00:00:00 2001 From: Irakli Chkhitunidze Date: Thu, 21 Sep 2023 06:09:57 +0400 Subject: [PATCH 2/3] update readme --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 2847e13..401f27d 100644 --- a/README.markdown +++ b/README.markdown @@ -35,6 +35,7 @@ To get a quick first impression, this is what you will get when you invoke `clic on the distance between the start and the end position, i.e. the time needed for moving will be higher if the distance is larger. + -s You can change speed of movement by changing this value -f Instead of passing commands as arguments, you may instead specify a file from which cliclick will read the commands (or stdin, when - is given as filename). From be35baf7c62778590ce2af97d4cfd4bea4a93af0 Mon Sep 17 00:00:00 2001 From: Irakli Chkhitunidze Date: Thu, 21 Sep 2023 12:44:04 +0400 Subject: [PATCH 3/3] fix -s option, and it works using 10 to infinity values, higher the value, mens slower the mouse movement --- Actions/MouseBaseAction.m | 14 ++++++++++---- README.markdown | 6 ++++-- cliclick.m | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Actions/MouseBaseAction.m b/Actions/MouseBaseAction.m index d243bdd..1f468c1 100644 --- a/Actions/MouseBaseAction.m +++ b/Actions/MouseBaseAction.m @@ -160,15 +160,21 @@ - (void)postHumanizedMouseEventsWithEasingFactor:(unsigned)easing float startX = currentLocation.x; float startY = currentLocation.y; float distance = [self distanceBetweenPoint:NSPointFromCGPoint(currentLocation) andPoint:NSMakePoint(endX, endY)]; - - unsigned steps = (((int)(distance * easing / (100 / speed))) + 1); + bool speederIsEnabled = speed >= 10; + + unsigned steps = ((int)(distance * easing / 100)) + 1; + + if (speederIsEnabled) { + steps = steps * speed; + }; + float xDiff = (endX - startX); float yDiff = (endY - startY); float stepSize = (float)1.0 / (float)steps; - + unsigned i; for (i = 0; i < steps; i ++) { - float factor = [self cubicEaseInOut:(stepSize * i)]; + float factor = speederIsEnabled ? stepSize * i : [self cubicEaseInOut:(stepSize * i)]; CGEventRef eventRef = CGEventCreateMouseEvent(NULL, eventConstant, CGPointMake(startX + (factor * xDiff), startY + (factor * yDiff)), 0); CGEventPost(kCGHIDEventTap, eventRef); CFRelease(eventRef); diff --git a/README.markdown b/README.markdown index 401f27d..f36eef9 100644 --- a/README.markdown +++ b/README.markdown @@ -16,7 +16,7 @@ Usage To get a quick first impression, this is what you will get when you invoke `cliclick -h`: USAGE - cliclick [-r] [-m ] [-d ] [-e ] [-f ] [-w ] command1 [command2] + cliclick [-r] [-m ] [-d ] [-e ] [-s ] [-f ] [-w ] command1 [command2] OPTIONS -r Restore initial mouse location when finished @@ -35,7 +35,9 @@ To get a quick first impression, this is what you will get when you invoke `clic on the distance between the start and the end position, i.e. the time needed for moving will be higher if the distance is larger. - -s You can change speed of movement by changing this value + -s Allows slowing the mouse movement to a constant rate. + Minimum accepted value is 10. Higher the value, + slower the mouse movement. Do not use together with -e option. -f Instead of passing commands as arguments, you may instead specify a file from which cliclick will read the commands (or stdin, when - is given as filename). diff --git a/cliclick.m b/cliclick.m index cf87668..a6790c8 100644 --- a/cliclick.m +++ b/cliclick.m @@ -47,7 +47,7 @@ int main (int argc, const char * argv[]) { struct ExecutionOptions executionOptions; executionOptions.easing = 0; - executionOptions.speed = 1; + executionOptions.speed = 10; executionOptions.waitTime = 0; executionOptions.mode = MODE_REGULAR; NSArray *modeOptionArg; @@ -114,7 +114,7 @@ int main (int argc, const char * argv[]) { executionOptions.waitTime = atoi(optarg) > 0 ? atoi(optarg) : 0; break; case 's': - executionOptions.easing = 0; + executionOptions.easing = 1; executionOptions.speed = atoi(optarg) > 1 ? atoi(optarg) : 1; break; default: