Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Having trouble understanding a script behaviour

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
noesis
Posts: 15
Joined: Wed Feb 01, 2012 3:05 pm

Having trouble understanding a script behaviour

Post by noesis »

I'm having trouble with getting a script to work like I think it should. Essentially it is an adaptation of a script Pako offered in the forums some time ago (viewtopic.php?f=5&t=2747&p=15789&hilit= ... ion#p15789) concerning getting window coordinates and moving the mouse pointer to that window (using a Find Window in the Event Ghost macro, before the script). I've got this part working without issue, the adaptation is that I want to move the mouse cursor back to where it was before the macro was initiated.

What is stumping me is that this works using mediaportal as the target for the window but it is meant for PowerDVD10 in Theatre Mode, and it is failing to work when that program is the target for the find window action. Script follows:

Code: Select all

from win32gui import GetWindowPlacement
from eg.WinApi import GetCursorPos
hwnd = eg.lastFoundWindows[0]
wp = GetWindowPlacement(hwnd)
mousePoint = GetCursorPos()
eg.plugins.Mouse.MoveAbsolute(wp[4][0]+100, wp[4][1]+100)
eg.plugins.Mouse.RightButton()
#eg.Wait(2.0)
# move mouse back to original position
#eg.plugins.Mouse.MoveAbsolute(mousePoint[0],mousePoint[1])
As the posted code goes, it works but the mouse pointer stays over the new coordinates. If I de-comment the last line, which is meant to return the mouse pointer back to it's original position, I get no errors and the mouse pointer moves back to where it was but the RightButton command doesn't seem to execute.

If I de-comment the 3rd last line (the "eg.Wait(2.0)") then I can see the mouse moves to where it should, does nothing for 2 seconds then moves back, and If I comment out the last line but keep the Wait command, the mouse moves then executes the right click after 2 seconds, even though the Wait is after the right click ?? - Like I said having trouble understanding this behaviour, is it what should be happening ? i.e. the Wait applying to the previous command ? any advice would be appreciated, This is the first time I've tried any type of Python scripting, so there could be a huge number of things I don't understand/realise with regard to how Python works.
Post Reply