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.

determening the top most windows

If you have a question or need help, this is the place to be.
Post Reply
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

determening the top most windows

Post by orennahum »

Hello,

I want to send an event to an application only if the application is currently the active application (top most window). How can I do that ?

Thanks,
Oren
Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: determening the top most windows

Post by Bartman »

use the find window action.
you don't send events to application but use events to trigger actions.
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

Re: determening the top most windows

Post by orennahum »

I'm using the find window action. But I also want to know if that window belongs to the top most application, otherwise if want to stop.

How can I do that ?

Thanks,
Oren
Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: determening the top most windows

Post by Bartman »

If you check the only foremost window action you will only get the foremost window.
Do you want to combine the search for a specific program and that the fact that is the foremost window?
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

Re: determening the top most windows

Post by orennahum »

exactly, this is what i want.

Oren
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

Re: determening the top most windows

Post by orennahum »

anyone ?
Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: determening the top most windows

Post by Bartman »

This involves some scripting. Although probably only a few lines I have to take a look at the code first.
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

Re: determening the top most windows

Post by orennahum »

i will appreciate it.

Oren
orennahum
Posts: 6
Joined: Sun Sep 06, 2009 10:22 am

Re: determening the top most windows

Post by orennahum »

anyone ?
Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Re: determening the top most windows

Post by Bartman »

After switching to Win7 here is the script.
This sends an "A" to notepad if it is the foreground window.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0">
    <Folder Name="ForegroundWindow" Expanded="True">
        <Macro Name="Emulate Keystrokes: A" Expanded="True">
            <Event Name="GameVoice.Command" />
            <Action>
                EventGhost.PythonScript(u'from eg.WinApi.Dynamic import GetForegroundWindow\nfrom eg.WinApi.Utils import GetWindowProcessName\nhwnd = GetForegroundWindow()\nif hwnd:\n    processName = GetWindowProcessName(hwnd)\n    if processName == "notepad.exe":\n        eg.result = hwnd\n    else:\n        eg.result = None\nelse:\n    eg.result = None\n        ')
            </Action>
            <Action>
                EventGhost.NewJumpIf(XmlIdLink(1384), 1, False)
            </Action>
            <Action>
                Window.SendKeys(u'A', False)
            </Action>
        </Macro>
        <Macro Name="Comment" id="1384" Expanded="True">
            <Action>
                EventGhost.Comment()
            </Action>
        </Macro>
    </Folder>
</EventGhost>
SANGER_A2
Posts: 6
Joined: Wed Feb 10, 2010 10:38 am

Re: determening the top most windows

Post by SANGER_A2 »

The OP didn't bother to reply and thank you Bartman. So although I'm resurrecting a dead thread, I'm doing it for him! This is one of quite a few threads I've looked through when trying to solve the same problem and your solution is the easiest to understand and use and it works great for me.

So THANK YOU! :D
Post Reply