Author Topic: VA and keystroke inputs  (Read 118 times)

jcdick1

  • Jr. Member
  • **
  • Posts: 59
VA and keystroke inputs
« on: November 10, 2024, 09:26:33 AM »
I have a set of Arduino Nano boards that take switch input and convert it to keyboard strokes.  I'm not a programmer in any capacity beyond the most basic of scripting, so I contracted out the coding. 

There's an "agent" that runs that sets what keystrokes are sent by each switch, and it also tells the Nano to turn on or off switch LEDs.  The issue I'm having is that if this agent is not the "active window," VA stops acknowledging the keystrokes.  I can minimize the agent to the taskbar, and my VA profile still works fine.  Until I click on a different window and take focus away from the agent.  Then VA stops responding.  I have to then restore the "agent" and bring it forward to get VA to accept the input again.

I can set some switches to send T E and S, and if the agent is minimized and Notepad given focus, I can type "TEST" into Notepad pressing those switches.

I didn't post this in the "Bugs" forum because it isn't necessarily a bug in VA.  But I was hoping maybe someone might have an idea of what I can point my contractor to for improving the input from these Nano boards?

I've attached a short video showing what I mean.  In it, you can see the agent window on the left of the screen with the connected Nanos as COM5, COM4, COM6.  It is initially the active window, as evidenced by its brighter title bar.  I've created a small VA profile that takes the switch input and opens/closes Notepad and turns on the LED if Notepad is running, and turns it off if Notepad is closed.  You can see VA logging the input initially as I press the switch. But once I click on Notepad and remove focus from the agent window, input to VA stops until I restore focus to the agent. 

Any suggestions is appreciated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: VA and keystroke inputs
« Reply #1 on: November 10, 2024, 10:13:23 AM »
You could have your contractor try different methods of sending virtual keyboard input.

VoiceAttack uses a standard Windows API keyboard hook to receive keypresses.
If the keypresses from an application aren't working as expected, that indicates they're not getting captured by the hook (which is a Windows component, not VoiceAttack-specific).

If you are or are not running VoiceAttack as administrator that's something you could try changing, but the focus of a window affecting the *receiving* of virtual keypresses sent by the application the window belongs to doesn't really mesh with that.



Personally I'd have skipped the keypresses altogether and used a VoiceAttack plugin to trigger commands directly. That'd be a more reliable method (obviously that means VoiceAttack would need to be running for your hardware buttons/switches to work).

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 291
  • Upstanding Lunatic
    • My AVCS Homepage
Re: VA and keystroke inputs
« Reply #2 on: November 10, 2024, 12:54:42 PM »
Because VoiceAttack allows us to hook into up to 4 joystick/controllers, I found it easiest to use a Joystick library to make my Arduino seem like an X-Box style game controller.  That way, I can push buttons on the controller and have VoiceAttack watch those as part of a command which is triggered by individual buttons on the controller.  In this way, focus is never an issue of course, and I can access the lovely suite of options for such button triggers including double-tap or long-press, etc.  This method also allows me to use the controller independently of VoiceAttack or combined with it.



This is the controller library I use:
ArduinoJoystickLibrary


(and, as an example, the DIY game controller I made - just two rotary encoders on a ProMicro clone for a jet sim cockpit control:  https://pastebin.com/drUnCfKN )

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: VA and keystroke inputs
« Reply #3 on: November 10, 2024, 01:01:45 PM »
Keep in mind that such a library will not work with an Arduino Nano.

You need a proper USB-capable board (not just a serial-over-USB chip like the FTDI chip used on the Nano).
E.G. an ATmega32u4-based board, like a Micro or Pro Micro.

jcdick1

  • Jr. Member
  • **
  • Posts: 59
Re: VA and keystroke inputs
« Reply #4 on: November 10, 2024, 02:13:18 PM »
You could have your contractor try different methods of sending virtual keyboard input.

VoiceAttack uses a standard Windows API keyboard hook to receive keypresses.
If the keypresses from an application aren't working as expected, that indicates they're not getting captured by the hook (which is a Windows component, not VoiceAttack-specific).

If you are or are not running VoiceAttack as administrator that's something you could try changing, but the focus of a window affecting the *receiving* of virtual keypresses sent by the application the window belongs to doesn't really mesh with that.



Personally I'd have skipped the keypresses altogether and used a VoiceAttack plugin to trigger commands directly. That'd be a more reliable method (obviously that means VoiceAttack would need to be running for your hardware buttons/switches to work).

It is running as administrator.

I'd originally asked for a VA plugin, and then I could write profiles for all the different potential uses, since VA has Windows process controls and such.  But not being a programmer, the contractor convinced me that an agent with an API would be the better way to go.  To turn on/off an LED, I just have to run a curl command with a POST to whichever device controls that switch/LED, which VA can do.  Or at profile startup, have VA run a GET and set all the LEDs (landing gear down, docked, etc) appropriately when I first start up something like E:D.  Or one of the servers in the basement can send an http POST and light an LED to let me know something's off.

I sent him a message asking him to check the communication between the agent or Nano code and the Windows API, so thanks for that.

I appreciate the feedback.