Giter Site home page Giter Site logo

bluem / cliclick Goto Github PK

View Code? Open in Web Editor NEW
1.5K 45.0 115.0 331 KB

macOS CLI tool for emulating mouse and keyboard events

Home Page: https://www.bluem.net

License: Other

Objective-C 88.49% PHP 1.37% Makefile 0.62% Shell 9.52%
objective-c cli macos mouse-events keyboard-events terminal

cliclick's Issues

How can reach this app from python?

Im not that good at coding and now really just a bit. I got this python script for blender which copies the mouse movent in blender to something in Marvelouse Designer. Now this code was written for windows, which can use:

ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) # left down

is there a easy way to do this with for example Popen orso? But i need to now how to get the path or should i look elsewhere?

Click through AppleScript is not opening menu of system bar

If I do a click through AppleScript on the system bar (where the clock, the battery, the wifi etc. are, in german "Menüleiste") nothing happens. My code (with AS):
do shell script "/opt/local/bin/cliclick c:810,10"
Not possible to emulate a click there. The mouse jumps to the position (810,10) but doesn't click.
With direct command on Terminal it is no problem.

Is there a trick or is it just forbidden by the system to use cliclick through AS?

On Mac OS 10.11.6 with cliclick (vs3.3, 11/12/2016) on my MacBook Pro Mid 2009

Thank

frank

Key press does not work on russian keyboard on OS X 10.12.6

I'm using cliclick to test hotkeys in my app. For example it presses control+shift+v. And the test runs on english and russian keyboards. But now then i run it on mac with 10.12.6 on board I get only control+shift when i switch to russian. Button "V" is ignored. It worked in earlier versions of OS X.

More “human-like” mouse movements (easing)

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;
    }
}

absolute negative values (“c:100,=-200”) aren't accepted

The help says to prefix with = to specify absolute positions on displays left of (/above) the main display:

(If you need to specify absolute negative values in case you have a setup 
with a second display arranged to the left of your main display, prefix the 
number with “=”, for instance “c:100,=-200”.)

However this isn't working for me:

$ ./cliclick p
Current mouse position: -1039,-1328
$ ./cliclick c:=-1039,=-1328
Invalid X axis coordinate “=-1039” given

If I try that without the = I get a click at a relative position (as expected).

Perhaps I misunderstood the format?

Drag Fails In OS X El Capitan Mission Control

The dragging of spaces to rearrange them in Mission Control works as expected in OS X Yosemite 10.10.5 but fails every time in any version of OS X El Capitan. The click down registers as evidenced by the darkening of the target space, but the space fails to drag. I'm using cliclick as part of an Applescript implementation, for example: do shell script "usr/local/bin/cliclick dd:830,70 w:1000 du:500,70" I'm using cliclick version 3.2.

About drag (again)

Hi,
Unfortunately, from my experience, the drag command does not seem to always return the expected results. I was trying to drag a folder from a Finder's window over a window of "ImageOptim" and repeating the same command over and over, sometimes (a few times) it works perfectly, sometimes (most of the time) it doesn't.
In addition, during these tests nothing else was changed and the "working conditions", at least those under my control, were always the same.

I tried to run all the commands directly from Terminal and all via Applescript, and I tried all the following with little changes of w: (wait amount and/or wait position(s) in the command) or other slight variations:

dd:1010,113 du:1010,650 (via AppleScript and activating Finder's window just before do shell …)
c:1010,113 dd:. du:1010,650 (as suggested having a similar issue)
c:1010,113 dd:1010,113 du:1010,650
open -a Finder; cliclick dd:1010,113 w:300 du:1010,650
c:1010,113 w:300 dd:. du:1010,650

cliclick m:1010,113 w:200 c:. w:200 dd:1010,113 w:200 du:1010,650 (this last one from Terminal, having the ImageOptim's window as last "active" window before focus on Terminal, has worked 4 times continuously … but not the 5th and 6th. Then again the 7th test.

Actually if one of these command works… repeating it again after a while, it doesn't any more. Have you please any further suggestion or advice about this?
And about this topic the dd:x,y du:x,y commands, may also have other commands between them or only the w: command is allowed? Thanks.

Always target latest SDK for building

Currently I'm using macOS 10.12.1 with Xcode 8.1 and if I import the project and initially try to build it I get an error stating The run destination My Mac is not valid for Running the scheme 'cliclick'.
This is caused by the project setting Base SDK located under PROJECT > cliclick > Build Settings > Architectures set to macosx10.7 which for me is showing SDK not found.

I'm not that familiar with Xcode (actually this is the first time I'm contributing to a project using it 😅) therefore this might be no good suggestion, but couldn't it help to set it to always use the latest SDK?

Therefore I'm suggesting this:

diff --git a/cliclick.xcodeproj/project.pbxproj b/cliclick.xcodeproj/project.pbx
index 58db10c..b4b3c4b 100644
--- a/cliclick.xcodeproj/project.pbxproj
+++ b/cliclick.xcodeproj/project.pbxproj
@@ -413,7 +413,7 @@
                ONLY_ACTIVE_ARCH = YES;
                OTHER_CFLAGS = "-DDEBUG=1";
                PREBINDING = NO;
-               SDKROOT = macosx10.7;
+               SDKROOT = macosx;
            };
            name = Debug;
        };
@@ -428,7 +428,7 @@
                MACOSX_DEPLOYMENT_TARGET = 10.7;
                OTHER_CFLAGS = "";
                PREBINDING = NO;
-               SDKROOT = macosx10.7;
+               SDKROOT = macosx;
            };
            name = Release;
        };

Screenshot shortcut

Hello,

I'm looking for a method to emulate shift + cmd + 3 (screenshot)

I tried this

cliclick kd:shift,cmd kp:num-3

but it doesn't work.

Any help will be very nice

Cannot read command file from stdin

When attempting to read commands from stdin, so that I could type them line by line into the terminal, by invoking cliclick as cliclick -w 100 -f /dev/stdin (and a few similar attempts), cliclick simply exits immediately and doesn't read from stdin/the terminal.

I'm doing this because I was trying to control a home theatre app with cliclick, by SSH'ing onto the machine running the home theatre app and having cliclick read from stdin and run commands. Individual commands like cliclick -w 100 kp:return work over SSH of course, but it's cumbersome to type that for every key, as opposed to typing like:

$ cliclick -w 100 -f /dev/stdin
h
j
k
l
:i
etc

This would allow me to interactively control said home theatre app just by typing into the terminal.

Latest version via brew?

Hi,

Is brew 3.1 already available via brew?
I just wanted to updated to cliclick 3.1 via brew and got this message:

brew upgrade cliclick
Error: cliclick 3.0.3 already installed

Leads to read value for keyboard backlit

Hi,

I'm writing a slider for backlit intensity for the mbp 2016 touch bar. I'm using your app to set the value up/down but I can't read the value as Apple removed the old ways of doing it.

Do any one have an idea on how to read the keyboard backlit value ?

Homebrew formula for cliclick

It would be cool to suggest a homebrew formula this project
Automatic compile / install with hombrew would be really nice

cliclick coordinates are off for mac retina

I was using cliclick and it was working great. I've recently switched to a 15" macbook retina display and now c:500,500 click is vertically somewhere in the middle of the screen. The screen is 2880x1800 so that can't be right.

Are there some scaling adjustments I need to make when working on a retina display?

Add support for ku at coordinates

Some web pages/menus only recognize a click after releasing the mouse,,, a key up.

Using cliclick c on a menu does not trigger the web page button. The only way to achieve a click on these menus is to use the cliclick dc option which seems to work. If a ku in combination with coordinates and not other keystrokes could be programmed into the software that would be helpful.

FeatureRequest: Support Mouse Down, Mouse Up - Not "just" Mouse Click

Hi Carsten,

After an upgrade to Sierra I had to realize that Karabiner/Seil are not working anymore, for the following use case:
I could, before the update, bind a key to the left mouse button, e.g. in their config format:

  KeyCode::D, ModifierFlag::OPTION_R | ModifierFlag::NONE,
  PointingButton::LEFT

(and option-r was remapped to caps-lock via seil)

That enabled me to do this:

  1. caps-lock + d -> mouse down (e.g. on start of text to select, e.g. on window border, with left hand)
  2. trackpad move pointer to destination (with right hand)
  3. release d and caps lock

This was amazingly effective, far more precise then clicking on the trackpad and less strain, basically just like tapping - but without having to move the hand away from the default typing position....

With cliclick I can't get it, since you 'just' support a full click but not a seperate mouse down / mouse up and drag did also not really work, e.g.:

#!/usr/bin/env bash
while true; do
    sleep 1
    echo down
    ./cliclick dd:.
    sleep 1
    echo up
    ./cliclick du:.
done

and then moving the pointer over text did not select in the browser and also not move any window when I move over its border while the the script is running.


Note: Tried to mess around a few hours with swift and obj.c - but to no success, could not really emulate a left mouse button down / up only, at the current track pad position.
Only managed to get same behaviour like pressing the '5' key on the numeric keyboard when the MouseEvents feature is on - but that allows not to drag, after 5 is down, dragging works then only with the other numeric keys. Crazy...

Maybe you find it trivial, sort of my last hope,

Cheers from Nr. 400 ;-)

Compile fails on Mac OS X 10.6

Hello, I'm the maintainer of cliclick in MacPorts and I recently updated our port to 3.0.2. It doesn't build for us on Mac OS X 10.6. We see errors like:

KeycodeInformer.m:48: error: expected ')' before 'instancetype'

and:

Actions/KeyBaseAction.m:36: error: expected expression before '@' token

Curiously, although your web page lists 10.6 or later as a requirement, it builds fine on Mac OS X 10.4.

Does not work with Bluestacks

Hi, I'm trying to use this with Bluestacks and it seems that the cursor is moved to the position but it does not stimulate the clicking. I have tried this with c, dc and tc. Is there a fix for this or a workaround that I could use?

Thanks.

Feature Request: Record

Add a --record SECONDS option.

I want to record a set of movements (minimum, just X/Y coordinates) with timings for a set number of seconds.

I have a use case where I need the mouse to follow a specific path, currently, am doing while true; do ./cliclick p >> output.txt; done, and regexing the output.

Unfortunately, there are lots of duplicates during pauses but mostly because I don't know the ms between the pauses or the polling interval since I'm running command-line (re-running the command obviously causes some ms delay, as well as writing to a file). There's no control. I don't know if it's 10ms or 20ms that I've stayed in a certain spot.

A record function could remove duplicate m:x,y positions, and insert in proper w:ms commands.

EDIT: sorry, I derped. ./cliclick actually clicked Close. ;)

Can't compile from source ActionsClassesMacro.h not found

I believe this is due to a new version of the OS and/or XCode.

OS version: 10.12.4
XCode Version: 8.3.2

Here's the build:
sandra@MacBook-Pro-2:~/socrates/snapshots/bin/cliclick-master$ make install
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/ClickAction.o Actions/ClickAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/ColorPickerAction.o Actions/ColorPickerAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/DoubleclickAction.o Actions/DoubleclickAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/DragDownAction.o Actions/DragDownAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/DragUpAction.o Actions/DragUpAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/KeyBaseAction.o Actions/KeyBaseAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/KeyDownAction.o Actions/KeyDownAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/KeyDownUpBaseAction.o Actions/KeyDownUpBaseAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/KeyPressAction.o Actions/KeyPressAction.m
Actions/KeyPressAction.m:136:51: warning: 'NSSystemDefined' is deprecated: first deprecated in macOS 10.12
[-Wdeprecated-declarations]
NSEvent *e1 = [NSEvent otherEventWithType:NSSystemDefined
^~~~~~~~~~~~~~~
NSEventTypeSystemDefined
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSEvent.h:78:26: note:
'NSSystemDefined' has been explicitly marked deprecated here
static const NSEventType NSSystemDefined API_DEPRECATED_WITH_REPLACEMENT("NSEventTypeSystemDefined", macosx(10....
^
Actions/KeyPressAction.m:147:51: warning: 'NSSystemDefined' is deprecated: first deprecated in macOS 10.12
[-Wdeprecated-declarations]
NSEvent *e2 = [NSEvent otherEventWithType:NSSystemDefined
^~~~~~~~~~~~~~~
NSEventTypeSystemDefined
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSEvent.h:78:26: note:
'NSSystemDefined' has been explicitly marked deprecated here
static const NSEventType NSSystemDefined API_DEPRECATED_WITH_REPLACEMENT("NSEventTypeSystemDefined", macosx(10....
^
2 warnings generated.
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/KeyUpAction.o Actions/KeyUpAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/MouseBaseAction.o Actions/MouseBaseAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/MoveAction.o Actions/MoveAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/PrintAction.o Actions/PrintAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/RightClickAction.o Actions/RightClickAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/TripleclickAction.o Actions/TripleclickAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/TypeAction.o Actions/TypeAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o Actions/WaitAction.o Actions/WaitAction.m
cc -include cliclick_Prefix.pch -I Actions -I . -c -o ActionExecutor.o ActionExecutor.m
ActionExecutor.m:30:10: fatal error: 'ActionClassesMacro.h' file not found
#include "ActionClassesMacro.h"
^
1 error generated.
make: *** [ActionExecutor.o] Error 1

Scrolling would be really great

It'd be heaps nice if there was a way to issue scrolling commands - ideally the smooth scrolling kind, not the chunky click mouse wheel variety. Is this a possibility?

Add support for right-clicking

The pure X11 (Linux) equivalent to cliclick, called xdotool, allows the user to specify which mouse button is used when sending a click event.

How to do cmd-C, cmd-V, cmd-X ...

How can you generate keyboard sequences like Copy, Paste etc. ?
I tried 'cliclick kd:cmd t:v ku:cmd' but that just prints out v instead of triggering a copying event.
If this isn't possible yet, I am happy to add something along the line of:

  • ad:, trigger key down event for key
  • au:, trigger key up event for key

or extend kd, ku to take a key code in addition to the current special keys

Any feedback would be helpful

Support setting base coordinate for subsequent coordinates-based actions

It could be handy to add a command-line option which takes coordinates, example: cliclick -b 500,400.

The idea behind this is that sometimes when defining coordinates to be used by cliclick, all coordinates depend on a certain base value. For example, when performing actions in an application window, the click or move coordinates will frequently be fixed relative to the window, but the window could be anywhere on the screen. In this case it would be great to just get the window bounds using AppleScript (or osascript at the shell) and set the base coordinate to a window corner and specify all distances from that base coordinates. cliclick would then add that base coordinates to all given action coordinates.

As cliclick supports relative coordinates, something similar can be done already using relative values only, but having base coordinates is probably easier to read and write.

Has the -q option been removed?

I have an old applescript that I wrote a couple of years ago that uses the -q option to get the current mouse position. However, in the current version cliclick -q returns an illegal option error.

Absolute negative coordinates are not accepted when clicking

Quote from cliclick’s help:

If you need to specify absolute negative values in case you have
a setup with a second display arranged to the left of your main display,
prefix the number with “=”, for instance “c:100,=-200”.

Such coordinates are not accepted by cliclick 3.2

Window position does not change while being dragged using the dd/du commands

I am using the start drag and end drag commands invoked as voice commands from Mac Dragon 6 so that I can drag windows and other UI elements around without having to hold the mouse button down. So, for example, I'll say the command "mouse down" (cliclick dd:+0,+0) to start the drag once my mouse is positioned over a window title bar, then I will move the window using my mouse, and then I will say the command "mouse up" (cliclick du:+0,+0) to end the drag.

All of this works, but the problem I'm having is that while the drag is in progress, the window is not being continuously dragged across the screen; only when I end the drag operation does the window position update.

I'm seeing the same behavior when using this technique to drag objects within a drawing program like Sketch. Scrollbars in the Chrome browser do actively update during the drag, although scrollbars in the Finder do not.

Any ideas why the Mac would not update the position of an element while it is being dragged using these commands?

Thanks!
-rem

Mouse moves slow in 4.0b1

Hallo

I just updated to cliclick 4.0b1 from version 3.3 and now I notice that when I do mouse moves the Mouse Cursor doesn't jump anymore, but moves visible from a to b. It moves as if I would use the mouse myself, even slower.
Is this by purpose or intention?
Or is it a setting?
Is it related to my own compiling with XCode and kind of home-made? I set Product > Build For > Running though.

I reverted to 3.3 where it is fast again.

Thanks
frank

improved dragging

First: cliclick is awesome! Congrats BlueM

The current dd and du commands work well when you try to drag an object from one place to another in an immediate action. But I could not find a way of having an ongoing dragging action, which is needed when using cliclick as a component in a remote desktop software (a la RDP or VNC)

Examples:

  • a user is dragging a document across the desktop
  • interacting with a 3D Software and rotating/handling objects continuously
  • dragging scrollbar on a window

I could not find a way to do it (possible I just didn't find a existing way), so I took cliclick's code and adjusted actions for dd, du and mm. Happy to share and create a pull request but I couldn't create a separate branch in order to actually create a pull request. BlueM, let me know what I should do, I would love to contribute.

Add support for “eject” key

Hallo
on my MacBook Pro from late 2009 (and surely on many other macs) there is the "Eject" Button, this is the very top right key on the keyboard. This is the picture on the key.
There seems no emulation for this button in cliclick.
Is it possible to add it?
Thanks

frank

Typing does not work in “verbose” mode

When in “verbose” mode (-m verbose), cliclick prints the action (as expected), but does not emulate any key events (= bug).

Example:
cliclick t:'ls -l' kp:return works as expected
cliclick -m verbose t:'ls -l' kp:return does not

Support for repeated commands

I know that cliclick can work from a commands file, or that I could write a bash loop; however, I'd love to see syntax like (inspired by xdotool):

> cliclick --repeat 500 -w 20 c:. => generate 500 click events at the current mouse position, one every 20ms

cliclick has a nice command chaining syntax, so maybe a better approach is to extend the algebra you've already written:

> cliclick -w 20 c:.*500 (same 500 clicks, once every 20ms as before)

allowing paren would enable more complicated logic:

> cliclick (c:.*5 m:+100,+100 w:20)*5 (5 clicks, move, wait, repeat all 4 more times)

Visualization of clicks

To make more perceivable what is going on (cf. #23) when events are scripted using cliclick, it would be helpful if clicks could be (optionally) visualized, similar to what some presentation tools (Mouseposé, OmniDazzle, …) offer.

Lock USB mouse while simulated events fire

I'm really enjoying this tool - many thanks to the developer. I'm using it to simulate mouse events for a GUI application that lacks fine tuning by keyboard. The issue I'm encountering is that sometimes if I accidentally move the physical mouse while cliclick is executing, the mouse will get stuck in a click until the next cliclick event. Is there any way to disable physical mouse input while cliclick is executing? Thanks!

Add support for relative mouse movements

For example, say I need to move the mouse 50px down. Currently, I must find the current mouse position, then do some math to find the end mouse position. Preferably, we could just send the command m:+0,+50, to indicate a relative move of +0 on x and +50 on y.

Love the utility!

Drag command.

Hi,
If I have a left and a right Finder's window, and I execute say "cliclick dd:. du:200,300" the current item under the cursor in the right Finder's window is correctly dragged to left window. Ok.

But, if on the left I have an application's window (ImageAlpha) and on the right the Finder's window, the drag command doesn't work anymore (actually neither if the drag command is always run on the app's window without involving the Finder). in short: the cursor moves at the coordinates but any dragging has performed.
So please is there any cliclick tricks to make it work or is it normal?

Sending shortcut

Just have not found how to ask question, so the question is: how to send shortcut into active windows e.g. ALT+CMD+I, to open Google Chrome Development Tools
Thanks

Change donation switch to avoid ambiguity

Problem: user reported that after executing the (invalid) command …
cliclick -dd:261,132
… no doubleclicking was performed, but the donations page (invokable via -d) was opened.

Option -d should be changed to a character which is not identical to the first character of any of the commands.

Addition: Get current cursor type

hi, great utility btw...
I'm using it inside app via an embedded ruby api.
I can get a click position from both ruby and cliclick to work out the offset factor to reliably find the window edge for a window drag resize...
that all works, however I can't work out a edge test to ensure I'm not being masked...
I was wondering if 'The resize-left-and-right cursor (resizeLeftRightCursor)' could be tested for and the dd: x,y target modified until true...
e.g. safe = safe + 10 if not left_right_cursor
drag = %Q[dd:#{@edg},#{safe} du:#{sq},+0]

so I guess it's a 'get cursor' function I'm after. e.g. cliclick gc:#{@edg},#{safe}
not convinced i'm making sense, but thought I'd ask...
john

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.