Tool that converts the mouse axis?

Whatever you want here. Just make sure it's off topic. Which...I guess if the topic is being off topic, then it means you should be on topic. Understand?
Post Reply
Message
Author
User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Tool that converts the mouse axis?

#1 Post by 3cmSailorfuku » Fri Apr 25, 2008 8:39 am

Hmm, I don't know what kind of keyword I should use for this to find anything related on google.
What I need is basically a tool that converts the mouse axis/movement (Y,X) into keyboard keys like

+Y = W
-Y = S
-X = A
+X = D

Maybe its even possible in Micromacro, but that would be too slow maybe?
I could need such a tool to make ego-shooters on the PSP more playable when im playing it on windows.
Senn such similiar tool for ResidentEvil4 for the PC.

Or maybe someone knows that the definitions of the mouse are if its moving up down left or right (It's AXIS_Y+ etc on a PS2 Controller).

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Tool that converts the mouse axis?

#2 Post by Administrator » Fri Apr 25, 2008 5:14 pm

There is a program called JoyToKey that can do this. It could also be done in MicroMacro by checking the mickeys and translating it into keyboard presses simply by using a series of if statements, but JoyToKey is probably more suited to your needs.

JoyToKey: http://www.electracode.com/4/joy2key/Jo ... ersion.htm

mousetokey.lua

Code: Select all

threshold = 15;

function exitCallback()
  keyboardRelease(key.VK_LEFT);
  keyboardRelease(key.VK_RIGHT);
  keyboardRelease(key.VK_UP);
  keyboardRelease(key.VK_DOWN);
end

function main()
  local oldx, oldy, newx, newy;
  newx, newy = mouseGetPos();
  origx, origy = newx, newy;

  local lastl, lastu, lastr, lastd = false, false, false, false;

  atExit(exitCallback);

  while(true) do
    -- minimize CPU usage and give other threads a chance to process
    -- while keeping very responsive
    coroutine.yield();
    rest(1);

    -- update mickeys
    newx, newy = mouseGetPos();
    local deltax = newx - origx;
    local deltay = newy - origy;

    -- X AXIS
    if( deltax <= (-threshold) ) then
      if( lastr == true ) then
        lastr = false; keyboardRelease(key.VK_RIGHT);
      end

      if( lastl == false ) then
        lastl = true; keyboardHold(key.VK_LEFT);
      end
    end

    if( deltax >= threshold ) then
      if( lastl == true ) then
        lastl = false; keyboardRelease(key.VK_LEFT);
      end

      if( lastr == false ) then
        lastr = true; keyboardHold(key.VK_RIGHT);
      end
    end

    if( deltax > (-threshold) and deltax < threshold ) then
      if( lastl ) then
        lastl = false; keyboardRelease(key.VK_LEFT); end
      if( lastr ) then
        lastr = false; keyboardRelease(key.VK_RIGHT); end
    end

    -- Y AXIS
    if( deltay <= (-threshold) ) then
      if( lastd == true ) then
        lastd = false; keyboardRelease(key.VK_DOWN);
      end

      if( lastu == false ) then
        lastu = true; keyboardHold(key.VK_UP);
      end
    end

    if( deltay >= threshold ) then
      if( lastu == true ) then
        lastu = false; keyboardRelease(key.VK_UP);
      end

      if( lastd == false ) then
        lastd = true; keyboardHold(key.VK_DOWN);
      end
    end

    if( deltay > (-threshold) and deltay < threshold ) then
      if( lastu ) then
        lastu = false; keyboardRelease(key.VK_UP); end
      if( lastd ) then
        lastd = false; keyboardRelease(key.VK_DOWN); end
    end
  end
end

startMacro(main);
This script will make the mouse function similar to that of a joystick (just like JoyToKey). When you start the script, it sets the original (zeroed) position. Moving it in any direction will cause the correct key presses to happen. To stop moving in that direction, you need to move it back to it's origin.

You might want to change the threshold variable, though. A higher number means that it won't start generating keypresses as quickly, whereas a smaller number would mean the opposite (of course). Just play with it to see what works best.


Most importantly, I have found a bug in the current version of MicroMacro which only effects the arrow keys...so unless you get a fixed version, the above script won't work at all. Newest version has just been uploaded. Of course, since you're using WASD instead of arrow keys, you'd only need to fix the script to use those instead, and it will work either way (just replace all key.VK_LEFT with A, key.VK_UP with W, ...).

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Tool that converts the mouse axis?

#3 Post by 3cmSailorfuku » Sat Apr 26, 2008 4:35 am

JoyToKey is a good one, the only problem I seem to have it only works Gamepad -> Mouse/Keyboard. I would need Mouse -> Keyboard.

The script is exactly what I need, however it should snap back when the mouse isnt being moved. Because either I have to return to the middle on my own.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Tool that converts the mouse axis?

#4 Post by Administrator » Sat Apr 26, 2008 11:16 am

JoyToKey is a good one, the only problem I seem to have it only works Gamepad -> Mouse/Keyboard. I would need Mouse -> Keyboard.
I'm almost certain that JoyToKey supports this. I used it briefly for RE4. It turns out that using the mouse in RE4 made it almost impossible to control, so I just stuck with the keyboard.
The script is exactly what I need, however it should snap back when the mouse isnt being moved. Because either I have to return to the middle on my own.
I see. Then JoyToKey is not for you; it would operate exactly like the script did.


This should work. You might have to play around with zerotime as well now. I haven't had the chance to test it.

Code: Select all

threshold = 15;
zerotime = 10;

function exitCallback()
  keyboardRelease(key.VK_LEFT);
  keyboardRelease(key.VK_RIGHT);
  keyboardRelease(key.VK_UP);
  keyboardRelease(key.VK_DOWN);
end

function main()
  local oldx, oldy, newx, newy;
  newx, newy = mouseGetPos();
  origx, origy = newx, newy;

  local lastl, lastu, lastr, lastd = false, false, false, false;
  local xzeroframe, yzeroframe = 0, 0;

  atExit(exitCallback);

  while(true) do
    -- minimize CPU usage and give other threads a chance to process
    -- while keeping very responsive
    coroutine.yield();
    rest(1);

    -- update mickeys
    newx, newy = mouseGetPos();
    local deltax = newx - origx;
    local deltay = newy - origy;

    -- X AXIS
    if( deltax <= (-threshold) ) then
      xzeroframe = 0;
      if( lastr == true ) then
        lastr = false; keyboardRelease(key.VK_RIGHT);
      end

      if( lastl == false ) then
        lastl = true; keyboardHold(key.VK_LEFT);
      end
    end

    if( deltax >= threshold ) then
      xzeroframe = 0;
      if( lastl == true ) then
        lastl = false; keyboardRelease(key.VK_LEFT);
      end

      if( lastr == false ) then
        lastr = true; keyboardHold(key.VK_RIGHT);
      end
    end

    if( deltax > (-threshold) and deltax < threshold ) then
      xzeroframe = xzeroframe + 1;
      if( lastl ) then
        lastl = false; keyboardRelease(key.VK_LEFT); end
      if( lastr ) then
        lastr = false; keyboardRelease(key.VK_RIGHT); end
    end

    -- Y AXIS
    if( deltay <= (-threshold) ) then
      yzeroframe = 0;
      if( lastd == true ) then
        lastd = false; keyboardRelease(key.VK_DOWN);
      end

      if( lastu == false ) then
        lastu = true; keyboardHold(key.VK_UP);
      end
    end

    if( deltay >= threshold ) then
      yzeroframe = 0;
      if( lastu == true ) then
        lastu = false; keyboardRelease(key.VK_UP);
      end

      if( lastd == false ) then
        lastd = true; keyboardHold(key.VK_DOWN);
      end
    end

    if( deltay > (-threshold) and deltay < threshold ) then
      yzeroframe = yzeroframe + 1;
      if( lastu ) then
        lastu = false; keyboardRelease(key.VK_UP); end
      if( lastd ) then
        lastd = false; keyboardRelease(key.VK_DOWN); end
    end


    if( xzeroframe > zerotime ) then
      origx = newx;
      xzeroframe = 0;
    end

    if( yzeroframe > zerotime ) then
      origy = newy;
      yzeroframe = 0;
    end
  end
end

startMacro(main);

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Tool that converts the mouse axis?

#5 Post by 3cmSailorfuku » Sat Apr 26, 2008 11:47 am

elverion wrote: I'm almost certain that JoyToKey supports this. I used it briefly for RE4. It turns out that using the mouse in RE4 made it almost impossible to control, so I just stuck with the keyboard.
Yes, in RE4 I disliked MouseAim aswell and just played with my gamepad. But in online games they aren't slow as zombies... :P
elverion wrote: I see. Then JoyToKey is not for you; it would operate exactly like the script did.
Actually JoyToKey would be perfect if I could setup Mouse <-> Keyboard, JoyToKey also didn't wanted to startup without having my PS2 Gamepad connected. So I kinda doubt I could've used anything else than a gamepad.

What I meant with "Snapping the mouse back" wasn't to snap back the view ingame, I meant the mouse position because the script would only stand still if the mouse was in the center, if I had the mouse a bit left it would constantly send the LEFT key. But I already fixed that and it works good enough... Though JoyToKey would be a bit more comfortable :) Thank you

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Tool that converts the mouse axis?

#6 Post by Administrator » Sat Apr 26, 2008 12:35 pm

What I meant with "Snapping the mouse back" wasn't to snap back the view ingame, I meant the mouse position because the script would only stand still if the mouse was in the center, if I had the mouse a bit left it would constantly send the LEFT key
The fix I applied to the script should have done just that. I can see how the variable names might have confused you, though. I am interested in seeing how you went about solving the same problem.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests