click drag - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: click drag (/thread-24057.html) |
click drag - olivers - Jan-29-2020 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 positionbut 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 RE: click drag - Larz60+ - Jan-30-2020 If you're not too deeply dependant on Quartz, wxpython has some good tools for this. see: https://wxpython.org/Phoenix/docs/html/dnd_overview.html |