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

Update mac.py #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Update mac.py #68

wants to merge 2 commits into from

Conversation

zefj
Copy link

@zefj zefj commented May 17, 2015

Added doubleclick() method for doubleclick handling. Calling click() twice does not trigger a proper doubleclick, nor does calling click() with n = 2, or manually calling press(), release() then sleeping for some time and repeating the sequence.

Add doubleclick() method for doubleclick triggering
@pepijndevos
Copy link
Collaborator

What are your thoughts regarding cross-platform compatibility for this change?

@zefj
Copy link
Author

zefj commented May 17, 2015

Not exactly sure what you mean, this change is OSX-specific, as far as I know pymouse/mac.py offers functionality exclusively for macs. Method I suggested triggers doubleclicks just fine on my mac, and does what otherwise I was not able to accomplish with this module.

@pepijndevos
Copy link
Collaborator

It contains Mac-specific implementations for a common interface.
So I think it should also live in base.py.
The base.py function could be a dummy that calls click twice, which is then overridden on platforms where two clicks does not have the intended result.
If Linux and Windows also need a specialised double-click function needs to be tested.

@pepijndevos
Copy link
Collaborator

Actually, take a look at the click function in base.py, it takes a n parameter to do multiple clicks. So please override that in mac.py to work with n=2.

@zefj
Copy link
Author

zefj commented May 18, 2015

Calling click() with n=2 does not trigger a double-click (does not for example open folders or applications on Desktop, just highlight them).

You need another method for double-click, because press() and release() both create new events on every call (which might be the reason current implementation does not work, I think?), whereas my method only modifies already existing event. Besides, triggering double-click on OSX requires this line to be present:

Quartz.CGEventSetIntegerValueField(event, Quartz.kCGMouseEventClickState, clickCount)

where clickCount is self-explanatory. There is no straight-forward way of putting that into press(), and putting that into base.py/click() in an if statement would be bad practice and as far as I'm concerned is out of question, because this file is supposed to be the base model only

To be honest, I see no other way of accomplishing that without incorporating unnecessary code into base.py and mac.py. It would be more straight-forward to just leave it as it is, since I don't think there is a need for triple-click that needs triggering like the double-click does, so only the double-click needs special handling, other multiple-click calls for macro solutions are just fine with iterating over press() and release(). All we would need to do is put an appropriate comment (or even a reference method raising NotImplementedError and a comment, that this is OSX-specific) in base.py, indicating that for triggering double-click on OSX you should use doubleclick(x, y, button).

To sum up, like I mentioned, other solutions would require serious modifications to press(), iterating over press() and release() n-times just won't work for double-click because you need to set

Quartz.CGEventSetIntegerValueField(event, Quartz.kCGMouseEventClickState, clickCount)

on one, existing event, before posting it (and modifying and posting it accordingly again to simulate releasing the button and pressing it again). Otherwise it will not trigger a proper action resulting from a double-click like we're all accustomed to.

@pepijndevos
Copy link
Collaborator

The question is if 2 clicks should be different from a double-click. We should think if it makes sense to say something like

    def click(self, x, y, button=1, n=1):
        event = Quartz.CGEventCreateMouseEvent(None,
                                        pressID[button],
                                        (x, y),
                                        button - 1)
        Quartz.CGEventSetIntegerValueField(event, Quartz.kCGMouseEventClickState, n)
        for i in range(n):
            Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
            Quartz.CGEventSetType(event, Quartz.kCGEventLeftMouseUp)
            Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
            Quartz.CGEventSetType(event, Quartz.kCGEventLeftMouseDown)

@zefj
Copy link
Author

zefj commented Nov 29, 2015

It might make sense and definitely looks promising, this way there would be a universal method for n amount of clicks, and a method for long press, simple enough without hardcoding just the doubleclick behaviour into a separate method. Please, test your snippet out and let me know if it works for double clicks as intended.

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

Successfully merging this pull request may close these issues.

None yet

2 participants