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.

How to get the front window name to trigger a proper action?

If you have a question or need help, this is the place to be.
Post Reply
fabien44
Posts: 3
Joined: Sat Aug 28, 2010 9:17 am

How to get the front window name to trigger a proper action?

Post by fabien44 »

Hello,

i would like to trigger an action depending on the mostfront window.

Here the scenario i want to implement:

Find frontmost window
If Window1 then jump to A
If Window2 then jump to B

How can i do this? I guess with python script but what would be?

Thanks in advance,
Fabien
skat
Posts: 48
Joined: Thu Jun 23, 2011 10:11 am

Re: How to get the front window name to trigger a proper act

Post by skat »

Maybe something similar to what I used:

Find Window: ehshell.exe
Python Script:

Code: Select all

from eg.WinApi.Dynamic import (GetForegroundWindow)
if eg.lastFoundWindows and eg.lastFoundWindows[0] == GetForegroundWindow():
    eg.result = False
else:    
    eg.result = True
If successful jump to "AlphaNumpad1"
User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: How to get the front window name to trigger a proper act

Post by jinxdone »

You could just trigger a new event with the window name + a prefix. Then just assign this this to another macro.

You may want to add the first event's name with eg.event.string, and also using the event payload instead of one long event string may be helpful..

Code: Select all

from eg.WinApi import (GetWindowText)
from eg.WinApi.Dynamic import (GetForegroundWindow)
eg.TriggerEvent('Foreground.' + GetWindowText(GetForegroundWindow()))
fabien44
Posts: 3
Joined: Sat Aug 28, 2010 9:17 am

Re: How to get the front window name to trigger a proper act

Post by fabien44 »

Great! It works very nice :D
Thanks a lot!
themaster1
Experienced User
Posts: 133
Joined: Wed Feb 03, 2010 9:02 pm

Re: How to get the front window name to trigger a proper act

Post by themaster1 »

Someone give me hints i wanna do the following thing:
- Find frontmost window
- left mouse click on the window
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: How to get the front window name to trigger a proper act

Post by jonib »

themaster1 wrote:Someone give me hints i wanna do the following thing:
- Find frontmost window
Add Macro...->Window\"Find a window"
- left mouse click on the window
Add Action...->Mouse\"Left mouse button"

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
themaster1
Experienced User
Posts: 133
Joined: Wed Feb 03, 2010 9:02 pm

Re: How to get the front window name to trigger a proper act

Post by themaster1 »

with a python script i mean otherwise i know how
eatmeimadanish
Experienced User
Posts: 118
Joined: Thu Oct 01, 2009 5:11 pm

Re: How to get the front window name to trigger a proper act

Post by eatmeimadanish »

Just copying actions will get you the XML and command line, just add eg.plugins before most of them and it works.

Code: Select all

eg.plugins.Window.FindWindow(u'program.exe', None, None, None, None, None, False, 0.0, 0)
eg.plugins.Mouse.LeftButton()
themaster1
Experienced User
Posts: 133
Joined: Wed Feb 03, 2010 9:02 pm

Re: How to get the front window name to trigger a proper act

Post by themaster1 »

Thanks for the hint, now what if i want to add "if-else" conditions.Let's say i want to get the name of the window

if window name=blabla

eg.plugins.EventGhost.ExclusiveEnablefolder blabla
Post Reply