Jump to content

Virtual Joysticks Proof Of Concept - Keyboard Throttle With Half/full/full Reverse Keys


2 replies to this topic

#1 evilC

    Member

  • PipPipPipPipPipPipPipPip
  • Legendary Founder
  • Legendary Founder
  • 1,298 posts
  • LocationLondon, UK

Posted 14 January 2013 - 04:06 PM

OK, I cannot take the full credit for this one - I learned of the existence of vJoy from a post by HackNFly.
Unfortunately it seems that PPJoy does not work with MWO, so the existence of an alternative to PPJoy intrigued me. As it stands, vJoy normally requires input from a "feeder application" written in C# but v1.x of vJoy is compatible with some stuff written to be compatible with PPJoy.

How it works:
A virtual joystick app (in this case vJoy) creates a fake joystick that appears in windows' "Game Controllers" list.
You then use a feeder application to send instructions to the vJoy virtual stick - in this case I will use GlovePIE, but I would like to use AutoHotkey, so if anyone can help me getting the mythical PPJoy/vJoy wrapper for AHK working, please do drop me a line...
So once your feeder app (GlovePIE) controls your virtual stick (vJoy), you can map it to in game functions.

"Why would you want to do this? I dont even use a joystick!", you may ask. Plenty of reasons:
Wish there was a keyboard shortcut for half speed and full speed reverse? Speed in 10% increments? etc etc. Well with an analogue axis, you can set keys to control a virtual throttle - so the world is your oyster!

Want turn left/right to be switched in reverse? Use a virtual axis and switch the left/right keys when the throttle is negative!

Use a joystick already but no matter what you do the inputs are reversed or otherwise messed up in game? If you can get your stick to control a virtual stick and it is ok, you can probably fix it through some simple code (multiplying an axis value by -1 inverts it etc)

Use a throttle already, but it has "detents" (notches) that you want to use for stop, but they aren't at the middle of the scale? No problem, alter the code so when your real stick is in the detente, the virtual stick is centered.

Also, it is better than altering game files - if you have a problem with a virtual stick script when you fire up the game, you can tab out, tweak it and try it in the same drop - not possible when altering game files...

So, I present to you, as a proof of concept and with code reasonably easy to understand and use - a virtual throttle, controlled by keyboard and with half speed and full reverse shortcuts.

At the moment, this is a bit of a hack - you need to enable "Test Mode" in Win7 x64 (Because vJoy 1.x has unsigned drivers), so if you do not know what Test Mode is then you should maybe be wary or at least educate yourself as to what it is and the risks it implies.
Ideally at some point I would like to get a similar solution sorted with vJoy 2.x, but I do not know of a simple scripting language (Such as GlovePIE or AutoHotkey) that can control vJoy 2.x, so it pushes it out of the reach of the community at large here I feel - this solution gives someone who is desperate enough to have the control system they want a fighting chance of acheiving what they want and so hopefully help plug the gap until PGI sorts it the hell out with the control system.

Anyway, enough waffle aside, on to the meat.

Tested on: Win7 x64, but should work with 32-bit.



The software I used:
GlovePIE 0.45 Free from http://glovepie.org/lpghjkwer.php
vJoy CC290512 from http://sourceforge.n...rable/CC290512/
IMPORTANT! Do not download vJoy 2.x - only this 1.x OLDER VERSION.

Process:

1) Make the following change to your user.cfg in the root of your game folder:
cl_joystick_throttle_range = 0
This sets throttle axes such that the middle is stop, down is reverse, up is forward.

2) Install vJoy. If using win7 x64, when you install, it will say you need test mode, and force a reboot - it will install after the reboot.
Open your game controllers menu and verify you see a stick called "vJoy Device". Double click it to test the controller. For me, it just sits in the top left corner, all the other axes at 0.

3) Unzip GlovePIE - there is no install, just double click PIEFree.exe to run it.

4) Paste the following code into the GlovePIE window and hit "Run".
 
 
var.sens = 0.025
if key.Shift+W then
   var.throttle = 1
else if key.Shift+S then
   var.throttle = 0.5
else if key.Shift+X then
   var.throttle = -1
else if key.W then
   var.throttle += var.sens
else if key.X then
   var.throttle = 0
else if key.S then
   var.throttle -= var.sens
end
 
if var.throttle > 1
   var.throttle = 1
else if var.throttle < -1
   var.throttle = -1
end
 
ppjoy.Analog6 = var.throttle

The code should be pretty easy to figure out if you know that for an axis, 1 is full, 0 is centre, -1 is full the other way.
the variable sens (var.sens) controls the speed at which it moves the throttle, adjust to suit your preference.

5) Go back to the game controller test window for the virtual stick, and marvel at how your keyboard now controls the virtual "slider" axis.

W+S - speed up down
X - full stop
Shift+W - full speed
Shift+S - half speed
Shift+X - full reverse

6) You need to go in game, and clear the keyboard commands that control the speed, as we now have an axis and if you used both, it would not stay in synch probably (This script may be OK, but if it gets more complicated, it is likely you will need to clear the underlying keys, so it is good practice to do it now.)

The quickest way to do it is make these edits (in the KEYBOARD - LEFT column)
throttle up -> a (Yes, say OK, you will map it back later)
throttle down -> a
full stop -> a
turn left -> a

Then double click in the "Throttle" row in the JOYSTICK (Right) column and hit W or S - the game should say something like j0_slider0
If it does not recognise it, check you can move the virtual stick in the game controllers test panel to verify the virtual stick is actually moving.

Have fun!

Edited by evilC, 14 January 2013 - 04:13 PM.


#2 Hammerhai

    Member

  • PipPipPipPipPipPipPip
  • Bad Company
  • Bad Company
  • 998 posts

Posted 14 January 2013 - 11:45 PM

Good work. Wanted to try out vjoy but was put off by the "feeder application" coding requirement for 2.x

#3 RobertHall

    Rookie

  • 4 posts
  • LocationKentucky, USA

Posted 19 November 2014 - 08:44 AM

this would have been awesome

http://gametech.biz/blog/?m=20140424

Edited by RobertHall, 20 January 2015 - 06:37 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users