asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

Can't get doubleClick to work #672

Open ifuchs opened 2 years ago

ifuchs commented 2 years ago

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.

pendragons-code commented 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.

ezolenko commented 2 years ago

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.

0x0dd4b2 commented 1 year ago

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.

RidaShamasneh commented 6 months ago

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 ...

ni-dschiller commented 4 months ago

This is still an issue also on Sonoma, wonder if it will be fixed ?!

ni-dschiller commented 4 months ago

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)