Need Assistance Mapping Joystick to Keyboard

Need Assistance Mapping Joystick to Keyboard

Postby bdsmokey » Sun 18 Apr, 2010 3:10 pm

I have a PPJOY virtual joystick, in which I am trying to bind keys to the WASD directions. My code while working is flawed, and I cannot find examples. Numerous keypress of simulations buttons will soon invalidate movement.




So GOAL:
If I press A Joystick goes all the way left
(RELEASES WHEN BUTTON IS RELEASED)
If I press D Joystick goes all the way Right
(RELEASES WHEN BUTTON IS RELEASED)
If I press S Joystick goes all the way Down
(RELEASES WHEN BUTTON IS RELEASED)
If I press W Joystick goes all the way Down
(RELEASES WHEN BUTTON IS RELEASED)

Here is my code:

PPJoy1.Analog0 = ((Keyboard.D+0)/1)
PPJOY1.Analog1 = ((Keyboard.S+0)/1)
PPJoy1.Analog0 = ((Keyboard.A+0)*-1)
PPJoy1.Analog1 = ((Keyboard.W+0)*-1)


On another note: Is it possible to lock in the current position of the axis until the button is released?

Currently if I press the Axis while holding the button, the Axis takes over movement.
bdsmokey
 

Re: Need Assistance Mapping Joystick to Keyboard

Postby lednerg » Sun 18 Apr, 2010 6:03 pm

I don't have PPJoy installed, so I can't test these. But they should work:
Code: Select all
PPJoy1.Analog0 = - A + D
PPJoy1.Analog1 = - W + S

What that does:
W... PPJoy1.Analog0 = -1
A... PPJoy1.Analog1 = -1
S... PPJoy1.Analog0 = 1
D... PPJoy1.Analog1 = 1
Both W & S... PPJoy1.Analog0 = 0
Neither W nor S... PPJoy1.Analog0 = 0
Both A & D... PPJoy1.Analog1 = 0
Neither W nor S... PPJoy1.Analog1 = 0

If you want to slow it down, then try this instead:
Code: Select all
var.Speed_X = .05    // between 0 and 1
var.Speed_Y = .05    // between 0 and 1
var.X = - A + D
var.Y = - W + S
var.SlowX = var.SlowX * (1 - var.Speed_X) + var.X * var.Speed_X
var.SlowY = var.SlowY * (1 - var.Speed_Y) + var.Y * var.Speed_Y
PPJoy1.Analog0 = DeadZone(var.SlowX, .001)
PPJoy1.Analog1 = DeadZone(var.SlowY, .001)

var.Speed_X and var.Speed_Y are for how fast each axis moves. Changing them to something higher (like .25) will make them move faster. 1 will make them move instantly to each side, like the first script. 0 will disable them.
User avatar
lednerg
 
Posts: 116
Joined: Fri 08 Jan, 2010 12:01 pm

Re: Need Assistance Mapping Joystick to Keyboard

Postby TiagoTiago » Mon 19 Apr, 2010 3:47 am

myself just now wrote:if you wanna just have the axis snap to full when the keys are pressed, you could do somthing like this:


Code: Select all
ppjoy0.Analog0 = (key.D +1)  - (key.A +1)
//gotta use the plus one to make them numbers i think,
// and since you're subtracting +1 from +1 it  goes away leaving just what matters


if you wanna smooth, you could do somthing like:
Code: Select all
ppjoy0.Analog0 = smooth((key.D +1)  - (key.A +1), 5)
//gotta use the plus one to make them numbers i think,
// and since you're subtracting +1 from +1 it  goes away leaving just what matters

seems i wasn't carefull enough when reading the other posts, sorry

Code: Select all
PPJoy1.Analog0 = smooth(- A + D, 5)

works just fine :)
(notifications don't always get to my inbox, if you think it happened please let me know)
TiagoTiago
 
Posts: 284
Joined: Fri 08 Jan, 2010 3:08 am

Re: Need Assistance Mapping Joystick to Keyboard

Postby lednerg » Mon 19 Apr, 2010 4:51 am

The problem with Smooth() is that there are only 30 values you can use for it. Using a low-pass filter like I did allows for a near infinite amount of adjustment.
User avatar
lednerg
 
Posts: 116
Joined: Fri 08 Jan, 2010 12:01 pm

Re: Need Assistance Mapping Joystick to Keyboard

Postby TiagoTiago » Mon 19 Apr, 2010 4:53 am

hm, well, you can nest smooths, i'm not sure what kind of filter that works like though
(notifications don't always get to my inbox, if you think it happened please let me know)
TiagoTiago
 
Posts: 284
Joined: Fri 08 Jan, 2010 3:08 am

Re: Need Assistance Mapping Joystick to Keyboard

Postby TiagoTiago » Mon 19 Apr, 2010 4:58 am

this looks fun:
Code: Select all
PPJoy1.Analog2 = smooth(- A + D, 30)
PPJoy1.Analog3 = smooth(smooth(- A + D, 30),30)
PPJoy1.Analog4 = smooth(smooth(smooth(- A + D, 30),30),30)
PPJoy1.Analog5 = smooth(smooth(smooth(smooth(- A + D, 30),30),30),30)
PPJoy1.Analog6 = smooth(smooth(smooth(smooth(smooth(- A + D, 30),30),30),30),30)
PPJoy1.Analog7 = smooth(smooth(smooth(smooth(smooth(smooth(- A + D, 30),30),30),30),30),30)

(i got all those axes mapped to the six axes that show as vertical red bars on the control panel thingy)
(notifications don't always get to my inbox, if you think it happened please let me know)
TiagoTiago
 
Posts: 284
Joined: Fri 08 Jan, 2010 3:08 am

Re: Need Assistance Mapping Joystick to Keyboard

Postby lednerg » Mon 19 Apr, 2010 10:15 am

[sorry about taking over your thread, bdsmokey]

Smooth() has a number of issues besides the 30 frame limit. Since it's based off of time, there's always going to be the issue of lag whenever it's set above a certain amount. The smooth amount also has to be an integer and it cannot be a variable. While it's really easy to put in a script, it's really not the best thing for all circumstances.

A Low-Pass filter, on the other hand, has none of those limitations. It's based off of the current position only, not positions from previous frames. It's just going to go from where it already is to wherever the input is pointing it to. You can also use a variable for the strength of the filter, like with the MouseWheel in the example below. (You can even link the strength of the filter to the speed of your motions. For example, you can make it so holding a Wiimote steady will increase the filter for more accuracy, while moving the Wiimote will lessen the filter for more responsiveness.)
Code: Select all
// Comparison of a Low-Pass filter with Smooth()

// WASD moves cursors. MouseWheel adjusts speed of Low-Pass cursor.
// Cursor 1 = Low-Pass
// Cursor 2 = Smooth()

PIE.FrameRate = 20hz // slowed down for demonstration

var.X = - A + D  // keys for left & right
var.Y = - W + S  // keys for up & down

var.DefaultSpeed_X = .205 // Use any number between 0 and 1.
var.DefaultSpeed_Y = .205 // Can also be another variable.

// the mousewheel will adjust both Speed values
if mouse.WheelUp then var.Speed_Adjust = var.Speed_Adjust + .001
if mouse.WheelDown then var.Speed_Adjust = var.Speed_Adjust - .001

// applies mousewheel adjustment, keeps speed above 0
var.Speed_X = abs(var.DefaultSpeed_X + var.Speed_Adjust)
var.Speed_Y = abs(var.DefaultSpeed_Y + var.Speed_Adjust)

// LowPass filter
var.LowPass_X = var.LowPass_X * (1 - var.Speed_X) + var.X * var.Speed_X
var.LowPass_Y = var.LowPass_Y * (1 - var.Speed_Y) + var.Y * var.Speed_Y

// Smooth() filter
var.Smooth_X = Smooth( var.X , 15) // Use an integer from 1 to 30.
var.Smooth_Y = Smooth( var.Y , 15) // Cannot be a variable.

// LowPass cursor, placed on the left
cursor1.x = var.LowPass_X*.2 + .35
cursor1.y = var.LowPass_Y*.2 + .5

// Smooth() cursor, placed on the right
cursor2.x = var.Smooth_X*.2 + .65
cursor2.y = var.Smooth_Y*.2 + .5

debug = "[ Speed_X = 0." + int(var.Speed_X * 1000) + " ]   [ Speed_Y = 0."  + int(var.Speed_Y * 1000) + " ]"


Or to simplify that all:
Code: Select all
var.LowPass_X = var.LowPass_X * .8 + (- A + D) * .2
var.LowPass_Y = var.LowPass_Y * .8 + (- W + S) * .2
cursor1.x = var.LowPass_X/2 + .5
cursor1.y = var.LowPass_Y/2 + .5

.8 and .2 can be replaced with any two decimals which add up to 1.
User avatar
lednerg
 
Posts: 116
Joined: Fri 08 Jan, 2010 12:01 pm

Re: Need Assistance Mapping Joystick to Keyboard

Postby TiagoTiago » Mon 19 Apr, 2010 11:02 am

that LPF thing is the shit :D
(notifications don't always get to my inbox, if you think it happened please let me know)
TiagoTiago
 
Posts: 284
Joined: Fri 08 Jan, 2010 3:08 am

Re: Need Assistance Mapping Joystick to Keyboard

Postby victor » Wed 26 May, 2010 6:03 pm

Hi guys,

I'm trying to emulate a joystick/controller, to use only the keyboard with an app that doesn't have support for keyboard. I think the solution is here somewhere.

More specifically, what I need is close to what was said here, only it is important that this has to work without any external joystick attached:

Quote:
If I press A Joystick goes all the way left
(RELEASES WHEN BUTTON IS RELEASED)
If I press D Joystick goes all the way Right
(RELEASES WHEN BUTTON IS RELEASED)
If I press S Joystick goes all the way Down
(RELEASES WHEN BUTTON IS RELEASED)
If I press W Joystick goes all the way Down
(RELEASES WHEN BUTTON IS RELEASED)

The issue is I'm new at this, I have PPjoy, I just don't know how to configure it, so that the keyboard takes over the commands. I read that this might be possible with the help of AHK + PPJoy but I really have no idea how, so I am kindly asking for a sort of step by step guide.
victor
 


Return to Keyboard

Who is online

Users browsing this forum: No registered users and 1 guest

cron