Author Topic: Joystick Axis to Varible Keyboard Repeat  (Read 1520 times)

JDsplice

  • Newbie
  • *
  • Posts: 20
Joystick Axis to Varible Keyboard Repeat
« on: May 26, 2020, 10:34:20 PM »
Does anyone know if the following exists:

GOAL: Translate a joystick axis input into repeating key presses that repeat faster as more axis input is given.  Games like No Mans Sky and GTA5 dont have support for HOTAS and programs like JoyToKey only repeat the key press a set number of times per second.

Example: Typically yaw is ON/OFF in these kind of games.  You could smooth it out by using the keybinds for yaw and tap repeatively at a speed reflecting the desired yaw strength.  So slow yaw would have a slow repeat and fast yaw would repeat faster.  It would be nice to convert the twist on a Joystick to emulate this function.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #1 on: May 26, 2020, 10:44:39 PM »
You can use the "{STATE_JOYSTICK" family of tokens to get axis data, combined with a loop, a few conditions, a variable pause action, and a way to invert the value E.G. the math functions in the "Set a Decimal Value" action, to construct what you're describing; Though whether it'll have the desired effect ingame is another matter.

You may need the experimental "Resource balance offset" for the faster presses (which is labeled advanced/experimental for good reason, keep that in mind), as otherwise the loop probably won't come around fast enough at high deflection.

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #2 on: May 26, 2020, 11:25:07 PM »
Thanks so much for figuring this out.  I didn't even know that was possible with VA.  I get the jist of what you are saying, but my knowledge in setting up this code is severily lacking.  Could you give me some basics to get me started and I might be able to figure out the rest?  The design would be something like this...

***Right Twist
Twist +(00 to 25)% = [key press] 500ms repeat
Twist +(26 to 50)% = [key press] 333ms repeat
Twist +(51 to 75)% = [key press] 250ms repeat
Twist +(76 to 100)% = [key press] Hold (release outside of range)
***Left Twist
Twist -(0 to 25)% = [key press] 500ms repeat
Twist -(26 to 50)% = [key press] 333ms repeat
Twist -(51 to 75)% = [key press] 250ms repeat
Twist -(76 to 100)% = [key press] Hold (release outside of range)

Any help is much appreciated!  :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #3 on: May 27, 2020, 01:10:16 AM »
This is not a command that can be accomplished with "basics".

You need to understand a number of advanced concepts, including how to dynamically change the timeout when the joystick position changes, and (now that I think on it further) doing that without blocking (I.E. not using a pause but instead using DateTime variables), both while waiting and while a key is down.

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #4 on: May 27, 2020, 09:15:54 AM »
Could you please translate this into VA code ...?

{TOP}
Pause 250ms
if STATE_JOYSTICK = 0 then goto SKIP
if STATE_JOYSTICK < 0 then goto NEG
if STATE_JOYSTICK > 0 then goto POS

{NEG}
Start Loop   
if STATE_JOYSTICK => 0 then goto SKIP
Press key [A]
Pause 250ms
Goto NEG

{POS}
Start Loop   
if STATE_JOYSTICK =< 0 then goto SKIP
Press key [D]
Pause 250ms
Goto POS

{SKIP}
Release key [A]
Release Key [D]
Goto TOP
« Last Edit: May 27, 2020, 04:07:39 PM by JDsplice »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #5 on: May 27, 2020, 04:45:02 PM »
What is that structure intended to do? As written, it'll just hold down a key while the joystick is not centered.


This would press a key for 10ms, with 250ms delay in between (it will not be pressed every 250ms exactly, as pressing the key also pauses the command internally):
Code: [Select]
Pause 0.25 seconds
Set integer [~joyPos] value to the converted value of {STATE_JOYSTICK1ROTATIONX}
Begin Integer Compare : [~joyPos] Is Less Than -767
    Press A key and hold for 0.01 seconds and release
Else If Integer Compare : [~joyPos] Is Greater Than 767
    Press D key and hold for 0.01 seconds and release
End Condition

There's a slight deadzone in the middle, in case your joystick doesn't quite center, which many don't.

JDsplice

  • Newbie
  • *
  • Posts: 20
Re: Joystick Axis to Varible Keyboard Repeat
« Reply #6 on: May 27, 2020, 11:24:16 PM »
Thanks so much!!!  ;D  I was able to use what you posted to make what I wanted and it worked really well...

Code: [Select]
Set integer [~joyPos] value to the converted value of {STATE_JOYSTICK1ROTATIONZ}
Begin Integer Compare : [~joyPos] Is Less Than 1000
    Press A key and hold for 0.333 seconds and release
    Write  '76-100%' to log
Else If Integer Compare : [~joyPos] Is Less Than 10000
    Press A key and hold for 0.02 seconds and release
    Write  '51-75%' to log
Else If Integer Compare : [~joyPos] Is Less Than 25000
    Press A key and hold for 0.007 seconds and release
    Write  '26-50%' to log
    Pause 0.08 seconds
Else If Integer Compare : [~joyPos] Is Less Than 32700
    Press A key and hold for 0.001 seconds and release
    Write  '0-25%' to log
    Pause 0.15 seconds
Else If Integer Compare : [~joyPos] Is Greater Than 64500
    Press D key and hold for 0.333 seconds and release
    Write  '76-100%' to log
Else If Integer Compare : [~joyPos] Is Greater Than 55000
    Press D key and hold for 0.02 seconds and release
    Write  '51-75%' to log
Else If Integer Compare : [~joyPos] Is Greater Than 40000
    Press D key and hold for 0.007 seconds and release
    Write  '26-50%' to log
    Pause 0.08 seconds
Else If Integer Compare : [~joyPos] Is Greater Than 32900
    Press D key and hold for 0.001 seconds and release
    Write  '0-25%' to log
    Pause 0.15 seconds
End Condition

The logs were so I could keep track of how much input I was using to help me tweak the values.  I could not figure out how to keep a key pressed while at 100% so I just had the key held down for a long time which almost had the same effect.