Mouse to WASD (mouse steering)

Official forum for open source FreePIE discussion and development.
Post Reply
Friedloc
One Eyed Hopeful
Posts: 5
Joined: Tue Oct 28, 2014 5:47 am

Mouse to WASD (mouse steering)

Post by Friedloc »

First hi all. :mrgreen:

To describe my problem, I have a spinal cord injury (paralysed fingers) and so I have a bit of a problem with WASD or arrow keys.
But my real problem is, I suck at coding. :oops:

I bought Rage and I am stuck at racing. So I tried a few glovepie scripts. The one below works best but it runs continously and I would need it to be toggled by key.
I am too stupid to add the toggle code (from the second code below) to the first glovepie script. I've tried to add it but my script refused to run.
The glovepie forum seems to be dead so I googled and found freepie. :D
I found freepie scripts for mouse to vjoy. But I would need mouse to wasd. And since I know next to nothing about phyton coding, I can't alter the code myself. I have to plee for help. :oops:

Could somebody point me to a freepie script (I found nothing suitable) or would be so nice to write a script similar to the first code?
I would love to stick with freepie because it is in active development. ;)

Or could somebody alter the first code to be toggled by F12?

Thx in advance. ;)


Code: Select all

// Mouse to WASD
// by lednerg

var.Speed = 1
var.MouseX = delta(mouse.x)
var.MouseY = delta(mouse.y)
var.WASD_Amount = sqrt((abs(var.MouseX))^2 + (abs(var.MouseY))^2) * var.Speed
var.WASD_xAng = int(MapEnsureRange(abs(arcsin(var.MouseX / var.WASD_Amount)),0,85,0,200))
var.WASD_yAng = int(MapEnsureRange(abs(arcsin(var.MouseY / var.WASD_Amount)),0,85,0,200))
if var.WASD_xAng > var.WASD_yAng {
   var.WASD_a = var.WASD_xAng
   var.WASD_b = var.WASD_yAng
   var.WASD_abSwitch = false
else
   var.WASD_a = var.WASD_yAng
   var.WASD_b = var.WASD_xAng
   var.WASD_abSwitch = true
}
if var.WASD_Init = false and var.WASD_Amount > 0 {
   var.WASD_aC = var.WASD_a
   var.WASD_bC = var.WASD_b
   var.WASD_Init = true
}
if var.WASD_Amount = 0 {
   var.WASD_Init = false
}
if var.WASD_bC > var.WASD_a and var.WASD_Init = true and var.WASD_AD_key = false and var.WASD_WS_key = false {
   if var.WASD_aC < var.WASD_a then var.WASD_aC = var.WASD_a
   var.WASD_bC = abs(var.WASD_bC - var.WASD_aC)
   if var.WASD_abSwitch = false then var.WASD_WS_key = true else var.WASD_AD_key = true
}
if var.WASD_bC <= var.WASD_a and var.WASD_Init = true and var.WASD_AD_key = false and var.WASD_WS_key = false {
   if var.WASD_abSwitch = false then var.WASD_AD_key = true else var.WASD_WS_key = true
   var.WASD_aC = abs(var.WASD_aC - var.WASD_bC)
   var.WASD_bC = var.WASD_b + var.WASD_bC
}
var.WASD_Pause = int(MapEnsureRange( 200 - var.WASD_Amount * 5000 ,125,250,0,200))
if var.WASD_AD_key = true {
   key.a = var.MouseX < -.0005
   key.d = var.MouseX > .0005
   wait 10 ms     
   if var.MouseX > -.05 then key.a = false
   if var.MouseX < .05 then key.d = false
   wait var.WASD_Pause ms
   var.WASD_AD_key = false
}
if var.WASD_WS_key = true {
   key.w = var.MouseY < -.0005
   key.s = var.MouseY > .0005
   wait 10 ms
   if var.MouseY > -.05 then key.w = false
   if var.MouseY < .05 then key.s = false
   wait var.WASD_Pause ms
   var.WASD_WS_key = false
}

Code: Select all

////////////////////////////////////////
//Toggle from mouse to steering wheel.//
////////////////////////////////////////

if key.space then
   var.mouse ++
   wait 2s

endif

  ///////////////////
//Unlocking Mouse//
///////////////////

if var.mouse > 1 then
   var.mouse = 0
   Say("Mouse Unlocked")
endif



  ////////////////////////////////////////
//So it only works when it is toggled.//
////////////////////////////////////////

if var.mouse = true then
   mouse.swallow = true

   if delta(smooth(mouse.DirectInputX))<0 then
      key.A=1
      else key.A=0

   if delta(smooth(mouse.DirectInputX))>0 then
      key.D=1
      else key.D=0

   if delta(smooth(mouse.DirectInputY))<0
      key.W=1
      else key.W=0

   if delta(smooth(mouse.DirectInputY))>0
      key.S=1
      else key.S=0
    else mouse.swallow = false
endif
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to WASD (mouse steering)

Post by CyberVillain »

Friedloc
One Eyed Hopeful
Posts: 5
Joined: Tue Oct 28, 2014 5:47 am

Re: Mouse to WASD (mouse steering)

Post by Friedloc »

Thx for the reply, but this includes vjoy. RAGE does not support joysticks, or I did not find out how to properly setup joysticks with Rage.
Hence the question for a direct mouse to wasd script.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to WASD (mouse steering)

Post by CyberVillain »

Its Rage the FPS game?

How do you want to stear the keyboard?
Friedloc
One Eyed Hopeful
Posts: 5
Joined: Tue Oct 28, 2014 5:47 am

Re: Mouse to WASD (mouse steering)

Post by Friedloc »

Yes, rage the fps.
I have a trackball. The left right movement is translated through the script to ad, up down to ws.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to WASD (mouse steering)

Post by CyberVillain »

Friedloc wrote:Yes, rage the fps.
I have a trackball. The left right movement is translated through the script to ad, up down to ws.

And the mouse move, do you hold down a button to to keyboad actions and if relased the mouse is used as normal?
Friedloc
One Eyed Hopeful
Posts: 5
Joined: Tue Oct 28, 2014 5:47 am

Re: Mouse to WASD (mouse steering)

Post by Friedloc »

No, I just move the ball of the trackball left and right. Forward and back I can press. It is the coordination I lack.
Imagine me with two fists doing all the movement. With the left fist I push the ball, with the right fist I tap forward or back arrow key.

Image

This is my trackball.

I would like to toggle the script with F12 or something.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to WASD (mouse steering)

Post by CyberVillain »

okej, so its both a mouse and a trackall correct? So you will use the mouse part as the mouse and the trackball to walk?
Friedloc
One Eyed Hopeful
Posts: 5
Joined: Tue Oct 28, 2014 5:47 am

Re: Mouse to WASD (mouse steering)

Post by Friedloc »

You confuse me. ;) It is a trackball, works like a mouse only upside down. :D

Forward und backwards I use the arrow keys on keyboard.
But left and right I would steer with the ball.

Code: Select all

if delta(smooth(mouse.DirectInputX))<0 then
      key.A=1
      else key.A=0

if delta(smooth(mouse.DirectInputX))>0 then
      key.D=1
      else key.D=0

endif
Like this glovepie code.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to WASD (mouse steering)

Post by CyberVillain »

If left and right on the mouse is taken, how do you look left right?
rodentz3
One Eyed Hopeful
Posts: 4
Joined: Sun Jan 03, 2016 7:06 am

Re: Mouse to WASD (mouse steering)

Post by rodentz3 »

search on Google for altController. Its a free program that can do what you want.
Post Reply

Return to “FreePIE”