Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
click drag
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GUI with drag and drop functionality sayyedkamran 7 6,029 May-26-2020, 10:20 PM
Last Post: jefsummers
  Looking for Python IDE With Drag and Drop GUI Dan_PanMan 0 2,292 May-23-2020, 04:39 PM
Last Post: Dan_PanMan
  [PyQt] Drag and Move window from menubar WBPYTHON 3 4,706 Apr-03-2020, 06:15 PM
Last Post: deanhystad
  [PyQt] Drag items across tabs Alfalfa 5 4,686 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [PyQt] Drag and drop converter Raures 0 4,468 Oct-01-2017, 07:44 PM
Last Post: Raures
  Drag and Drop GUI crystallized_neuron 3 16,526 Apr-26-2017, 08:41 PM
Last Post: joe_anonimist
  Drag and drop image object vijaysagi 1 16,771 Apr-06-2017, 09:36 AM
Last Post: wuf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020