Sunday, August 20, 2017

#1 2017-04-12 07:21:00 pm

DonL
Member
Registered: 2015-08-31
Posts: 19

Coordinates Question

Hi all!  I just need to ask a simple question regarding the python positions for posx and posy.

Where is the starting point for these references?  Is it the bottom left hand corner of the screen?

Offline

 

#2 2017-04-12 09:07:39 pm

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2683
Website

Re: Coordinates Question

Would be nice if you share the used library with us. There is no standard rule because when using PyObjC it will be top left and when using math based libraries it is bottom left. Without example code it's really hard to tell neutral

Offline

 

#3 2017-04-12 09:33:46 pm

DonL
Member
Registered: 2015-08-31
Posts: 19

Re: Coordinates Question

Sorry.  I should have included the script.  I'm trying to adapt this widely used mouse click script to automate a video transition.

I have the following saved as a Service and then assigned to a function key.

Applescript:

on run {input, parameters}
   
   activate application "ATEM Software Control"
   tell application "System Events"
       tell process "switchergui"
           activate
       end tell
   end tell
   
   set x to 1259
   
   set y to 966
   
   
   
   do shell script "

/usr/bin/python <<END

import sys

import time

from Quartz.CoreGraphics import *

def mouseEvent(type, posx, posy):

theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)

CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):

mouseEvent(kCGEventMouseMoved, posx,posy);

def mouseclick(posx,posy):

mouseEvent(kCGEventLeftMouseDown, posx,posy);

mouseEvent(kCGEventLeftMouseUp, posx,posy);

ourEvent = CGEventCreate(None);

currentpos=CGEventGetLocation(ourEvent); # Save current mouse position

mouseclick("
& x & "," & y & ");

mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position

END"

   
   activate application "ProPresenter 5"
   
   
   return input
end run

I think you answered my question about the coordinates, which is great and thanks for that!  Now I'm getting an error message like this.

Applescript:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `

/usr/bin/python <<END

import sys

import time

from Quartz.CoreGraphics import *

def mouseEvent(type, posx, posy):

theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)

CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):

mouseEvent(kCGEventMouseMoved, posx,posy);

def mouseclick(posx,posy):

mouseEvent(kCGEventLeftMouseDown, posx,posy);

mouseEvent(kCGEventLeftMouseUp, posx,posy);

ourEvent = CGEventCreate(None);

currentpos=CGEventGetLocation(ourEvent); # Save current mouse position

mouseclick(1259,966);

mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position

END'

Offline

 

#4 2017-04-13 06:59:16 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2683
Website

Re: Coordinates Question

I see that you have borrowed parts of my code from this post. The problem is that you have changed the markup and indentation of my original code. Python uses indentation for scope like other programming languages uses curly braces or an end keyword as in AppleScript.

Offline

 

#5 2017-04-19 06:22:10 pm

DonL
Member
Registered: 2015-08-31
Posts: 19

Re: Coordinates Question

DJ Bazzie Wazzie wrote:

I see that you have borrowed parts of my code from this post. The problem is that you have changed the markup and indentation of my original code. Python uses indentation for scope like other programming languages uses curly braces or an end keyword as in AppleScript.


Indeed I did sir.  Thank you!  You've written a great piece of code.  I'm sure you're aware that it's been shared far and wide!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)