Python Forum

Full Version: click drag
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wonder if I could be pointed towards what is probably a simple coding solution. I am trying to automate a click and drag on a GUI for an audio looper on mac osx. I can position the cursor , but now I need to click and drag a short distance , in a prescribed timeframe , around three seconds start to finish , and then have the cursor reposition itself at the starting point. I can do it in a very roundabout way with AutoMouseClick and Repeater using macros , but it would seem python should offer a much simpler solution. I have found this piece of script
#!/usr/bin/python
import sys
import time
from Quartz.CoreGraphics import * # imports all of the top-level symbols in the module
def mouseEvent(type, posx, posy):
 theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
 CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
 mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclickdn(posx,posy):
 mouseEvent(kCGEventLeftMouseDown, posx,posy);
def mouseclickup(posx,posy):
 mouseEvent(kCGEventLeftMouseUp, posx,posy);
def mousedrag(posx,posy):
 mouseEvent(kCGEventLeftMouseDragged, posx,posy);
ourEvent = CGEventCreate(None); 
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
mouseclickdn(60, 100);
mousedrag(60, 300);
mouseclickup(60, 300);
time.sleep(1);
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
but I think it needs some drag duration input to work as I would like.
I was hoping pyautogui would be useful , but with no experience of these things the installation on mac is rather difficult.

Any help or pointers appreciated.
Oli
If you're not too deeply dependant on Quartz, wxpython has some good tools for this.
see: https://wxpython.org/Phoenix/docs/html/d...rview.html