I sometimes need two or three programs active at once. I dedicated three buttons on my remote, one for each of the three programs that I will use.
Button "A" opens program one
Button "B" opens program two
Button "C" opens program three
To switch focus between programs I want to press the corresponding button. If the program is NOT open it will open it, however if it is already open is switches focus to program.
I basically need some kind of "if then" conditional loop. So far I have used duplicate Find Window event but feel there must be a better way. I am probably missing something simple and hoping that someone can help out.
Thanks for any suggestions.
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.
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.
Looking for fewest lines of code to reach goal
Re: Looking for fewest lines of code to reach goal
I guess I will have to learn Python programming to achieve what I want to do. Are there any tutorials for first timers wanting to learn this language?
Re: Looking for fewest lines of code to reach goal
Sounds like a good way to do it, to me. If you post your .xml you might get some better suggestions on how to clean it up.burchis wrote:So far I have used duplicate Find Window event but feel there must be a better way.
-
barnabas1969
- Experienced User
- Posts: 133
- Joined: Sat Feb 04, 2012 1:42 am
Re: Looking for fewest lines of code to reach goal
Here's one solution. It requires setting up three different macros for each button.
Here's an example for Button A:
In the first macro, add the "Find a window" action. Un-check the box that says "stop macro if target is not found". Do not check the box that says "stop macro if target is found".
Then, add a Python Script action. In this action, add the following code:
Now, create two more macros... one will be triggered by the event Main.StartProgButtonA, and the other will be triggered by the event Main.BringForegroundButtonA. Add actions to those macros to do what you want (bring it to the foreground, or start the program).
There is probably a more elegant way to do it. For example, the first part of the if statement could simply start the program instead of triggering an event. The else-part of the script could do the actions you want to bring it to the foreground. You'll have to search the documentation for those functions.
Here's an example for Button A:
In the first macro, add the "Find a window" action. Un-check the box that says "stop macro if target is not found". Do not check the box that says "stop macro if target is found".
Then, add a Python Script action. In this action, add the following code:
Code: Select all
if eg.result == []:
eg.TriggerEvent("StartProgButtonA")
else:
eg.TriggerEvent("BringForegroundButtonA")There is probably a more elegant way to do it. For example, the first part of the if statement could simply start the program instead of triggering an event. The else-part of the script could do the actions you want to bring it to the foreground. You'll have to search the documentation for those functions.
Re: Looking for fewest lines of code to reach goal
Here's a thread on a loosely related topic.