From GlovePIE
Just some code which may inspire you:
Title
(Please use this format to avoid frustration.)
Sample Code
if starting then
var.init=true
end
Keyboard.Control AND Keyboard.R = Wiimote.A
if Keyboard.Shift then
var.speed=0.8
else
var.speed=0.2
end
PPJoy.Up = Keyboard.W * var.speed
toggle(var.whatever) = pressed(key.space)
debug = "Pitch of wiimote is: " + Wiimote.Pitch
debug=1/RemoveUnits(delta(TimeStamp)) + " fps"
; glovepie scripts run about 60 times a second
Var.Pitch = MapRange(Smooth(Wiimote.Pitch, 5) , -90 degrees, 90 degrees, -1, 1)
Var.Roll = MapRange(Smooth(Wiimote.Roll, 5) , -180 degrees, 180 degrees, -1, 1)
Var.Yaw = MapRange(Smooth(Wiimote.Yaw, 5) , -180 degrees, 180 degrees, -1, 1)
debug = Var.Pitch +" "+ Var.Roll +" "+ Var.Yaw
|
More Sample Code
// Not working before version 0.44
if shift then var.speed = 100% else var.speed = 20%
xinput.LeftStick = WASD * var.speed
|
Wheel2WASD
/* Script for using a steering wheel with programs that use WASD for steering.
2011 - Keith 'DeadlyDad' Olson
Essentially, it holds down a desired key for a number of cycles, then
releases it and won't hold it down again until the held down time + the
released time = PIECycleLength.
*/
// Constants
var.SteeringDeadZoneLow = -.5
var.SteeringDeadZoneHigh = .5
var.AccelDeadZoneLow = -.5
var.AccelDeadZoneHigh = .5
var.PIEcyclelength = 10
// Main Loop -------------------------------------------------------------------
// Press button to turn emulation on/off
If released(Joystick.Wheel1.Button1)
toggle(var.DrivingControlsOn)
Keyboard.W = 0
Keyboard.A = 0
Keyboard.S = 0
Keyboard.D = 0
endif
if var.DrivingControlsOn
// Setting up keyboard variables (if needed)
'Keyboard.RepeatFakeKeys = False
'Keyboard.RepeatMultipleFakeKeys = False
var.PIEcycle = (var.PIEcycle mod var.PIEcyclelength) + 1
// Steering
var.Steering = MapRange(Joystick.Wheel1.x,-1,1,-1*var.PIEcyclelength,var.PIEcyclelength)
var.SteeringVal = abs(var.steering)
// Steering left
if var.Steering < var.SteeringDeadZoneLow
if var.SteeringVal >= var.PIEcycle
Keyboard.A = 1
else
Keyboard.A = 0
endif
else
Keyboard.A = 0
endif
// Steering right
if var.Steering > var.SteeringDeadZoneHigh
if var.SteeringVal >= var.PIEcycle
Keyboard.D = 1
else
Keyboard.D = 0
endif
else
Keyboard.D = 0
endif
'-------------------------------------------------------------------------------
// Speed Control
/* Note: The Microsoft Sidewinder Force Feedback Wheel I'm using has separate
axes for the brake and accelerator, which I combine here into a single variable.
*/
var.AccelY = MapRange(Joystick.Wheel1.y,-1,1,var.PIEcyclelength,0)
var.AccelRoll = MapRange(Joystick.Wheel1.roll,-1,1,var.PIEcyclelength,0)
var.Accel = var.AccelY - var.AccelRoll
var.AccelVal = abs(var.Accel)
// Decelerating
if var.Accel < var.AccelDeadZoneLow
if var.AccelVal >= var.PIEcycle
Keyboard.S = 1
else
Keyboard.S = 0
endif
else
Keyboard.S = 0
endif
// Accelerating
if var.Accel > var.AccelDeadZoneHigh
if var.AccelVal >= var.PIEcycle
Keyboard.W = 1
else
Keyboard.W = 0
endif
else
Keyboard.W = 0
endif
endif
|