Author Topic: Variable looping (loop blocks) - how to break the loop?  (Read 12771 times)

0 Members and 2 Guests are viewing this topic.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #15 on: August 21, 2015, 10:35:54 PM »
True! Now it is obvious!
I'll try it when I get to my computer. Now I am in the phone.

Thank you.
btw this is one of the reasons VC is so good, you still enjoy it!

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #16 on: August 22, 2015, 04:56:15 PM »

this comment might be very dumb ....
referring to the first post, I the the issue has 2 tiers....

first: make sure a process is launched and running ...
this I handle by setting a timer that trigger the same command again ... the command start with an if process running, ture: trigger set focus ... false: trigger timer again (I usually put a kill timer before the if, just in case)

Second: I will just use use window.focus ... then do everything I want ... it has been working like a charm since timers were introduced ...
When Voice command gets tough, use hand gestures

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #17 on: August 22, 2015, 07:31:32 PM »

In the beginning of the video I show how my last command works with the enhancement proposed by James. Thanks everybody!
But then, in the end of the video I show a weird behavior with window.focus. This is the problem that I noticed accidentally and have mentioned earlier in this thread. Am I doing anything wrong?

https://youtu.be/WUOzp_8vcG8

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #18 on: August 22, 2015, 11:23:55 PM »
when I use Window.focus on Chrome and Firefox it works with both and both actions are slightly greyed out in the history window,
as I said before chrome on my W8.1 PC works just fine and also works on my W7 PC, I wonder if its due to the fact that chrome runs multiple different processes so its trying to focus a hidden window,

back when I used NetfliXBMC I had problems finding the right chrome window to close using eventghost even though there was only one window open it would show 3 different windows, so maybe VC isn't focusing the right chrome window,

I tried using different window.focus such as "chrome.exe", "google chrome" and tried them capitalized but those didn't work for me, I'm not sure what may be stopping yours from working, is chrome the only window that its having trouble focusing?

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #19 on: August 23, 2015, 12:02:39 AM »
I only noticed that behavior with chrome and I also believe in the same cause that you mentioned. The scripting language I'm used to program, autoit, needs the actual name of a window, ie "Untitled - Notepad" for notepad, so it can attach to such window. Actually it allows for other few things to match to a window, but none of the standard ways use the process name as James uses in VC. Then with autoit it is still possible to use other ways to enumerate all the available windows pertaining to a process and then one can attach to one of those windows.
Long story short, I'm mentioning autoit only because I suppose VC can have the same difficulty to attach to the correct window. What I used to do in autoit is to attach using what is more likely to result in the right window to be selected. But it depends on the target program.

« Last Edit: August 23, 2015, 12:06:13 AM by marcusvdt »

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #20 on: August 23, 2015, 12:29:17 AM »
I've never used autoit but I have heard that its similar to AutoHotKey, and from what you just described it sounds like it is,

I know this wouldn't be the best solution but maybe instead of using Window.focus you could use autoit or AutoHotKey script to call focus to Chrome and other windows by using the cmd line parameters and just passing the window name you want to focus maybe something like this,

(for this to work you will need to install Autohotkey)
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<command id="1299" name="Find Window AHK" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch.Hidden</cmdType>
    <params>
      <param>find window.ahk</param>
      <param>chrome</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.Hidden</cmdType>
    <params>
      <param>find window.ahk</param>
      <param>XBMC</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
</command>

place "find window.ahk" in your VC folder

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #21 on: August 23, 2015, 01:34:09 AM »
Thanks PegLegTV. While I was recording this video and writing this post, you posted a response which seems to have the same purpose of what I just made. Take a look below...

This is some of the data about the chrome window which I use in my video. In autoit, I can use a combination of any of these parameters below to make sure I'm attaching to the right window:
Title:   Google - Google Chrome
Class:   Chrome_WidgetWin_1
>>>> Visible Text <<<<
Chrome Legacy Window

The video below shows how VC's method is failing and confirming the reason is probably the existence of more than one process for chrome. Btw, the wiki mentions it can fail and I'm sure James already knows the exact situations where it can fail. I'm not complaining at all.

The video also shows how I can solve that situation with external scripting, but wouldn't like to go that path because it makes the stuff more complicated because then I would need to make my script to talk with VC and vice versa. Probably will not justify the effort. Also will need to keep track of external source code, etc, etc...
The interesting thing is that both VC and autoit scripting are using some windows api to get control of windows, so maybe James can find a way to implement different matching techniques? If not, that's fine anyway as I can workaround it with scripts as shown in the video.

https://youtu.be/GI0Z981PbMQ



jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #22 on: August 24, 2015, 01:03:33 PM »
I've tested the focus action with chrome on many different computers running different versions of Windows from Vista to W10 and never had a single failure in focusing chrome.  I'm not sure what is special about your system.  Chrome always creates many processes so that by itself is not necessarily the problem.

Obviously there is room for improvement with the focus action.  For a while now I have been considering a "Window" plugin that would allow us to target windows using various methods (process, window names, class etc.) and possibly do more than just focus them (monitor, or resize/reposition etc.).  I think there is probably a lot that could be done here that could be useful.  The only problem is to take the time to actually create it.

In your case, I suggest you try a few things since I think the issue you are having is somewhat unusual.  You could try uninstalling and reinstalling chrome.  Also try using admin privilege and disabling UAC just to be sure.  Otherwise you can use another solution such as autoit for now.  I will probably make this plugin but at this point I cannot say when.  It is a bad time for me with too many different things that require my time pulling me in different directions.

For the record, when I mentioned that focus was not always working in the action description, I don't think this had anything to do with multiple processes or with chrome specifically.  It was more a question of Windows deciding not to allow programmatic focusing of a window in order to "protect" the user experience somehow.  In some cases, what would happen is that the window in question would flash on the task bar but not actually focus.  I could never make sense of when Windows would decide to do this though.  There could also be issues with certain programs using true fullscreen mode and not allowing other windows to come forward but I'm not 100% sure about this anymore.  I don't use the focus actions all that much but recently it seems that they have just been working fine for me.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #23 on: August 24, 2015, 01:07:18 PM »
If anyone else has experienced any reproducible problems using the focus action with chrome or any other programs, please let us know.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #24 on: August 24, 2015, 02:07:36 PM »
I'm not sure the problem is related to various process of chrome or not. Maybe it is the issue as you mentioned of the window flashing (but it does not flash because the window in not actually minimized). Don't know.
I'll use an autoit script in the meantime, just not sure yet how my script will send a confirmation to VC. Will try something like an exit code or something. Or maybe I can trigger an event using the API, not sure yet.

Thanks for looking at it!


PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #25 on: August 24, 2015, 02:27:57 PM »
I'll use an autoit script in the meantime, just not sure yet how my script will send a confirmation to VC. Will try something like an exit code or something. Or maybe I can trigger an event using the API, not sure yet.

If you want to trigger an event using Autoit, I posted an Autohotkey script that controls windows 8.1 netflix app, and I have it trigger events when it starts, stops and when you start and stop a movie as well,

This post has the AutoHotkey script, you can take a look and see an example of how to trigger an event with your autoit script
http://voxcommando.com/forum/index.php?topic=2145.msg18598#msg18598

note:: with my method the script needs to be in the main VC folder, if you wanted to put it in a different folder then you will need to add the file path


jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #26 on: August 24, 2015, 02:44:53 PM »
VC automatically generates events when a new window is focused.  But I'm sure you already knew that. :)

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #27 on: August 24, 2015, 02:55:33 PM »
James, yes I know!  :bonk

But as you can see in my video, such event gets triggered even when window.focus seem to fail.

But you are right, as I'll be using the autoit script to set the focus, then the "focused" event for that window truly means such window has been put in focus.
And I can double confirm also with the logic block.

Consistent enough!  ;)

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #28 on: August 24, 2015, 03:10:26 PM »
If you want to trigger an event using Autoit, I posted an Autohotkey script that controls windows 8.1 netflix app, and I have it trigger events when it starts, stops and when you start and stop a movie as well,

This post has the AutoHotkey script, you can take a look and see an example of how to trigger an event with your autoit script
http://voxcommando.com/forum/index.php?topic=2145.msg18598#msg18598

note:: with my method the script needs to be in the main VC folder, if you wanted to put it in a different folder then you will need to add the file path

Thanks, I've found an example in your code. The syntax in autoit would be similar.
Btw, soon I'll probably port or adapt your Netflix script to autoit. No special reason, it's just easier to me to manage it later. Will need to translate all your commands, check what else I may need, etc. Thanks for providing the source code!

About this way of triggering events, honestly I did not notice yet this is possible. Wonderful!

Thanks guys!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Variable looping (loop blocks) - how to break the loop?
« Reply #29 on: August 24, 2015, 05:45:31 PM »
But you are right, as I'll be using the autoit script to set the focus, then the "focused" event for that window truly means such window has been put in focus.
And I can double confirm also with the logic block.

I really don't think you will need to check the focus using a logic block.  I can't think of any circumstance in which the event would be fired and then the logic block would return false on checking the focus.

Regarding the command line api, please note that it is ultimately just sending a UDP message so if you are able to send UDP easily from your own program it is probably preferable, but not a big deal either way.