problem with AHK-CvJoyInterface

Ask gaming related questions (AHK v1.1 and older)
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

problem with AHK-CvJoyInterface

30 Jan 2016, 07:12

im trying to bind moving controls (up,down, left, right) to wasd on my keyboard with https://github.com/evilC/AHK-CvJoyInterface, like this:

w::
myStick.SetContPov(0, 1)
Return

w up::
myStick.SetContPov(-1, 1)
Return

d::
myStick.SetContPov(0, 3)
Return

d up::
myStick.SetContPov(-1, 3)
Return

s::
myStick.SetContPov(0, 2)
Return

s up::
myStick.SetContPov(-1, 2)
Return

a::
myStick.SetContPov(0, 4)
Return

a up::
myStick.SetContPov(-1, 4)
Return

but no effect :(

how can i bind it correcttly ?
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 07:34

SetContPov takes the same range of values as reading from a physical hat using AHK's GetKeyState.
-1 is centre
0 is up

Then add 100 for each degree of rotation. So Right is 9000, Down is 18000, Left is 27000. Diagonals also work this way - Up and right is 4500

You may also want to check out my new project - UCR. UCR is a GUI application that lets you set up these kinds of remappings using plugins.
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 07:58

tnx a lot for answer !!

now my config are:

w::
myStick.SetContPov(0, 1)
Return

w up::
myStick.SetContPov(-1, 1)
Return

s::
myStick.SetContPov(18000, 1)
Return

s up::
myStick.SetContPov(-1, 1)
Return

a::
myStick.SetContPov(27000, 1)
Return

a up::
myStick.SetContPov(-1, 1)
Return

d::
myStick.SetContPov(9000, 1)
Return

d up::
myStick.SetContPov(-1, 1)
Return

but still no effect :(

by the way, i got an error why launching UCR:

https://i.gyazo.com/993ff69aafa97a840a2 ... 95a559.png
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 08:09

Adapted from Simple Example.ahk that comes with the library:

Code: Select all

; Simplest usage example.
; Minimal error checking (Just check if DLL loaded), just the bare essentials code-wise.

#SingleInstance, force
#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

w::
myStick.SetContPov(0, 1)
Return

w up::
myStick.SetContPov(-1, 1)
Return

s::
myStick.SetContPov(18000, 1)
Return

s up::
myStick.SetContPov(-1, 1)
Return

a::
myStick.SetContPov(27000, 1)
Return

a up::
myStick.SetContPov(-1, 1)
Return

d::
myStick.SetContPov(9000, 1)
Return

d up::
myStick.SetContPov(-1, 1)
Return
Note, however, that this code will not work very well. It is not possible to get a diagonal. If you hold W, then hold A, the hat moves to the left, not up+left. When you then release A (But are still holding W), the hat moves back to center.
Better logic is needed.

When running UCR, are you trying to download from github and run? If you use the source version from GitHub, you need to have AHK_H installed, not the regular AHK_L.
Download the zip file for UCR, then double-click UCR.exe
UCR.exe is actually the AHK_H AutoHotkey.exe, but renamed. If you replace AutoHotkey.exe in you AHK install folder with UCR.exe (renamed to Autohotkey.exe), you could then double-click UCR.ahk to run UCR, or even debug UCR with Scite4Autohotkey.

Also note that UCR suffers from the same diagonals problem as your code at the moment, because I do not have the proper plugin written to do what you want.
I may write one this weekend though.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 08:25

Actually, you piqued my interest. I think I just worked out a way to do it quite easily, so I am going to take your test script and write a proof-of-concept using that. Give me about 30 mins.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 08:41

Here's one solution, but I do not like it very much.
Going to keep looking for a better way.

Code: Select all

; Simplest usage example.
; Minimal error checking (Just check if DLL loaded), just the bare essentials code-wise.

#SingleInstance, force
#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]
x_angle := -1
y_angle := -1

; End Startup Sequence
Return

~w::
	y_angle := 0
	Gosub, SetPov
	Return

~w up::
	y_angle := -1
	Gosub, SetPov
	Return

~s::
	y_angle := 180
	Gosub, SetPov
	Return

~s up::
	y_angle := -1
	Gosub, SetPov
	Return

~a::
	x_angle := 270
	Gosub, SetPov
	Return

~a up::
	x_angle := -1
	Gosub, SetPov
	Return

~d::
	x_angle := 90
	Gosub, SetPov
	Return


~d up::
	x_angle := -1
	Gosub, SetPov
	Return

SetPov:
	out_angle := 0
	axes := 0
	if (x_angle != -1){
		out_angle += x_angle
		axes++
	}
	if (y_angle != -1){
		if (x_angle == 270){
			out_angle := 630	; bodge for up+right
		} else {
			out_angle += y_angle
		}
		axes++
	}
	if (axes){
		out_angle := (out_angle / axes) * 100
	} else {
		out_angle := -1
	}
	
	myStick.SetContPov(out_angle, 1)
	return
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 08:52

Pre-calculated lookup arrays for the win!

AxisMap := [[-1,0,18000], [9000,4500,13500], [27000,31500,22500]] Declares a lookup array for the various combination of x and y axis positions.
eg [-1,0,18000] in the array is the lookup for when is X neutral. The first value (-1) is for when Y is also neutral, the second (0) is for when Y is up, the third (18000) is for when Y is down.

So in this way, when the keys are pressed, we set x_angle and y_angle to values which point to indexes of these arrays.
Then we can easily find the angle we want with: AxisMap[x_angle, y_angle]

Code: Select all

; Simplest usage example.
; Minimal error checking (Just check if DLL loaded), just the bare essentials code-wise.

#SingleInstance, force
#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]
AxisMap := [[-1,0,18000], [9000,4500,13500], [27000,31500,22500]]
x_angle := 0
y_angle := 0

; End Startup Sequence
Return

~w::
	y_angle := 2
	Gosub, SetPov
	Return

~w up::
	y_angle := 1
	Gosub, SetPov
	Return

~s::
	y_angle := 3
	Gosub, SetPov
	Return

~s up::
	y_angle := 1
	Gosub, SetPov
	Return

~a::
	x_angle := 3
	Gosub, SetPov
	Return

~a up::
	x_angle := 1
	Gosub, SetPov
	Return

~d::
	x_angle := 2
	Gosub, SetPov
	Return

~d up::
	x_angle := 1
	Gosub, SetPov
	Return

SetPov:
	myStick.SetContPov(AxisMap[x_angle, y_angle], 1)
	return
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 10:12

tnx for answer but wasd still not working :(

here is my config

Code: Select all

; Simplest usage example.
; Minimal error checking (Just check if DLL loaded), just the bare essentials code-wise.

#SingleInstance, force
#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]

AxisMap := [[-1,0,18000], [9000,4500,13500], [27000,31500,22500]]
x_angle := 0
y_angle := 0

; End Startup Sequence
Return

; Hotkeys

t::
	myStick.SetBtn(1,1)
	Return

t up::
	myStick.SetBtn(0,1)
	Return

y::
	myStick.SetBtn(1,2)
	Return

y up::
	myStick.SetBtn(0,2)
	Return
u::
	myStick.SetBtn(1,3)
	Return

u up::
	myStick.SetBtn(0,3)
	Return
g::
	myStick.SetBtn(1,4)
	Return

g up::
	myStick.SetBtn(0,4)
	Return
h::
	myStick.SetBtn(1,5)
	Return

h up::
	myStick.SetBtn(0,5)
	Return
j::
	myStick.SetBtn(1,6)
	Return

j up::
	myStick.SetBtn(0,6)
	Return 
w::
	y_angle := 2
	Gosub, SetPov
	Return
 
w up::
	y_angle := 1
	Gosub, SetPov
	Return
 
s::
	y_angle := 3
	Gosub, SetPov
	Return
 
s up::
	y_angle := 1
	Gosub, SetPov
	Return
 
a::
	x_angle := 3
	Gosub, SetPov
	Return
 
a up::
	x_angle := 1
	Gosub, SetPov
	Return
 
d::
	x_angle := 2
	Gosub, SetPov
	Return
 
d up::
	x_angle := 1
	Gosub, SetPov
	Return
 
SetPov:
	myStick.SetContPov(AxisMap[x_angle, y_angle], 1)
	return
 
t, y ,u,g,h,j keys works corretly
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 10:59

I tested the script that I posted, and it does work. Not sure why yours doesn't.

I just committed a new version of UCR where the ButtonToButton plugin works properly with hat diagonals. Replace UCR.ahk from the ZIP with the from here.

You would need 4 ButtonToButton plugins to remap a WSAD to a hat.
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

30 Jan 2016, 12:10

tnx for help, i replaced UCR.ahk and i can map all buttons

here is my config https://i.gyazo.com/9562db46f7a83131b3d ... 405772.png

but in mortal kombat x "wasd" still did not working anyway :(

upd: same problem in mortal kombat 9 :(

upd2: i am tried to test wasd buttons on online joystick tester http://html5gamepad.com/ buttons worked correctly but left, right, up and down (wasd) still not worked :(

https://i.gyazo.com/94bdfd3e2bd03054802 ... 3a4957.png

and here is my vjoy configuration

https://i.gyazo.com/c340ea4a08017c0149c ... e604b4.png

upd3: after i set number of POVs from 0 to 4 in game right button and down button now working, but i got a new bug, something holds up - up left direction so up and left buttons stil not working :(
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 06:01

tnx a lot for help i was solved my problem by remapping wasd to axis buttons in UCR, now all wasd dirrections works perfect ;)

so i have a last question: how can i use mapped buttons and axises in macro scripts ?

for example i need something like this: axis down, axis back + button1 hold, axis forward, axis forward + button2 + button1 release

Code: Select all

~button9::                             ;POWERful macro
   send axisdown
   sleep 20
   send axisback,{button1 down}
   sleep 20
   send axisforward
   sleep 20
   send axisforward,button2,{button1 up}
  return
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 06:46

You could possibly write a script that read the output from UCR, but the intended way to do this would be to write a UCR plugin.

ie, take one of the normal remapper plugins and modify it so that instead of mapping the bindings straight through, it instead manipulates the outputs in the desired way.
for example i need something like this: axis down, axis back + button1 hold, axis forward, axis forward + button2 + button1 release
"axis down, axis back" - not sure what you mean here. A joystick is TWO axes (X and Y), not one. I presume you mean "Y Axis down, X Axis Left".
"axis forward, axis forward" - Again, unclear what you mean. Do you mean "X axis right, X axis center, X axis Right"?

What would be the trigger to send this sequence of outputs? Pressing a button?
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 06:56

yep, i want to press button9 for example, to send this sequence of outputs

so, my question is how can i call button1 or Y Axis down in the script to run it in UCR run script plugin ?

is this correct ?

Code: Select all

~9::                             ;POWERful macro
   send Y axis down
   sleep 2
   send Y axis centre 
   sleep 20
   send X axis back,{1 down}
   sleep 2
   send X axis centre
   sleep 20
   send X axis forward
   sleep 2
   send X axis centre
   sleep 20
   send X axis forward,2,{1 up}
   sleep 2
   send X axis centre
  return
 
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 07:35

To have button 9 send this sequence of actions, the "proper" way to do it in UCR would be to create a new plugin that:

Has 1 InputButton control (That you map to button 9)
Has 2 OutputButton controls (That you map to vJoy button 1 + 2)
Has 2 OutputAxis controls (That you map to vJoy X and Y axis)

When done this way, the plugin becomes "generic" insofar as the end-user can configure it to use different inputs and outputs, but the functionality remains the same.

In the event for the InputButton, you would use the SetState method of the Outputs to set their state accordingly.
This is not intended to be something that is trivial for all users to implement. In order to do this, you would need to understand how to write or modify an existing plugin.

I am at work at moment and cannot fully write and test something, but to give you an idea of what such a plugin may look like:
(You would save this as TheFatalsCustomPlugin.ahk in the Plugins\User folder)

Code: Select all

class TheFatalsCustomPlugin extends _Plugin {
	Type := "TheFatal's Custom Plugin"
	Description := "Your description here"
	; The Init() method of a plugin is called when one is added. Use it to create your Gui etc
	Init(){
		; Create the GUI
		; Add a hotkey, and give it the name "MyHk1". All hotkey objects can be accessed via this.InputButtons[name]
		; Have it call MyHkChangedState when it changes state.
		this.AddInputButton("IB1", 0, this.MyHkChangedState.Bind(this), "xm ym w200")
		; Add an Output, and give it the name "MyOp1". All output objects can be accessed via this.OutputButtons[name]
		this.AddOutputButton("OB1", 0, "xm yp+25 w200")
		this.AddOutputButton("OB2", 0, "xm yp+25 w200")
		this.AddOutputAxis("OutputAxis1", 0, "xm yp+25 w125")
		this.AddOutputAxis("OutputAxis2", 0, "xm yp+25 w125")
	}
	
	; Called when the hotkey changes state (key is pressed or released)
	MyHkChangedState(e){
		if (e){	; Only do this on press of the Input Button (e=1), do nothing on release (e=0)
			static StickOps := UCR.Libraries.StickOps
			; The input button was pressed, send the sequence of actions
			; Send Axis Down
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))
			; Send Axis Back
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(0))
			; Hold button 1
			this.OutputButtons.OB1.SetState(1)
			; Send Axis Forward
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(100))	
			Sleep 100
			; Center Axis
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(50))
			Sleep 100
			; Send Axis Forward
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(100))	
			; Hold Button 2
			this.OutputButtons.OB2.SetState(1)
			; Release Button 1
			this.OutputButtons.OB1.SetState(0)
			; Release Button 2
			this.OutputButtons.OB2.SetState(0)
			; Release Axes
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(50))
		}
	}
}
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 07:44

thanks a lot i will test it when i will be at home
TheFatal
Posts: 34
Joined: 30 Jan 2016, 06:58

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 12:57

ok, i tested it part

; Send Axis Down
this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))
; Send Axis Back
this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(0))

works correctly, but

this.OutputButtons.OB1.SetState(1)

did not holds the button, only presed it :(
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 14:03

The code I posted only holds the button for a very short amount of time - the command this.OutputButtons.OB1.SetState(1) is executed, then almost instantly the button is released by the command this.OutputButtons.OB1.SetState(0)
If you want to hold the button longer, put a Sleep command in between them.
I wasn't sure of the exact sequence and timing that you wanted, so I just chucked a load of commands in there and made sure that all the outputs ended up in a "neutral" state at the end of the script, so that it could be repeated over and over.

If you need to leave a button pressed or an axis not at center at the end of the sequence, that's not a problem for UCR, but I am not sure how well it would work in terms of being able to repeat the sequence. If you can write down the exact sequence of events, and the amount of time each of them needs to be held, then i could improve it for you.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 14:17

TheFatal wrote:yep, i want to press button9 for example, to send this sequence of outputs

so, my question is how can i call button1 or Y Axis down in the script to run it in UCR run script plugin ?

is this correct ?

Code: Select all

~9::                             ;POWERful macro
   send Y axis down
   sleep 2
   send Y axis centre 
   sleep 20
   send X axis back,{1 down}
   sleep 2
   send X axis centre
   sleep 20
   send X axis forward
   sleep 2
   send X axis centre
   sleep 20
   send X axis forward,2,{1 up}
   sleep 2
   send X axis centre
  return
I didn't actually see this before I wrote the code (Did you maybe edit the post?), so this gives me a bit more to go on.
Bear in mind that AHK cannot sleep for just 2 ms - the minimum amount of time that you can sleep is about 10ms.
I am also guessing that maybe what you want is to hold button 2 until you release the input button?
The code below shows how to do that.
So with that in mind, here is an adjusted version:

Code: Select all

class TheFatalsCustomPlugin extends _Plugin {
	Type := "TheFatal's Custom Plugin"
	Description := "Your description here"
	; The Init() method of a plugin is called when one is added. Use it to create your Gui etc
	Init(){
		; Create the GUI
		; Add a hotkey, and give it the name "MyHk1". All hotkey objects can be accessed via this.InputButtons[name]
		; Have it call MyHkChangedState when it changes state.
		this.AddInputButton("IB1", 0, this.MyHkChangedState.Bind(this), "xm ym w200")
		; Add an Output, and give it the name "MyOp1". All output objects can be accessed via this.OutputButtons[name]
		this.AddOutputButton("OB1", 0, "xm yp+25 w200")
		this.AddOutputButton("OB2", 0, "xm yp+25 w200")
		this.AddOutputAxis("OutputAxis1", 0, "xm yp+25 w125")
		this.AddOutputAxis("OutputAxis2", 0, "xm yp+25 w125")
	}
 
	; Called when the hotkey changes state (key is pressed or released)
	MyHkChangedState(e){
		if (e){	; Only do this on press of the Input Button (e=1), do nothing on release (e=0)
			static StickOps := UCR.Libraries.StickOps
			; The input button was pressed, send the sequence of actions
			; Y Axis Down
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(0))
			Sleep 10
			; Y Axis Centre
			this.OutputAxes.OutputAxis2.SetState(StickOps.AHKToVjoy(50))
			Sleep 20
			; X Axis Back
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(0))
			; Hold button 1
			this.OutputButtons.OB1.SetState(1)
			Sleep 10
			; X Axis Centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			Sleep 20
			; X Axis Forward
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(100))	
			Sleep 10
			; X Axis centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
			Sleep 20
			; X Axis Forward
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(100))	
			; Hold Button 2
			this.OutputButtons.OB2.SetState(1)
			; Release Button 1
			this.OutputButtons.OB1.SetState(0)
			; X Axis centre
			this.OutputAxes.OutputAxis1.SetState(StickOps.AHKToVjoy(50))
		} else {
			; Input Button was released
			; Release Button 2
			this.OutputButtons.OB2.SetState(0)
		}
	}
}

User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: problem with AHK-CvJoyInterface

02 Feb 2016, 14:20

Also, what you probably need to do is to select the option "Suppress Repeats: On" for the input button (Button 9 for you) - drop down the first combobox in the plugin's GUI, and select the "Suppress repeats" option.
This stops the sequence from repeating over and over while you hold the button.
[Edit] Just realized that this only applies if the Input Button is a keyboard key. As you are using a joystick button to trigger the sequence, this probably does not apply - joystick buttons do not "repeat" when held, like keyboard keys do.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 54 guests