Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Using AHK to control vJoy


  • Please log in to reply
51 replies to this topic
evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

When I said I tried it in 32-bit mode, I meant on a 32-bit copy of Win7.

I got it to work fine on Win7 x64, as you did, so I figure I was doing it right.

 

AHK script couldn't load the DLL if I recall, I forget the exact error - I can try again on monday.

 

As long as it controls a vJoy 2.x virtual joystick, and I can code in AHK, I will happily move UJR from the current library to yours if you can get it working in 32-bit as well as 64-bit on Win7.



axlar
  • Members
  • 196 posts
  • Last active: Dec 04 2015 08:50 AM
  • Joined: 29 Nov 2012

Here is readme for x86 version.

1. Install VJoy 2.0.x

2. Extract VJoy SDK 2.0.x

3. Place AHK scripts(VJoy_lib.ahk and VJoy_Test.ahk) into script directory

4. Place x86 version "vJoyInterface.dll" from VJoy SDK into script directory.

WS008343.jpg

If not, make sure you don't have any dll named "vJoyInterface.dll" on your computer(e.g. /Windows/System32) except VJoy was installed.

You can check the copied vJoyInterface.dll is surely x86 version seeing "Product Version" properties.

WS008336.jpg

 

5. Run Configure VJoy tool and enable buttons you wish to use.

WS008338.jpg

 

6. Before run a script, make sure AutoHotkey_L 32-bit version is installed.

 

7. Run VJoy_Test.ahk to set the VJoy State.

WS008337.jpg

 

8. Run "joy.cpl" or press button "Open cpl" to check Game Controller Properties

WS008339.jpg



112244
  • Members
  • 12 posts
  • Last active: Jan 29 2013 07:22 AM
  • Joined: 11 Nov 2012

Awesome work Axlar I'll try it out later. icon_mrgreen.gif



axlar
  • Members
  • 196 posts
  • Last active: Dec 04 2015 08:50 AM
  • Joined: 29 Nov 2012

evilc, please try fixing LoadLibrary in script "VJoy_lib.ahk". Is this work ?

 

(plan1)

        dllpath = %A_ScriptDir%\vJoyInterface.dll
        hDLL := DLLCall("LoadLibrary", "AStr", dllpath)

 

(plan2)

        hDLL := DLLCall("LoadLibrary", "WStr", dllpath)


axlar
  • Members
  • 196 posts
  • Last active: Dec 04 2015 08:50 AM
  • Joined: 29 Nov 2012
Awesome work Axlar I'll try it out later. icon_mrgreen.gif

 

Regardless of the test results, please let me know whether you are using the 32-bit or 64-bit Windows7.

Also, please tell me whether you are using the 32-bit AHK or 64-bit AHK



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Thanks a load axlar, will try it on monday when I have access to a 32-bit machine.

Saying that, I am kind of tempted to VM a copy of 32-bit windows for testing purposes.

 

I think I would have to re-work some of the parts of UJR though - At the moment I need one subroutine per stick button, so having 32 subroutines in my code is pretty bad coding - I need to work out a way to solve this more elegantly.



112244
  • Members
  • 12 posts
  • Last active: Jan 29 2013 07:22 AM
  • Joined: 11 Nov 2012

Got it working!

 

- Windows 7 Professional 64 bit

- AutoHotKey v1.1.09.02 Unicode 64 bit

- vJoy 2.02 I011112

- vJoyInterface.dll from vJoy install directory

 

I tried the vJoyInterface.dll from the SDK without success, it wasn't until taking it from the install directory that it worked. Thanks a bunch axlar. happy.png



axlar
  • Members
  • 196 posts
  • Last active: Dec 04 2015 08:50 AM
  • Joined: 29 Nov 2012

I see, thanks for the test.wink.png 

 

 

 

I tried the vJoyInterface.dll from the SDK without success, it wasn't until taking it from the install directory that it worked. Thanks a bunch axlar. happy.png

 

 But I don't know why... The x64 dll in SDK and dll from the install directory are samesad.png

 

/cygdrive/c/share/vJoy202SDK-011112/SDK/lib/amd64
$ md5sum vJoyInterface.dll
13c14612d307706140713b7d3fec087b *vJoyInterface.dll

/cygdrive/c/Program Files/vJoy
$ !md5
md5sum vJoyInterface.dll
13c14612d307706140713b7d3fec087b *vJoyInterface.dll


112244
  • Members
  • 12 posts
  • Last active: Jan 29 2013 07:22 AM
  • Joined: 11 Nov 2012

That's what I thought too, it had me pretty confused.



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Thanks Axlar, tested on a 32-bit version of win7 and it all worked fine.

Will be switching over to your library in due course :)



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Right, trying to put together a new package for axlar's code.

Will detect 32-bit or 64-bit and load appropriate DLL.

 

BTW, in your test code, to test buttons...

You probably hit a limitation I did - AHK does not natively support coloured buttons or even changing text colour on button.

 

My solution was this:

1) Use a text box instead of a button.

2) Set the variable associated with each button to something like "Button1"

3) set the g-label to each button to the same subroutine eg ButtonClicked

4) Set ButtonClicked to pull the variable name and strip "Button" from the front, just leaving a number:

 

StringTrimLeft, var, A_GuiControl, 6
ButtonClicked(var)
 
This should save you needing 32 subroutines in your test app...


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Finally success...

Started to get Axlar's library working with UJR.

 

I modded VJoy_init() in VJoy_lib.ahk thus:


    if (!hDLL) {
if !DllCall("IsWow64Process", "uint", ThisProcess, "int*", IsWow64Process)
IsWow64Process := false
if (%A_PtrSize% < 8 || IsWow64Process == 0){
dllpath = VJoyLib\x86\vJoyInterface.dll
} else {
dllpath = VJoyLib\x64\vJoyInterface.dll
}
 
        hDLL := DLLCall("LoadLibrary", "Str", dllpath)
        if (!hDLL) {
            MsgBox, LoadLibrary %dllpath% fail
        }
    }
 

 

 

So if you make a Lib folder in the same folder as the script, and in there x86 and x64 folders with the relevant DLLs in each, it should automatically load the correct DLL.

 

Things are a bit more complicated though:

 

How come the values to set axis are between 0 and 32767, whereas AHK's GetKeyState presents 0 to 100?

Yeah, I know I can easily mult by 327.67 but it just seems excessive. I guess it is just because of the word size of the register that holds joystick values?



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Hmm, the code paste on this forum seems borked, but you get the idea...



axlar
  • Members
  • 196 posts
  • Last active: Dec 04 2015 08:50 AM
  • Joined: 29 Nov 2012

Thanks for the fix suggestion. I'm trying to port.

 

 

BTW, in your test code, to test buttons...

You probably hit a limitation I did - AHK does not natively support coloured buttons or even changing text colour on button.

 

My solution was this:

1) Use a text box instead of a button.

2) Set the variable associated with each button to something like "Button1"

3) set the g-label to each button to the same subroutine eg ButtonClicked

4) Set ButtonClicked to pull the variable name and strip "Button" from the front, just leaving a number:

 

StringTrimLeft, var, A_GuiControl, 6
ButtonClicked(var)
 
This should save you needing 32 subroutines in your test app...

-----

Elegant.

 

 
Finally success...

Started to get Axlar's library working with UJR.

--

I modded VJoy_init() in VJoy_lib.ahk thus:

 

So if you make a Lib folder in the same folder as the script, and in there x86 and x64 folders with the relevant DLLs in each, it should automatically load the correct DLL.

-----

I won't do any more than displaying an error to people who missed to deploy the DLL.
I think it is sufficient if people have installed different bit-version of VJoy and AHK_L, script will be guide to use the appropriate DLL from SDK.
 
Reason 1, Because I hate redistributing DLLs or specify how to deploy DLLs that was made by other developer.
 
Reason 2, I want to simplify the deploy plan in readme by omitting installing DLL in SDK.
(Referencing 112244's case, I think the VJoy SDK unnecessary because client has 64-bit dll that is deployed in VJoy install destination directory already.)
 
case1) client OS is 64-bit, installed VJoy 64-bit && using AHK_L 64-bit
    = use installed 64-bit dll(SDK unnecessary. client can omit to download SDK.)
case2) client OS is 32-bit, installed VJoy 32-bit && using AHK_L 32-bit
    = use installed 32-bit dll(SDK unnecessary. client can omit to download SDK.)
case3) client OS is 64-bit, installed VJoy 64-bit && using AHK_L 32-bit
    = use 32-bit dll from SDK, displaying an error message.
 
Things are a bit more complicated though:

 

How come the values to set axis are between 0 and 32767, whereas AHK's GetKeyState presents 0 to 100?

Yeah, I know I can easily mult by 327.67 but it just seems excessive. I guess it is just because of the word size of the register that holds joystick values?

-----

In the sample(VJoy_Test.ahk), script doesn't hold axis values.
O.K, I plan to hold values belong to each Device defined by class.


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
I won't do any more than displaying an error to people who missed to deploy the DLL.
I think it is sufficient if people have installed different bit-version of VJoy and AHK_L, script will be guide to use the appropriate DLL from SDK.
 
Reason 1, Because I hate redistributing DLLs or specify how to deploy DLLs that was made by other developer.
 
Reason 2, I want to simplify the deploy plan in readme by omitting installing DLL in SDK.
(Referencing 112244's case, I think the VJoy SDK unnecessary because client has 64-bit dll that is deployed in VJoy install destination directory already.)
 
case1) client OS is 64-bit, installed VJoy 64-bit && using AHK_L 64-bit
    = use installed 64-bit dll(SDK unnecessary. client can omit to download SDK.)
case2) client OS is 32-bit, installed VJoy 32-bit && using AHK_L 32-bit
    = use installed 32-bit dll(SDK unnecessary. client can omit to download SDK.)
case3) client OS is 64-bit, installed VJoy 64-bit && using AHK_L 32-bit
    = use 32-bit dll from SDK, displaying an error message.
My point was that these conditions should be detectable in code, so the instructions can be simplified, removing the need to say "If you have X OS and Y AHK, then use DLL Z." - you just package the DLLs with the library, in an appropriate folder structure.