Author Topic: Joystick Axis Support  (Read 703 times)

scottb613

  • Newbie
  • *
  • Posts: 47
Joystick Axis Support
« on: March 28, 2025, 07:17:09 AM »
Hi Folks,

First off CONGTATS - on getting v2 out the door. Just purchased - looking forward to testing when I get my key.
 :)  :)  :)

After all these years - you are certainly entitled to another ten spot.

Feature Request - - - Joystick Axis Support - - - so I can remove Joy2Key from my control program ensemble.

Regards,
Scott

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 317
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Joystick Axis Support
« Reply #1 on: March 28, 2025, 12:50:03 PM »
Have you looked into device state conditions?  There are also joystick axis tokens, too, including position, rotation, acceleration, angular acceleration, angular velocity, etc. - check the VA Help Manual starting around page 191.   Might be able to get rid of Joy2Key right away if you build a conditional command which can watch your joystick axes for non-zero values....

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #2 on: March 28, 2025, 07:41:42 PM »
Hi...

Thanks for the great response - let me see if I can get that to work. All I want to do is to press a key when the joysticks of a Logitech 310 "Xbox" controller is moved to a specific position. Basically - just press arrow keys for the respective position for movement in an application that doesn't support joysticks.

Regards,
Scott

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #3 on: March 28, 2025, 07:58:47 PM »
Hi....

I've used VA for many years and created many profiles - I can program/script in Ksh/Csh/Bash, Python, and C - I understand what you're showing me - but what TRIGGERS this even? I need it to be triggered by the movement of the joystick. I can trigger an event by a Voice Command - Keyboard Shortcut - or - Joystick Button Press - - - I don't see how to trigger the event by Joystick Movement?

Code: [Select]
(X+ = [Right Arrow]) (X- = [Left Arrow]) (Y+ = [Up Arrow]) (Y- = [Down Arrow])
Thanks for your help and patience.
;)

Regards,
Scott
 

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #4 on: March 28, 2025, 08:19:02 PM »
Hi...

Hmm - something like this?

Code: [Select]
Start Loop (Infinite)

If {STATE_JOYSTICK1X} > 70
Press and Release "Right Arrow" key

If {STATE_JOYSTICK1X} < 30
Press and Release "Left Arrow" key

If {STATE_JOYSTICK1Y} < 30
Press and Release "Up Arrow" key

If {STATE_JOYSTICK1Y} > 70
Press and Release "Down Arrow" key

Pause 0.05 seconds

End Loop



JoyToKey continuously monitors the joystick’s state in the background at a low level, using the Windows DirectInput or XInput APIs. It checks the axis positions (e.g., X+, X-, Y+, Y-) and button states in real-time.

Does VA2 use the same? Just concerned about performance.


RRegards,
Scott

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4855
  • RTFM
Re: Joystick Axis Support
« Reply #5 on: March 29, 2025, 07:48:42 AM »
All applications monitoring joysticks have to poll for information, I.E. request information in a loop. The Windows joystick systems are not event-driven like the keyboard and mouse APIs are.


What you have there could work, though there are some very minor optimizations you could make:

Use the "Device State" tab if you're checking joystick X or Y positions, specifically (as these are the only axes available through that option)

Make mutually-exclusive conditions "Else If"


That said, in real-world terms these are not going to matter, especially with an artificial delay of 50ms.

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #6 on: March 29, 2025, 07:56:10 AM »
Hi...

Code: [Select]
Start Indefinite Loop
    Begin Device State Check :  Joystick 1 X Is Greater Than 95
        Press down Right key
    Else
        Release Right key
    End Condition
    Begin Device State Check :  Joystick 1 X Is Less Than 05
        Press down Left key
    Else
        Release Left key
    End Condition
    Pause 0.1 seconds
End Loop

It seems close - but I am missing something - when I start the loop - it has a constant [Right Arrow] key press with the joystick in the neutral - the only way to release it - is when I move the joystick to the left which presses a [Left Arrow]. As soon as I release to neutral - it's pressing [Right Arrow] again.

I need to hold down the arrow key until the joystick is released.

I see what you're saying about Else If.

Thanks for all the help, info, - and patience.
:)

Regards,
Scott


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4855
  • RTFM
Re: Joystick Axis Support
« Reply #7 on: March 29, 2025, 08:00:52 AM »
That's not what I was referring to regarding "Else If". This changes the command from tapping the directional keys to holding them.

As to the constant holding: have you actually checked the values returned by the joystick axes?
They are not percentages, which you appear to be assuming.

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #8 on: March 29, 2025, 08:55:18 AM »
Hi Pfeil,

Yep - I didn’t get to the “else if” as I thought that was efficiency - just trying to get it to work.

I looked up joystick values in Win10:

Code: [Select]
Value Range: 0 to 65535 (16-bit unsigned integer).
Neutral (center): ~32767 (middle of the range).

Full Left: 0.

Full Right: 65535.


I’ll play with this again later tonight.

Regards,
Scott

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4855
  • RTFM
Re: Joystick Axis Support
« Reply #9 on: March 29, 2025, 09:00:52 AM »
32767 is greater than 95, no?

Also, those are values for joystick devices. Gamepads tend to use -32768 to 32767, with 0 as the center position.


Have you checked the actual values your device is outputting, using a "Write a Value to the Event Log" action and the relevant joystick state tokens?

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #10 on: March 29, 2025, 12:02:07 PM »
Hi Pfeil,

Hah - write to event log - new to me - wahoo.

I see said the blind man - neutral is 128 || x- = -32768 || x+ = 32768.

I should see if a calibration makes neutral 0.

Thanks.

Regards,
Scott   

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 317
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Joystick Axis Support
« Reply #11 on: March 30, 2025, 01:15:57 PM »
I should see if a calibration makes neutral 0.

...even if you cannot, it is no matter.  You just need to know that greater than so much or less than so much equals an axis actuation.  Wouldn't matter if neutral was 1000, you have a very large range to work within, so if value was greater than 5000 or less than -5000, that is sufficient to detect axis movement and direction.

scottb613

  • Newbie
  • *
  • Posts: 47
Re: Joystick Axis Support
« Reply #12 on: April 01, 2025, 06:19:49 AM »
Hi...

Thanks to both of you - you were a big help and very patient. It's kind of working - and greatly appreciated. It's just VASTLY easier to setup in the other program.

I'll still stand by my original request - using a joystick axis should be as easy as assigning a button in VA - hopefully - someday - if time permits.
 ;)

Have a good day...

Regards,
Scott