Author Topic: Stacking Logic Blocks?  (Read 4873 times)

0 Members and 2 Guests are viewing this topic.

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Stacking Logic Blocks?
« on: October 20, 2019, 01:38:16 PM »
I tried to search the forums but I couldn't find an answer because I couldn't think of good search words to use. Anyway...

Is it possible to have If functions inside of other If functions? I am trying to write a command that will perform different tasks taking multiple variables in mind. I'll just write out a example

If NOT ProgramFocused == Videogametitle
     (If {1} == iTunes
          (If NOT ProcessRunning == iTunes
               (Launch iTunes)
     (If {1} == Chrome
          (If NOT ProcessRunning == Chrome
               (Launch Chrome)

I don't know, something like that. If the video game has focus, then it doesn't go on to anything else. But if the video game doesn't have focus than it goes on to other if functions.
Is there actually a way to disable Vox if certain apps have focus?

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #1 on: October 20, 2019, 01:42:07 PM »
I just want to say that I discovered this software due to my frustration with Cortana. Cortana would minimize my games thinking I was talking to her. I was looking for a voice command alternative and I discovered this and it is awesome. I can't believe I have never heard of this before. I am still setting it up but it seems awesome. I just want to say good work.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #2 on: October 21, 2019, 07:34:03 PM »
Welcome to VC and the forum.

You can't nest logic blocks within logic blocks, but you can have consecutive logic blocks and you can use the action VC.StopMacro to avoid moving on to the next IF statement as needed.

It sounds as though you will want to use events (https://voxcommando.com/mediawiki/index.php?title=Events), not a voice command, in order to evaluate whether your video game is active.

VC automatically generates events every time a window is focused or unfocused.

It depends what you mean by "disable". If you want VC to stop listening for voice commands while you're playing a videogame, then the action to use is VC.Off.

VC is very customizable and there are different ways to solve the same problem. Here is one possible approach to your situation (if I'm understanding the objectives properly). I used Chrome focus events just as an example.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.5-->
<commandGroup open="True" name="Daniel's commands" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="310" name="Playing video game (stop listening)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Here i'm using the Chrome.focused/unfocused events. You would look in the History window for the events associated with your videogame. They will appear there after you have focused and unfocused that program. Drag those events onto this command in your command tree. You can then delete my placeholder events, and you'll have to update the if statements in the command macro accordingly.">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{LastEvent}&amp;&amp;Focused.Chrome</ifParams>
      <then>
        <action>
          <cmdType>VC.Off</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{LastEvent}&amp;&amp;Unfocused.Chrome</ifParams>
      <then>
        <action>
          <cmdType>VC.On</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>Focused.Chrome</event>
    <event>Unfocused.Chrome</event>
  </command>
  <command id="288" name="test launch {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="The first IF statement is just ot make sure that you're not playing the video game. If you are, we immediately exit this macro without doing anything. Otherwise, it goes on to evaluate the second IF statement.&#xD;&#xA;&#xD;&#xA;I've attached a sample payload XML file to the forum post. You'll need to copy it into your VC/Payloads folder. You can delete the OSD action; it's just here to demonstrate the difference between {1} and {PF.1} notation.">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProgramFocused</ifType>
      <ifParams>chrome&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProcessRunning</ifType>
      <ifParams>{PF.1}&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>{PF.1} is already running.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Launch</cmdType>
          <params>
            <param>{1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>test launch</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\Daniel_programs.xml</payloadFromXML>
  </command>
</commandGroup>

See the link in my signature tips if you're not sure how to import the above (but basically you can just copy and paste it into your command tree in the editor).

You'll also need the attached payload XML file, which you should place in your VC\payloads folder. It's just an example. You may have to revise it to work properly on your system.



« Last Edit: October 23, 2019, 12:16:36 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #3 on: October 23, 2019, 11:45:34 AM »
Welcome to VC and the forum.

You can't nest logic blocks within logic blocks, but you can have consecutive logic blocks and you can use the action VC.StopMacro to avoid moving on to the next IF statement as needed.

It sounds as though you will want to use events (https://voxcommando.com/mediawiki/index.php?title=Events), not a voice command, in order to evaluate whether your video game is active.

VC automatically generates events every time a window is focused or unfocused.

It depends what you mean by "disable". If you want VC to stop listening for voice commands while you're playing a videogame, then the action to use is VC.Off.

VC is very customizable and there are different ways to solve the same problem. Here is one possible approach to your situation (if I'm understanding the objectives properly). I used Chrome focus events just as an example.



Thank you, nime5ter. This is some very useful information. I had to change a few things inside your code to get it to work (e.g. Focused.VoxCommando-->Focused.chrome, Launch--> Launch.OpenFile) but I would say this solves probably all of my problems. And now I have a better understanding of how do use payloads as well as working around the limitations by using the StopMacro action. I'm glad you mentioned the StopMacro action. I was looking for something like this.

The payload thing inspired a new idea, and so maybe you could tell me if something was possible. Is it possible to have the "If ProgramFocused" refer to a payload list? So that way if I ever needed to add a game or something, I could just edit the payload rather than all the individual events and stuff.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #4 on: October 23, 2019, 06:28:05 PM »
Sorry for the mislabeled event in my example. I've fixed it now for future forum visitors. Glad you know what you're doing and could diagnose the error yourself. :)

I am not fully envisioning what you have in mind with the payload XML and events, to be honest.

There are some payloadXML actions, which you can explore via the action selection helper tool in the interface or via the wiki. They permit you to add data to a payload XML file or get results from a payload XML file that can then be used in subsequent actions.


« Last Edit: October 23, 2019, 08:22:28 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #5 on: October 23, 2019, 11:51:07 PM »
I think I thought of a solution for what I was trying to do but it would require checking for multiple processes in a single logic block. Is that possible? Something like "If ProcessRunning == chrome,notepad,itunes"...

Well, let me see if I could better explain my goal using an example. Say I had a payload called GamesList.xml that just had a list of different games and there process names.

e.g.
Code: [Select]
    <payload>
        <value>r5apex</value>
        <phrase>Apex</phrase>
    </payload>
    <payload>
        <value>Tslgame</value>
        <phrase>PUBG</phrase>
    </payload>

I was hoping I could do something like "If Process Running == GamesList.xml" so that way it would check for all the processes listed in that payload. The closest I have gotten is having a payload that says

Code: [Select]
    <payload>
        <value>chrome</value>
        <phrase>Games</phrase>
    </payload>
and then the action
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.7-->
<command id="397" name="Is Games Running" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PayloadXML.GetValue</cmdType>
    <params>
      <param>C:\Users\7heBo\Documents\VoxCommando\payloads\GamesList.xml</param>
      <param>Games</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>ProcessRunning</ifType>
    <ifParams>{LastResult}&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Game is running</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <params>
          <param>Game is not running</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Check Games</phrase>
</command>
All I would need is multple values set to the same phrase. something like
<value>chrome,itunes,notepad,etc...</value>
<phrase>Games</phrase>

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #6 on: October 24, 2019, 05:52:44 AM »
So, something like this?
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.5-->
<commandGroup open="True" name="Loop through payloads and launch" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="412" name="Check game status" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>File.Read</cmdType>
      <params>
        <param>{Path.VC}\payloads\Daniel_programs.xml</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>&lt;phrase&gt;(.*?)&lt;/phrase&gt;</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.MatchToEvent</cmdType>
      <params>
        <param>processChecker</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Check game status</phrase>
  </command>
  <command id="288" name="Do something with game" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="The custom event we generated carries a payload value from our regular expression matches -- i.e., a payload phrase. Here we look up its value and do something with it -- launch it. This will launch all the games listed in the payload xml  if they're not yet running ... ?">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProcessRunning</ifType>
      <ifParams>{1}&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>{1} is already running.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>PayloadXML.GetValue</cmdType>
          <params>
            <param>payloads\Daniel_programs.xml</param>
            <param>{1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>Launch.OpenFile</cmdType>
          <params>
            <param>{LastResult}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>processChecker</event>
  </command>
</commandGroup>

"Check game status" command: reads payload xml file. Captures each phrase in the list as a {match.#}. Passes that as a payload attached to custom event called processChecker. This is using the action Results.MatchToEvent

"Do something with game" checks whether that payload process is running, and does something with it.
« Last Edit: October 24, 2019, 08:52:00 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #7 on: October 24, 2019, 08:30:37 AM »
Trying to paste your code into Vox I get "invalid XML". I will try and go through and see if I can figure out what is in there.

edit:
Okay, I figured out why it wasn't working. the second to last line says "</command"  and is missing that ">". No worries. I'm gonna play with this now to see what you have here.
« Last Edit: October 24, 2019, 08:58:26 AM by Daniel »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #8 on: October 24, 2019, 08:55:32 AM »
I've re-copied the command group and replaced it above. See if that helps. (I tested copy and pasting it from the forum back in to my command tree and it is working for me.)

My commands are using the "Daniel_programs" payload xml file that I posted in my first example above.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #9 on: October 24, 2019, 11:11:43 AM »
Thanks, nime5ter. You have been a tremendous help. I think I have all the tools I need. At least for now. I'm sure I will think of new concoctions in the future.

Before I let you go I had a couple of random inquiries that I'll just ask here rather than create new threads.

1. The VC.RestartFull action doesn't seems to work. I don't understand what I am doing wrong.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.7-->
<command id="67" name="Restart Vox" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>VC.RestartFull</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Restart Vox</phrase>
</command>

2. Is it possible to check for a key state? Like it would check if a key is currently being pressed?

3. Is there any sort of GetColorPixel Action? It would check what color a certain pixel on the screen is?

I went through the actions and didn't really see anything like these.
« Last Edit: October 24, 2019, 11:44:00 AM by Daniel »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #10 on: October 24, 2019, 01:55:29 PM »
1. Your command looks great and it's working for me.

Can you be more specific about what's happening on your end?
What does the history window indicate when you issue the voice command?

2. You'll need to download and enable the Hook plugin. Go to your Plugins menu option to initiate the download. Because key loggers upset anti-virus software, it is not part of the main application download.
https://voxcommando.com/mediawiki/index.php?title=Plugin_Hook

3. I don't think so, but I'll get back to you on this one. You want to specify coordinates in the active window, and get the color info back?
« Last Edit: October 25, 2019, 03:46:45 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #11 on: October 25, 2019, 01:15:41 PM »
1. It just doesn't work. It acknowledges my command. I even put a confirmation to make sure but it doesn't restart. I imagine it is because I just got this and am still testing it with the trial version so maybe they don't allow it to restart so conveniently to prevent people from just using the trial forever.

2. I don't have any actions in mind that would require this at the moment but it is good to know that it has the potential functionality. Like to create a loop that would stop with a certain keypress or something.

3. Bummer on this one. I like using these. I guess i could always revert to AHK if it don't exist in Vox.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Stacking Logic Blocks?
« Reply #12 on: October 25, 2019, 05:47:01 PM »
1. It just doesn't work. It acknowledges my command. I even put a confirmation to make sure but it doesn't restart. I imagine it is because I just got this and am still testing it with the trial version so maybe they don't allow it to restart so conveniently to prevent people from just using the trial forever.

Oh! Of course. Stupid of me. Yes, absolutely that's true. Auto-restart is blocked if you're on a trial. I even say so myself in an earlier thread.
https://voxcommando.com/forum/index.php?topic=2460.msg21161


Quote
3. Bummer on this one. I like using these. I guess i could always revert to AHK if it don't exist in Vox.

Yes, and I believe some users actually do some communication back and forth between ahk and Vox, so maybe someone will pipe up with more information.

There is also a Feature Request board on the forum. In theory, it doesn't hurt to ask.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

PegLegTV

  • $upporter
  • Sr. Member
  • *****
  • Posts: 497
  • Karma: 43
    • View Profile
Re: Stacking Logic Blocks?
« Reply #13 on: October 26, 2019, 06:27:37 PM »
Hey Daniel, I've done some work with AHK and VC they work fairly well together, I modified a Netflix script to work with VC and added in a bunch of extras, It's been awhile but I'm pretty sure that I used PixelGetColor to verify what screen it was on in the app, here's a link to the post where I shared the .ahk file: https://voxcommando.com/forum/index.php?topic=2145.msg18598#msg18598

it also has some 'Run' actions that's what you'll need to trigger events in VC, I hope this helps

Daniel

  • Jr. Member
  • **
  • Posts: 25
  • Karma: 2
    • View Profile
Re: Stacking Logic Blocks?
« Reply #14 on: November 19, 2019, 11:28:05 AM »
Thanks PegLegTV for the information. I haven't been messing with my commands lately, I haven't thought of anything that would require the PixelGetColor but atleast now I know there is ways out there.