Author Topic: Hold key to listen  (Read 3843 times)

0 Members and 4 Guests are viewing this topic.

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Hold key to listen
« on: April 01, 2019, 09:43:28 PM »
I had thought that I had read somewhere that VoxCommando could be set to listen only when a specific key was held down (e.g., Left Control key, or, when CapsLock was on, etc.).  However, I'm not finding that information, so I am thinking maybe I was wrong?

At any rate, is there a way to make VoxCommando execute commands only if a specific key is pressed and if that key is not pressed to ignore all commands?  That would be really helpful to me because I will have people stop by my office and start talking to me and if I forget to turn off VoxCommando, my computer can start behaving wildly.

Any pointers would be greatly appreciated.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #1 on: April 02, 2019, 09:27:12 AM »
Yes.  This can be done using events generated by the "Hook" plugin.  You could use the mouse or keyboard to accomplish this.

https://voxcommando.com/mediawiki/index.php?title=Plugin_Hook

Another method is to use Standby mode in VC.  Then you can use voice commands to tell VC when to listen, or to use a PREFIX to issue commands while remaining in standby mode.  If you use a voice command to put VC into Listen mode (On), you can also have it set a timer to automatically revert to Standby mode after a period of inactivity.

Another option is to use the "Win" plugin to register a "hotkey" key-combination with the Windows OS.  This is more efficient than using the Hook plugin because Hook must always listen to every single keyboard event on your system in order to work.  The downside to using the Win plugin is that you can only register a key-combination press to toggle VC on and off.  If you want to have VC listen while a key is held down and stop when the key is lifted then Hook is your only option, or some other program like EventGhost that is performing a similar option.

I can create a quick demo video showing how to use Hook to do this, but let me know if you are interested in the other options as well.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #2 on: April 02, 2019, 11:31:13 AM »
Here is how you can do it using the Hook plugin.

https://youtu.be/Kf9b-4j53cc


TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #3 on: April 02, 2019, 02:36:56 PM »
This is brilliant!  Exactly what I need. 

The video explaining it was excellent; and the use of the tilde as the toggle key is one I hadn't thought of, but it is very convenient and almost never used for anything else. 

Perfect!  Thank you, @jitterjames!   ;D ;D

This is the best $ I have spent on an application for a *long* time and I was happy to register it.

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #4 on: April 02, 2019, 04:50:52 PM »
So...  I've got the Hook plugin all set up and working, but I'm running into a problem.  The activating key press and key release actions work *only if VoxCommando has the focus.* 

Many of the voice commands I use to add standard comments in MS Word documents for papers that I am editing (I am a professor and I "get" to edit a lot of student papers and I use voice commands to add comments so that I don't have to keep retyping the same comment over and over).

Is there a way to get VoxCommando to recognize the key press and key release events even when those occur when another application has the focus?

I am wondering if I am going to need to have EventGhost recognize the key press and then send a command to VoxCommander?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #5 on: April 02, 2019, 05:19:07 PM »
By design, and so far in every situation that I have tested, VoxCommando generates the hook events regardless of what program has the focus.  In other words, it always works even if another program has focus.  As far as I know this should be the case for everyone.

It's possible that something has changed in Windows 10 so I will need to do more testing.

It's possible that disabling UAC or running VoxCommando as administrator might make a difference for you.

Or maybe it depends on which key combination you are using or what software you are running.

I know that it works for me fine in Windows 7 with MS Word 2007.  I'm running Windows 7 with UAC off, using an admin account but not running VC "as admin".

I can test on Windows 10 but not necessarily all other possibilities.

If EventGhost keyboard detection works better then yes you can use that to send events to VoxCommando quite easily via a number of methods (TCP, HTTP, UDP etc.)  UDP is probably the easiest but is not always 100% reliable on all networks.

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #6 on: April 02, 2019, 05:46:28 PM »
@jitterjames, I will try tomorrow when I am back at my machine to see if running as an Administrator helps.

I am running Windows 10 and MS Word 2016.

The key combinations I tried were the tilde and also the left control key.

I don't know that EventGhost keyboard detection will work better--but I think that will be my fallback.

I don't know if it is related, but I have had poor luck getting VoxCommando to send keys to apps and have EventGhost send the keys instead.  I've tried VoxCommando's SendKeys, InputKeys, and DxInput and while they all work successfully to send keys to Notepad, I have not been successful using any of the 3 to send keys to Notepad++, to MS Word 2016, or to most dialog boxes.  I have VoxCommando send an event to EventGhost and then EventGhost sends the keys to the app.

I'll post back tomorrow when I have a chance to run VoxCommando as an Admin.  Thanks for the support.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Hold key to listen
« Reply #7 on: April 03, 2019, 08:58:41 AM »
Good morning,

A somewhat unhelpful update from the lab:

I am logged onto a Windows 10 computer as an Admin. UAC is on.

I've now tested James's Hook command for temporarily switching VC into listening mode, first using a tilde and then using my left-Alt key. So far it seems to be working.

One thing we found helpful for testing was to turn on the "Show Overlay" setting in VC's Options (https://voxcommando.com/mediawiki/index.php?title=Main_Menu#Options). This makes it easier to see when VC is listening when other programs are focused and maximized.

For me, this command worked no matter which program was in focus. I tried Notepad++, MS Word 2010, and Chrome.

The tilde obviously was a little inconvenient because it was typing the character over and over in my document as long as the key was held down. :) But the VC command functioned; VC stayed in listening mode until I released that key.
« Last Edit: April 03, 2019, 09:06:21 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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #8 on: April 03, 2019, 09:15:39 AM »
Is it possible you are using EventGhost to capture keyboard input at the same time and it is somehow interfering with VoxCommando?

Also, is it possible that trying to perform keyboard emulation while you are still holding down a button on your keyboard is problematic?

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #9 on: April 03, 2019, 10:21:21 AM »
Thanks to both @jitterjames and @nime5ter.

I am baffled:  the problem seems quite inconsistent. 

I always am logged in with an Admin account and UAC is off.  I have had the VoxCommando overlay "on" since I installed the program because it is helpful to know when VC is listening.

This morning, I ran VoxCommando "as administrator" and was successful in using Word 2016 while using the Left Control key to toggle Vox.On and Vox.Standby.  Consistently I could see the VC overlay turn green when pressing LCtrl.  That's great! 

Weird thing was, I then closed and restarted VoxCommando normally (*not* as an administrator) and it still worked with the Word 2016 document.  I have no idea why this didn't work yesterday.

However, continuing with VoxCommando in non-administrator mode, when I tried using LCtrl in Notepad++, pressing LCtrl did *not* change the VC overlay and voice commands were not recognized (of course, since VC wasn't listening).  If I immediately switched to Word 2016 and pressed LCtrl, the VC overlay turned green and voice commands were registered.  If I immediately switched back to Notepad++, LCtrl would no longer work.  Very strange.

So, I restarted VoxCommando as an admin.  Now the LCtrl was registered in Notepad++ and Word!  So, I exited VoxCommando and restarted it in non-administrator mode:  Now LCtrl was not registered in Notepad++ nor was it registered in Word 2016! 

I don't understand the inconsistency, but, I guess I know to run VoxCommando as administrator to get the best results.

Yes, the fact that the LCtrl key is held down during keyboard emulation is something I have to be aware of and have tried to work around.  I wish that were the problem, but I have ensured that is not the cause of the difficulties. 

I am using EventGhost at the same time, but not to capture the LCtrl key, so I don't think that is it.  Plus, LCtrl works as expected when running VoxCommando as an administrator, so seems like that wouldn't solve the problem if EventGhost were somehow interfering with the LCtrl behavior.

I'll keep looking for a pattern and see if I can figure out what changes the effectiveness of the LCtrl.

I'd also like to find a way to get EventGhost and/or VoxCommando to cause the system to release the LCtrl key press before executing the subsequent commands.  EventGhost has the EmulateKeys command that is supposed to do a "key up" only, but that does not effectively cause the LCtrl not to be recognized in Word 2016 (I haven't tried with other apps, but I anticipate it would be the same).  That would help with having to be sure keyboard events are not muddled by the LCtrl key.

Anyway, thanks for all the help and testing and suggestions.  For now, it seems like the best solution is running VoxCommando as administrator.  Will update here if I discover anything potentially useful.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #10 on: April 04, 2019, 10:55:23 AM »
I don't understand the inconsistency either.  In theory Windows should not allow any program with a lower level of privilege to control a program with a higher level of privilege, so if Word or Notepad were somehow running at a higher level VC should not ever be able to control those programs.  The fact that it is unpredictable on your system just shows that Windows still have a lot of issues.

I haven't experienced any of these issues on the various systems I've tested, but I expect these types of peculiarities with Windows when lots of different users are running a lot of different hardware and software combinations on a an OS that ultimately is still very flawed on many levels.

Yes EventGhost could very well be interfering even if it is not set to capture that particular key.  Keyboard hooks need to be registered so that a program can listen to ALL keyboard events.  What it does with that information (generate an event of not) is not important.  If you want to find out for sure, the best plan is to close EventGhost and make sure its process is completely shut down and then restart VoxCommando before testing.

But in any case it will hopefully not be too big of an issue for you to simply always run VC as admin.

I don't think you can force the release of a key when it is still physically pressed down.  Even if you could it sounds like a recipe for trouble.

I think you would be better off using a keypress to toggle VC on and off rather than holding the button down while speaking.  Then, if you are worried about forgetting to turn VC off you can have VC either turn off immediately after the first recognized voice command, or switch off after a certain amount of time.  I'm also wondering if you've tried using prefix mode at all?

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #11 on: April 07, 2019, 12:57:42 PM »
The inconsistency seems to be related to locking and unlocking the Windows 10 desktop. 

When I lock the computer by pressing WIN+L on the keyboard and then later come back and enter the password to unlock the computer, the keys detected by VoxCommando (and I would note this is an issue in EventGhost too) are...different than expected. 

For example, in Vox's History window, instead of showing Hook.LControlKey when I press down the left control key, it will show Hook.LWin+Sleep+LControlKey.  I can assure you, I am not holding down the LWin key and I don't even have a Sleep key on my keyboard.  However, I did hold down the LWin key to lock the computer--so it seems like perhaps key activity is not detected once the machine is locked (which is probably by design) and the LWin key up from locking the desktop has not been detected?  Not sure about why a Sleep "key" is detected.  Another time after unlocking, the Vox History shows Hook.LWin+Sleep+Return+LControlKey every time I pressed the left control key.  In both cases, however, it consistently shows Hook.LControlKey.Up without the extra keys being "released"--presumably because I am only actually releasing the left control key and I'm not releasing any of the other keys.

My solution to this has been (in addition to running VoxCommando "as administrator") to have EventGhost detect when I unlock the computer; then I have EventGhost run a batch file that restarts EventGhost (because it has similar, but not the same problems after unlocking) and another batch file that restarts VoxCommando if it was running when the machine is unlocked.

After restarting Vox, the History shows only Hook.LControlKey when I press the left control key, as expected.

Don't know if this helps sort out what is happening in the background, but it is perhaps a helpful workaround for anyone else experiencing similar issues.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Hold key to listen
« Reply #12 on: April 07, 2019, 01:27:52 PM »
This is something I can probably help with.

Here is a version that detects when the system is unlocked, and clears out the key buffer.  If a key is physically held down while the system is being unlocked this might cause a problem but try it out and let me know.

Remember to UNBLOCK the dll file after replacing it with the attached version.

TheIntersect

  • Jr. Member
  • **
  • Posts: 9
  • Karma: 3
    • View Profile
Re: Hold key to listen
« Reply #13 on: April 08, 2019, 12:57:35 PM »
Thank you, @jitterjames, for the updated Hook.dll.  I have been using it today.  It does seem to have resolved the issues.   Thanks for working out a fix!

The only odd thing I noticed today was that I did receive a History entry of Hook.Sleep+LControlKey one time when I was just pressing LControlKey. 

I simply added that event to the event that Hook.LControlKey is in--now, both events trigger the same response.  This would be a problem for someone who actually needed to respond only to LControlKey, but it is working just fine for me. 

I don't know that the .Sleep prefix is related to locking and unlocking the desktop, or if it is related to something else.  If I can discover a pattern, I'll post something.  I am guessing it has something to do with my laptop going to sleep while it is locked, but I have not been able to establish that yet.