Keyboard to vJoy axis. Possible?

Official forum for open source FreePIE discussion and development.
Post Reply
User avatar
andreaspada
One Eyed Hopeful
Posts: 23
Joined: Thu Jul 13, 2017 10:06 am
Location: Rio de Janeiro
Contact:

Keyboard to vJoy axis. Possible?

Post by andreaspada »

Hi! I'm trying to improve my scripts with one more functionality. I'd like to use my keyboard to control the headlook movement (like a virtual trackir), to provide simple macros and more granular and precise movements.
Is it possible to simulate a vJoy axis via jeyboard?

For example, I already did so:

Code: Select all

if keyboard.getPressed(Key.NumberPad4): # left
	kx = kx -500
and

Code: Select all

vJoy[2].x = kx
although, even if vJoy Monitor correctly sees that the x values changes, the game (Elite:Dangerous) do not recognize my keys as axis...
Commander89
One Eyed Hopeful
Posts: 7
Joined: Tue Jul 11, 2017 1:49 pm

Re: Keyboard to vJoy axis. Possible?

Post by Commander89 »

I have to found that if statements don't really work for mapping keyboard presses to joystick commands. Don't know if it will solve your problem but maybe you could try this sort of makeup

Code: Select all

keyboard.setKey(Key.U, joystick[j].getDown(19))
The statement works with my psmove controller, so I suppose it should work with your joystick as well. I'm very noobish at this sort of thing but I think the code you're looking for should look something like this.

Code: Select all

keyboard.setKey(Key.Numberpad4, vJoy[2].x = kx))
User avatar
andreaspada
One Eyed Hopeful
Posts: 23
Joined: Thu Jul 13, 2017 10:06 am
Location: Rio de Janeiro
Contact:

Re: Keyboard to vJoy axis. Possible?

Post by andreaspada »

Many thanks, I'll give it a try!
Jabberwock
Cross Eyed!
Posts: 196
Joined: Mon Mar 02, 2015 3:58 pm

Re: Keyboard to vJoy axis. Possible?

Post by Jabberwock »

Your code is fine and it is working. The reason that it is not seen in the game is because the values for axes for vJoy and other controllers (and plugins) are not normalized. Some operate in the range -1000 to 1000, other (such as vJoy) in the range of -32767 to 32767. Just increase the value and it should work.

For debugging controllers input I suggest using DxTweak2, it shows you both the raw data received and how it is interpreted by the system.
User avatar
andreaspada
One Eyed Hopeful
Posts: 23
Joined: Thu Jul 13, 2017 10:06 am
Location: Rio de Janeiro
Contact:

Re: Keyboard to vJoy axis. Possible?

Post by andreaspada »

Wow, this is pretty awesome! Thanks for your reply, I'll check again!
User avatar
andreaspada
One Eyed Hopeful
Posts: 23
Joined: Thu Jul 13, 2017 10:06 am
Location: Rio de Janeiro
Contact:

Re: Keyboard to vJoy axis. Possible?

Post by andreaspada »

For some reasons, it works to me only if I initialize the Axis using xoutput, this way:

Code: Select all

# Mapping keyboard to the axis, to properly initialize them

# Left
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.LeftArrow):
	kbdX = xoutput[0].AxisMin
# Down
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.DownArrow):
	kbdY = xoutput[0].AxisMin
# Right
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.RightArrow):
	kbdX = xoutput[0].AxisMax
# Up
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.UpArrow):
	kbdY = xoutput[0].AxisMax

# Directional movements, with incremental values

if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad5): # center
	kbdX = 0
	kbdY = 0
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad4): # left
	kbdX = kbdX -(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad2): # down
	kbdY = kbdY -(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad6): # right
	kbdX = kbdX +(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad8): # up
	kbdY = kbdY +(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad1): # left/down
	kbdX = kbdX -(headlook)
	kbdY = kbdY -(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad3): # down/right
	kbdY = kbdY -(headlook)
	kbdX = kbdX +(headlook)	
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad9): # right/up
	kbdX = kbdX +(headlook)
	kbdY = kbdY +(headlook)
if keyboard.getKeyDown(Key.RightControl) and keyboard.getKeyDown(Key.NumberPad7): # up/left
	kbdX = kbdX -(headlook)
	kbdY = kbdY +(headlook)


# Panel shows up and close when keys releases

# Target panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.A): # Target Panel
	kbdX = -11500
	kbdY = -2100
if keyboard.getKeyUp(Key.LeftShift) and (kbdX == -11500):
	kbdX = 0
	kbdY = 0

# System panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.D): # System Panel
	kbdX = 11500
	kbdY = -2100
if keyboard.getKeyUp(Key.LeftShift) and (kbdX == 11500):
	kbdX = 0
	kbdY = 0

# Role panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.S): # Role Panel
	kbdX = 0
	kbdY = -11500
if keyboard.getKeyUp(Key.LeftShift) and (kbdY == -11500):
	kbdX = 0
	kbdY = 0

# axis filtering for headlook
headlookX = filters.deadband((mouseX), 500) 
headlookY = filters.deadband((filters.mapRange((mouseY), -100, 100, 100, -100)), 500)

# Switch mouse headlook - it temporary disable the mouse movements
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.W):
	vJoy[2].x = headlookX
	vJoy[2].y = headlookY
	vJoy[1].x = 0
	vJoy[1].y = 0
else:
	vJoy[2].x = kbdX
	vJoy[2].y = kbdY
It's working: not sure if is it the best implementation, but it works.
Jabberwock
Cross Eyed!
Posts: 196
Joined: Mon Mar 02, 2015 3:58 pm

Re: Keyboard to vJoy axis. Possible?

Post by Jabberwock »

Now I am rather confused... xoutput[0].AxisMax is simply 32767, which is the max axis value also for vJoy. You do not seem to „initialize” anything, you just assign kbdX and kbdY the relevant values.
User avatar
andreaspada
One Eyed Hopeful
Posts: 23
Joined: Thu Jul 13, 2017 10:06 am
Location: Rio de Janeiro
Contact:

Re: Keyboard to vJoy axis. Possible?

Post by andreaspada »

Sorry to do not reply before, but my "reply" option was absent...

Yes, I'm confused too. Anyway, if I remove those lines, things do not works. Any clue?
Post Reply

Return to “FreePIE”