CvJoyInterface - A new, class based vJoy library

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

CvJoyInterface - A new, class based vJoy library

24 Dec 2014, 13:49

I have used and maintained Axlar's vJoy interface for many years now in my projects, and it has stood the test of time well, but I felt that it was a little difficult to use for less experienced coders, polluted the global namespace too much etc, and had a number of other niggles, so I thought I would re-write it.

CvJoyInterface is designed to make it easy for anyone to operate virtual sticks - for example, in it's simplest use-case, you do not even need to Acquire() the stick, CvJoyInterface will do it automatically for you:

Code: Select all

#SingleInstance, force
#include CvJoyInterface.ahk
;#include <CvJoyInterface>

; Create an object from vJoy Interface Class.
vJoyInterface := new CvJoyInterface()

; Was vJoy installed and the DLL Loaded?
if (!vJoyInterface.vJoyEnabled()){
	; Show log of what happened
	Msgbox % vJoyInterface.LoadLibraryLog
	ExitApp
}

myStick := vJoyInterface.Devices[1]

; End Startup Sequence
Return

; Hotkeys
F10::
	; On press of F10 try and press button 1
	myStick.SetBtn(1,1)
	Return

F10 up::
	; On release of F10, release button 1
	myStick.SetBtn(0,1)
	Return

; Hotkeys
F11::
	; Refer to the stick by name, move it to 0%
	myStick.SetAxisByName(0,"x")
	SoundBeep
	return

F12::
	; Refer to the stick by index (axis number), move it to 100% (32768)
	myStick.SetAxisByIndex(vJoyInterface.PercentTovJoy(100),1)
	SoundBeep
	return
Github Page (Download)
matt
Posts: 2
Joined: 09 May 2016, 13:50

Re: CvJoyInterface - A new, class based vJoy library

10 May 2016, 09:01

Hey there, I don't know if this is the place to discuss about it but I just found your library and can't thank you enough for your work. It allowed me to finally work out a solution to get throttle control on keyboard in GTA V, through AHK, vjoy and x360ce — sounds cumbersome, but it actually works very well thanks to CvJoyInterface. So, thanks alot for this! I am surprised that there is no answer to this thread by the way.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

10 May 2016, 12:55

Yep, this is the right place :)

I think that the main reason there are so few replies is that people wanting to use AHK to control vJoy tend to use one of my GUI applications that achieves the same result without them needing to learn how to code in AHK.

See the UCR thread.

By the way, there is a new version of vJoy coming that is able to create virtual XBox controllers. Dunno if that will simplify your tool chain any, but maybe not.
What are you using for input, a real XBox controller? The new XBox version of vJoy will probably only help when you are not using a physical XBox controller.
matt
Posts: 2
Joined: 09 May 2016, 13:50

Re: CvJoyInterface - A new, class based vJoy library

11 May 2016, 14:24

Well, I don't really know how to code in AHK either, but with a bit of searching and experiments I managed to get what I needed. I'll have a look at UCR, maybe it will be more interesting that what I currently have, thanks for the link!

I use both the keyboard and a 360 controller when playing, so yeah, the xinput version of vjoy won't be helpful to me, but I can see it gathering lots of interest.
kjyek
Posts: 7
Joined: 01 Jun 2016, 19:56

Re: CvJoyInterface - A new, class based vJoy library

01 Jun 2016, 22:17

How do I do something as simple as with vJoy? I can't figure it out.

Code: Select all

a::joy5
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

02 Jun 2016, 05:33

You cannot use syntax like that to control joysticks, that is why I wrote this library.

To make a operate vjoy button 5, download CvJoyInterface.ahk, and put this ahk script in the same folder as it.

Code: Select all

#SingleInstance, force
#include CvJoyInterface.ahk
;#include <CvJoyInterface>
 
; Create an object from vJoy Interface Class.
vJoyInterface := new CvJoyInterface()
 
; Was vJoy installed and the DLL Loaded?
if (!vJoyInterface.vJoyEnabled()){
	; Show log of what happened
	Msgbox % vJoyInterface.LoadLibraryLog
	ExitApp
}
 
myStick := vJoyInterface.Devices[1]
 
; End Startup Sequence
Return
 
; Hotkeys
a::
	; On press of a, press button 5
	myStick.SetBtn(1,5)
	Return
 
a up::
	; On release of a, release button 5
	myStick.SetBtn(0,5)
	Return
kjyek
Posts: 7
Joined: 01 Jun 2016, 19:56

Re: CvJoyInterface - A new, class based vJoy library

02 Jun 2016, 10:09

Thanks man. The issue was my script wasn't in the same directory as CvJoyinterface.ahk :facepalm:
I didn't think that necessary since I have it in /lib folder.
kjyek
Posts: 7
Joined: 01 Jun 2016, 19:56

Re: CvJoyInterface - A new, class based vJoy library

02 Jun 2016, 10:37

Couple questions if you don't mind.
Can this be used to temporarily block POV input or is BlockInput still necessary?
I know the syntax here is wrong, but what would your vJoy implementation be for something like this?:

Code: Select all

a::
GetKeyState, POV, JoyPOV
if POV = 27000
{
;Block POV input if possible
myStick.SetBtn(1,5)
Sleep, 10
myStick.SetBtn(0,5)
Sleep, 10
POV DOWN ; or whatever the syntax is for vJoy
Sleep, 10
POV DOWN Release ;  or whatever the syntax is for vJoy
;Unblock Pov input if possible
}
Return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

02 Jun 2016, 16:08

Thanks man. The issue was my script wasn't in the same directory as CvJoyinterface.ahk
If you have CvJoyInterface.ahk in the lib folder, then replace #include CvJoyInterface.ahk with #include <CvJoyInterface>
Can this be used to temporarily block POV input or is BlockInput still necessary?
Using AHK, you cannot *in any way* alter how applications see a physical joystick, like you can for keyboard and mouse.
BlockInput has absolutely no effect on joysticks.

If you want to remap stuff without having to learn to code, see my UCR app. That has a GUI that will allow you to remap stuff to a vJoy stick.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

12 Sep 2016, 15:08

Some news regarding AHK and vJoy support.

I just pushed a fix for this library - the ResetPovs() method of a device class was pointing at ResetButtons.

I have a beta build of the new vGen API which supports normal vJoy AND virtual XBox controllers through one API, and additionally all axis ranges are the same as AHK (0->100). Not sure on timescales yet, but seeing as I will be implementing this in UCR ASAP, and UCR uses CvJoyInterface, I would expect there to be an updated version of this lib just as soon as I can get the damned vGen API working properly on x86.

Also, I have just found some bugs in vJoy:

It appears that the first time you issue a command to set the position of a Button, POV, or Axes, all buttons, povs and axes get set to 0, then your command is executed.
Therefore, all buttons, axes and povs other than the first one you operate will be set to 0. (0 for POV Hats is "Up")
The Init values you can set using registry keys cannot work around this.
I would imagine we will have a fix very soon.

I am also seeing a crash with x86 AHK if I do not issue a vJoyEnabled() call before Acquire()
CvJoyInterface always does this anyway, so we did not notice it before. However, vJoyEnabled() was removed from the vGen API, and I have not been able to get that to work on x86, so I guess my problems with vGen are as a result of this.
keung
Posts: 3
Joined: 18 Jul 2017, 12:22

Re: CvJoyInterface - A new, class based vJoy library

18 Jul 2017, 12:40

Hey evilC!

I was planning to macro a few button presses in a loop while streaming from Xbox One to the Xbox App on Windows 10, but quickly found out it's not that simple. After a few hours of research I managed to emulate joystick button inputs using vJoy and your interface. However, it seems that the Xbox App does not recognize the vJoy device as an Xbox controller and the inputs are ignored.

Right now, I'm kind of stuck. What I need to do is position my crosshair in game (via the streaming capability) using an X360 controller, then use AHK to continuously send the button presses. I know how to script that, but I have no clue how to set it up properly. Do you have any idea?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

18 Jul 2017, 13:58

I just added support for buttons and POVs to the new version, so the basics are working.
You must have the SCPVBus installed, which is required for vJoy's vXBox functionality to work.
I have included everything you should need in the attached ZIP. Just run the install.bat in the SCPVBus folder as admin, then the example AHK scripts should be functional.
This is using a new technique (Most of the work is done in vGenBasicWrapper.dll, which is C#), so you would be doing me a favor by testing it out for me, as I don't have much feedback yet as to whether it works for everyone.
Attachments
vGenBasicWrapper.zip
(1.81 MiB) Downloaded 379 times
keung
Posts: 3
Joined: 18 Jul 2017, 12:22

Re: CvJoyInterface - A new, class based vJoy library

18 Jul 2017, 23:02

Alright, just experimented with it. I ran install.bat as admin, although for some reason it didn't seem to do anything, but running the command manually worked wonders (no idea why). I do see the bus in device manager now. I then ran your Example.ahk and tabbed into the Xbox App while streaming, but nothing happened. Also tried Simplest Example.ahk (modified it a little bit to trigger on F8 keypress and alsotried swapping between vGen.vJoy and vGen.vXbox), but still no response. I had a look in the Monitor vJoy application, and it wasn't picking up on anything, but I suppose it is a different interface(?)

I also noticed that when I start streaming without a controller plugged in, the App says it can't find a valid controller.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: CvJoyInterface - A new, class based vJoy library

19 Jul 2017, 05:25

Example.ahk should move the controller around.
I use this web page to test vXBox - when you load up the page, press a button on a controller to activate the page, else it does nothing.
You should see both vJoy and vXBox going thru the same motions (X axis moves up and down, buttons 1-4 cycle)
If absolutely zero happens, it sounds like it maybe is not loading the DLL properly.
I have a Discord channel here, feel free to drop in and we will see if we can get it working.
keung
Posts: 3
Joined: 18 Jul 2017, 12:22

Re: CvJoyInterface - A new, class based vJoy library

20 Jul 2017, 19:28

I'll hop onto discord sometime during the weekend :)
Larkas
Posts: 1
Joined: 28 Aug 2019, 21:40

Re: CvJoyInterface - A new, class based vJoy library

28 Aug 2019, 21:43

I'm sorry if this is not the right place to ask, but how is this different from this? I've been using the latter successfully, should I change/upgrade?
Elrond5
Posts: 1
Joined: 15 Dec 2016, 23:45

Re: CvJoyInterface - A new, class based vJoy library

23 Dec 2019, 18:47

I'm confused how to get this working, all I want to do is change WASD to send controller movement instead

W::Y Axis 32768

A::X Axis -32768

S::Y Axis -32768

D::X Axis 32768
IiIShadeIiI
Posts: 11
Joined: 22 Jul 2020, 19:09

Re: CvJoyInterface - A new, class based vJoy library

02 Dec 2020, 19:00

evilC wrote:
24 Dec 2014, 13:49
I thought I would re-write it.

CvJoyInterface is designed to make it easy for anyone to operate virtual sticks
Thank you, sir, you are my hero :salute:


Elrond5 wrote:
23 Dec 2019, 18:47
I'm confused how to get this working, all I want to do is change WASD to send controller movement instead

W::Y Axis 32768

A::X Axis -32768

S::Y Axis -32768

D::X Axis 32768
I'm not an expert in this matter but I'd use something along the lines of

#include CvJoyInterface.ahk
vJoyInterface := new CvJoyInterface()

w:: vJoyInterface.Devices[1].SetAxisByIndex(32768, 1)
s:: vJoyInterface.Devices[1].SetAxisByIndex(0, 1)
d:: vJoyInterface.Devices[1].SetAxisByIndex(32768, 2)
a:: vJoyInterface.Devices[1].SetAxisByIndex(0, 2)

etc.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 103 guests