VoxCommando

Help and Support (Using VoxCommando) => VoxCommando Basics and Core Features => Topic started by: Slalomen on July 04, 2015, 03:12:43 PM

Title: Hook and monitoring programs... How?
Post by: Slalomen on July 04, 2015, 03:12:43 PM
Hello everyone!
There is a problem: I have mouse with Xbuttons and after i press XButton1 i  talk in Team speak... In Hook settings is monitoring clicks of mouse, and then i push the XButton1 VC go to standby mode(i done macros this triggers). But then Hook monitoring mouse clicks there are many history in VC and also freezing mouse movements... After i write macros then focus in VC(unfocused.* and focused.*) changing do checking (Process is running ? ts3client_win64) if run do HookEnabled else HookDisable... And also checking then XButoon1 is Up... But after some time Hook don`t work(don`t monitoring mouse clicks). There are my group "Hook":
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.1-->
<commandGroup open="True" name="Hook" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="221" name="Launch Hook" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Hook.Enable</cmdType>
      <params />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="199" name="Monitoring of Hook" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProcessRunning</ifType>
      <ifParams>ts3client_win64&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>Hook.Enable</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Hook.Disable</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>focused.*</event>
    <event>Hook.Mouse.Up.XButton1</event>
  </command>
  <command id="190" name="Hook Vc.Stanby" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProcessRunning</ifType>
      <ifParams>ts3client_win64&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>VC.Standby</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>Hook.Mouse.Down.XButton1</event>
  </command>
  <command id="206" name="Hook Vc.On" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>ProcessRunning</ifType>
      <ifParams>ts3client_win64&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>VC.On</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>Hook.Mouse.Up.XButton1</event>
  </command>
</commandGroup>

Question: How monitoring programs status in VC in background mode for example Team Speak and return parameter... Then Team Speak is off Hook disable then on enable then changing status of program then and changing parameter and Hook disable/enable.
Or simply then run TS or TS already running Hook is enable then TS shutdown or off Hook is disable...

Sorry my bad English. Thanks.
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 05, 2015, 10:00:13 AM
Do you really want to monitor if TeamSpeak is running, or do you actually want to monitor is TeamSpeak is focused?

If you want to enable the Hook plugin only when TeamSpeak is focused, then this is much easier to do, and much less work for VC.

The way you are doing it now, every time you press or release the mouse, VC must scan all running processes to see if TeamSpeak is running.  This is creating too much work for the PC.  This is probably why you see freezing.

You might also want to just leave VC in standby mode while TeamSpeak is running instead of switch back and forth between On and Standby every time you click a mouse.  You can still give VC commands while you are in standby mode by using a prefix.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 01:14:22 PM
Yep really want to monitor TeamSpeak running, because i use VC then i gaming and use also TS... Hook use for switch mode of VC. For examle i play in game and use VC for commands in game and in this time TS is running and i also can speech with friends...

If its possible in VC monitoring the status of programs?
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 05, 2015, 07:02:33 PM
Yes, there are several ways.

A Python script that checks if the process is running in a separate thread is probably safest.

Download the Python script that is attached to this message (processRunningCheck.py) and place it in your VoxCommando\PY folder.

You will need to enable the Python plugin in VoxCommando.

Then you can change your command group to:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<commandGroup open="True" name="Hook" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="190" name="Hook VC.Standby" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.Standby</cmdType>
      <params />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Hook.Mouse.Down.XButton1</event>
  </command>
  <command id="206" name="Hook VC.On" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.On</cmdType>
      <params />
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Hook.Mouse.Up.XButton1</event>
  </command>
  <command id="207" name="Load Python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\processRunningCheck.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

---

The Python script will be executed automatically when you first launch VoxCommando. It will check the current status of the 'ts3client_win64' process every 5 seconds. You can edit the timing if you want.

1. When process running changes to "True", the Python script will enable the Hook plugin.

2. When process running changes to "False", the Python script will disable the Hook plugin.

3. Also, if the status of the process changes, the script will trigger a "True" event in VoxCommando (if process is now running) or a "False" event (if process is now quit). You do not need to use the event, but it is there just in case it is helpful for you or for someone else who wants to adapt the Python code. You will see these events in the History window.

Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 07:27:30 PM
Thanks very much... Maybe I soon start learn this language... Very interesting! Thanks!
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 07:48:50 PM
Hmm... TS is running then i do full restart of VC, and yes py file load and then after 5 sec checked and VC write Hook enable , but Hook don`t work, in plugins chekboks of Hook is active, not understand why Hook don`t work((( And then after i shut down TS this in logs:

7/6/2015 1:56:48 AM   652   [vcevent] Process.ts3client_win64.False

7/6/2015 1:56:48 AM   665   action repeat set to: 1
7/6/2015 1:56:48 AM   665   Action:  Hook.Disable -
7/6/2015 1:56:48 AM   665   [action] Hook.Disable:

7/6/2015 1:56:48 AM   696   Action ERROR: System.ComponentModel.Win32Exception (0x80004005): Invalid hook handle
   в MouseKeyboardActivityMonitor.WinApi.Hooker.ThrowLastUnmanagedErrorAsException()
   в MouseKeyboardActivityMonitor.WinApi.Hooker.Unsubscribe(Int32 handle)
   в MouseKeyboardActivityMonitor.BaseHookListener.Stop()
   в MouseKeyboardActivityMonitor.BaseHookListener.set_Enabled(Boolean value)
   в vcPlugin.ctlMain.checkBoxEnabled_CheckedChanged(Object sender, EventArgs e)
   в System.Windows.Forms.CheckBox.OnCheckedChanged(EventArgs e)
   в System.Windows.Forms.CheckBox.set_CheckState(CheckState value)
   в System.Windows.Forms.CheckBox.set_Checked(Boolean value)
   в vcPlugin.ctlMain.setEnabled(Boolean isEnabled)
   в vcPlugin.Plugin.doAction(String[] parsedActions, String[] parsedParams)
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 08:10:16 PM
There is problem in then TS already running  and i run VC py script work incorrect or don`t work, but if run VC is first and after run TS script work good... Very bad but i don`t understood py language yet((( Pls help is it possibly...
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 08:30:27 PM
Modify some commands in VC, now then VC started automatically Hook switch in disable mode, and after then loaded the script and checking after 5 sec then Hook is enable... And this work!)) But i want know how correct the py script what work good this out my change... I already know html and php , maybe i can change and py script... Thanks!
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 05, 2015, 09:27:56 PM
We will investigate the problem further.

For now, please try the following:

In your Hook plugin settings, make sure that Hook is disabled by default. (Save the settings).

Replace the command that loads the python script with this command:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<command id="207" name="Load Python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <params>
      <param>PY\processRunningCheck.py</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Hook.Enable</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Hook.Disable</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>

And then restart VoxCommando.

Does this solution work properly for you? (Or is this the solution that you have used already?)
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 05, 2015, 09:46:14 PM
@Slalomen: are you using a laptop with a track pad and an external mouse attached as well?  In other words, do you have two mice on your system?  I think the hook plugin may have some difficulty in initializing the hook for mouse clicks when you have 2 mice.  I need to do some tests.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 09:58:57 PM
I work with one mouse(Bloody T7)

And this my command:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.1-->
<command id="225" name="Load Python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Hook.Disable</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <params>
      <param>PY\processRunningCheck.py</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>

looks how in you, because Hook is enable by default, and its work normally...
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 05, 2015, 10:02:12 PM
But how without this switching do what py script work good its possibly? Thanks! Starting downloading py courses ))
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 06, 2015, 01:24:35 AM
Hmm... After some time Hook is not work not response of mouse clicks(( I don`t know what do(( No switches form on off of Hook but after some time not work((( It`s bad...
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 06, 2015, 08:20:56 AM
For us, this solution is working, but we cannot test it for very long periods.

Does the Hook plugin continue to work for you without errors if you leave it enabled always, for a long time?
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 06, 2015, 10:15:07 AM
Today i launch VC and hook was enable always and working good but after i start use VC commands for example loops of 200 iteration 3 or 4 times after without problems in logs Hook is not response of mouse clicking... And yesterday after i starting use commands in VC after some time Hook is not response... I use DXInput for my commands...
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 06, 2015, 10:37:16 AM
Thank you for the information.

James needs to investigate the problem with the Hook plugin. It will take some time.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 06, 2015, 12:48:05 PM
I make the video with Hook problem but English is bad... Are you need this video?
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 06, 2015, 01:47:01 PM
I don't think we need to see this video, but if you already made it then I will be happy to watch it in case it can help us to understand better.  ;D
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 06, 2015, 06:39:38 PM
https://youtu.be/F5ZBTdK9oKg

Lol i speaking English like god))
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 06, 2015, 09:45:41 PM
1000% better than my Russian.  :biglaugh
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 06, 2015, 11:01:18 PM
https://youtu.be/F5ZBTdK9oKg

Lol i speaking English like god))

Thanks.  I will see if there is anything I can fix.
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 07, 2015, 10:40:32 PM
OK.  I have tried to make some changes to the hook plugin.  I do not have the same problem when I use the hook plugin so it makes it difficult to know if my changes will help you or not.  Please try the new version of the plugin and let me know if it works better.

How to update to the new plugin.

1 - Close VoxCommando
2 - Go to your VoxCommando\plugins folder
3 - Delete the hook folder
4 - Start VoxCommando
5 - On the main VoxCommando menu
 - Click "Plugins"
 - Click "More"
 - Click "Download Hook Plugin"
6 - Restart VoxCommando, and then open the settings for the hook plugin and put them back to the way you had them.
7 - Save your settings and then test.

Good luck! :)
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 08, 2015, 11:54:14 AM
Thanks for your work, but still problem Hook is not response after 5-6 loops of 150-200 iterations, but now after Hook is not response the switching there are no problem its progress...
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 08, 2015, 12:11:51 PM
Are you using keyboard hooks?

Or just mouse hooks?
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 08, 2015, 12:24:11 PM
just mouse(Down and Up). Use DXInput for loops.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 03:31:46 PM
Then expected fixing of this problem? ::dis
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 03:57:32 PM
I am working on it.  I do not know if I will be able to find a solution.

I have discovered that this seems to happen on slower systems, or when a system is very busy.  Perhaps it only happens when VoxCommando is busy for a long time.  Somehow the mouse hook is lost.

I have seen other programmers discussing this online with the same problem but none of them have a solution that I can find that works.  It is a very low level problem cause either by Windows, or by the .dll that I am using.  I have tried many different things to try to solve the problem in the plugin but so far I don't think I have made it any better.

Can you please send me the commands that you are using to do keyboard emulation.  I have a suggestion on something you can try but I think it will be easier for me if I can edit your command xml and then give it back to you than if I try to explain it.

thanks.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 04:08:54 PM
Hmm... But i use many commands and after some time hook is not responsive not only loops there are many other commands((( I don`t know how i can help... maybe send my collection?
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 04:29:39 PM
What kind of computer (CPU) are you using?

Does this happen any time, or only when you are playing games?

Well... if it can happen with any command, then I don't think there is any point in sending me your command collections.

If you are able to see a pattern of what causes it to happen then please let us know.

Maybe as a solution you can use a keyboard hook instead of a mouse hook?   I don't think that keyboard hooks have the same problem for some reason, even though they are using the same dll.
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 05:07:24 PM
Try this simple program that runs outside of VoxCommando and sends event messages to VoxCommando through UDP.

Maybe this will work better.

By default it will only generate events for XButton1, but you can change it.

This is very simple and only for testing.

Please turn OFF your hook plugin in VoxCommando when testing this program.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 05:25:03 PM
CPU - Intel Core i7
Its happen any time like in video then I use loops on a desktop in notepad or I play in game and use other commands...
What mean see a pattern?
I use DxInput(Keypress or Keycombo) and only keyboard press, i have rapoo wireless keyboard... Maybe install keyboard drivers?
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 05:50:52 PM
Thanks for your help with simple program but i don`t understood how it`s use for example i change key on key 1 and focused on VOX and then i press key 1 any change in VOX i not see((
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 11, 2015, 06:07:05 PM
You should not change anything in the simple program. Leave it as "XButton1".

Disable the Hook plugin in VC (in Options) and restart VC to be safe.

The program needs to be running on the same machine as VoxCommando.

When the simple program is running, every time you click the XButton1 on your mouse, you should see XButton1 mouse events in the VoxCommando history window.

Do you see those?

If you have commands that are triggered by the XButton mouse click, those should be triggered. Is that working?

If so, you can try to use the simple program to change VoxCommando from On to Standby using the mouse. Hopefully it will continue to work even when you are using processor intensive commands like your DXInput looping commands.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 06:14:54 PM
I off plugin in options run the program(XButton1) restart VOX and the i clicking on these key anything is change in VOX(run both in administrator mode)(( Thanks
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 06:27:39 PM
It should generate an EVENT in VoxCommando.  You should see it in the history panel.  You can assign the event to commands that switch VoxCommando to On or Standby mode.

The program assumes you have not changed the default listen port in VoxCommando Options / Advanced / UDP.  The default port is 33000.

The mouse button name is case sensitive.  I used the name that you had in your original events.
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 11, 2015, 06:36:39 PM
When you click the XButton1 on your mouse, do you see the mouse event in your VoxCommando "history" window?

Yes? No?

Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 06:41:26 PM
Yes see in Options 33000 port but events not generates, XButton1 is name from Hook plugin, maybe name of key is different?
No don`t see((
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 06:54:26 PM
Maybe problem in my mouse Bloody T7 and Bloody 5 program?
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 07:05:41 PM
I don't know. I give up for today.

You can try changing the button name to:
Code: [Select]
Left
And then clicking the left mouse button.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 11, 2015, 07:10:45 PM
 :) Well done! Thanks its work, still find interpretation for XButton1))
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 11, 2015, 07:17:53 PM
OK good. For now the main objective is to test if this program works reliably for a long time. Please test it using the left button. We can find the correct button name later.
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 12, 2015, 08:05:06 PM
Here is a new version with a small change.  Save the .exe file over the old one.  Make sure it is in the same folder as "MouseKeyboardActivityMonitor.dll"

In this version:
  When you erase the button name, it will work for all buttons.  In other words: leave the text box empty.  Blank.

This way you can test with any mouse button and find the correct name.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 12, 2015, 09:16:13 PM
Thanks! If you can modify this good simple program that then lunch text field be empty... Thanks! :) Testing this loops work great!!! Because now in text field : XButton1, but work all mouse clicking :) And if manually write XButton1 then XButton1 clickings sends to udp :)
Title: Re: Hook and monitoring programs... How?
Post by: jitterjames on July 13, 2015, 10:17:59 AM
With this version you can now save the button and it should use it again when you restart the program.

If it is possible, it is better to only use one button so that you are not creating a lot of events that VoxCommando will need to process for nothing.
Title: Re: Hook and monitoring programs... How?
Post by: Slalomen on July 17, 2015, 10:56:30 PM
Thanks you very much! But if field on startup be empty it is be better... If you can modify this little program... Thanks! :)
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 18, 2015, 08:55:34 AM
?

Are you using the exe file that James last posted?

Just delete the key that is in the field and click "save". The next time you open the program it will be empty. And it will continue to be empty as long as you don't change it.
Title: Re: Hook and monitoring programs... How?
Post by: nime5ter on July 18, 2015, 08:48:22 PM
The "off topic" follow-up question about if()cases and {LastSpoken} has been moved to its own thread.

See: http://voxcommando.com/forum/index.php?topic=2276.0