Open ifuchs opened 2 years ago
It seems that macOS has a lot of issues relating to pyautogui in general. Through some tests on a friends computer, it seems that basic tasks like copying and pasting seem to fail.
To fix doubleclick on OSX this code needs to be changed from clicking repeatedly here: https://github.com/asweigart/pyautogui/blob/667161b072e89b4a25b806c5f2ca616e6c0aeec3/pyautogui/_pyautogui_osx.py#L390-L413 to use something like this:
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, CGPointMake(x, y), kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, theEvent);
CGEventSetType(theEvent, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, theEvent);
CGEventSetIntegerValueField(theEvent, kCGMouseEventClickState, 2);
CGEventSetType(theEvent, kCGEventLeftMouseDown);
CGEventPost(kCGHIDEventTap, theEvent);
CGEventSetType(theEvent, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
For more info see here: https://stackoverflow.com/questions/1483657/performing-a-double-click-using-cgeventcreatemouseevent
It looks like this was broken at some point as part of refactoring possibly, because there are unused variables btn up down
that are directly useful for the code above.
I added a potential solution for this problem in https://github.com/asweigart/pyautogui/pull/775. Let me know if you facy any problems with it.
I tried this fix today on pyqutogui version 0.9.54 and it seems to fix the double_click(..) issue. I wonder if this fix should get more attention and probably be merged with mainstream ...
This is still an issue also on Sonoma, wonder if it will be fixed ?!
As autopy
and mouse
also do not work on macOS - but mentioned they should - i could find a solution with pynput
:
if double:
if button == 'left':
button = pynput.mouse.Button.left
elif button == 'right':
button = pynput.mouse.Button.right
pynput.mouse.Controller().click(button=button, count=2)
Running on MacOS 10.14. Single click, no problem but doubleClick of a desktop icon seems not to work. Tried with differing intervals with no luck.