Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More “human-like” mouse movements (easing) #23

Closed
BlueM opened this issue Sep 9, 2015 · 7 comments
Closed

More “human-like” mouse movements (easing) #23

BlueM opened this issue Sep 9, 2015 · 7 comments

Comments

@BlueM
Copy link
Owner

BlueM commented Sep 9, 2015

For purposes such as scripting screencasts, where things like the movement of the mouse pointer should be perceivable (instead of the mouse jumping around the screen, which is what happens when using cliclick now), it would be nice to have mouse movement easing – probably cubic in/out easing.

This means that a whole series of mouse move events would have to be fired to emulate this.

Reminder: for calculating the easing, this would be sufficient:

// Modeled after the piecewise cubic
// y = (1/2)((2x)^3)       ; [0, 0.5)
// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
//
// Source: AHEasing, License: WTFPL
//
// Expects the [whatever action] to be split up into small steps represented
// by a float from 0 (start) to 1 (end). Method is to be called with the float
// and returns an "eased float" for it.
-(float)cubicEaseInOut:(float)p {
    if (p < 0.5) {
        return 4 * p * p * p;
    } else {
        float f = ((2 * p) - 2);
        return 0.5 * f * f * f + 1;
    }
}
@sixpetrov
Copy link

sixpetrov commented Oct 24, 2017

Hello. Is there a way to disable easing effect? I built the project, and I can't find option to disable easing.

I really need just move, I don't want to actually see how mouse is moved.

I managed to disable it replacing this code:
[self postHumanizedMouseEventsOfType:kCGEventMouseMoved toX:(float)p.x toY:(float)p.y];

with this one:
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(p.x, p.y), kCGMouseButtonLeft); CGEventPost(kCGHIDEventTap, move); CFRelease(move);

I found this piece of code in git diff.
It works, but I wonder is this correct way to do it. Thanks.

@BlueM
Copy link
Owner Author

BlueM commented Oct 25, 2017

Currently, there is no flag to disable easing, but there will be.

@BlueM
Copy link
Owner Author

BlueM commented Oct 25, 2017

@sixpetrov
Copy link

Cool. Thank you. And thank you so much for sharing this project. I started learning cocoa recently, and cliclick is super valuable resource.

I already changed few things. For example cliclick p will put coordinates to clipboard. So I can just paste it for mouse move or click. Pretty neat :)

Cheers

@BlueM
Copy link
Owner Author

BlueM commented Oct 26, 2017

You needn’t change the source – there’s pbcopy for that.

@sixpetrov
Copy link

True, but by default cliclick p outputs text also, I just need coordinates.
Also I remember Richard Stallman said once: the best way to learn is to take some open-source project and play with it :)

@BlueM
Copy link
Owner Author

BlueM commented Oct 28, 2017

Enter pipes: using …
cliclick p | awk '{print $4}'
… or …
cliclick p | cut -d ' ' -f 4
… or …
cliclick p | perl -pe 's/^.*: //'
… or one of numerous other tools you can modify the output however you need it – in this case everything except the coordinates would be dropped using any of the lines above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants