How do I assign a button to a mouse position and bring the mouse back to that position with another button press (for VR purposes/python/freepie) via /r/learnprogramming


How do I assign a button to a mouse position and bring the mouse back to that position with another button press (for VR purposes/python/freepie)

To make a long story short, I have an oculus dk2 vr headset, a blue tooth adapter and psmove motion controller. I play a game doom 3 fully possesed in vr, and you can control your aiming separetely from your view with the mouse.

Now I was able to make my psmove act like a mouse with the built in gyroscope, which sounds more difficult than it is. I use an app called psmoveservice, wich can connect the psmove to the pc through bluetooth, then I use another app called psmovefreepiebridge which sends the raw data to an app called freepie.

Freepie is based on python syntax and you can import libraries. I started off with this code (a guy named zelmon wrote it) which assigns some buttons to the psmove, and makes the psmove act like a mouse.

def update(): #define globals #define constants mag = 1000 dz = 0.005 i=0 j=0 #bind left mouse to cross button #Right mouse to circle button #Middle mouse to move mouse.leftButton = joystick[j].getDown(14) mouse.rightButton = joystick[j].getDown(13) mouse.middleButton = joystick[j].getDown(19) #Mouse movement using Gryoscope # Only moves when the trigger is held down mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag if joystick[j].getDown(20): mouse.deltaX = mdX mouse.deltaY = mdY if starting: freePieIO[0].update += update 

Now of course because the psmove doesn't use any positional tracking here it loses alignment with the aiming in game a lot, especially after changing direction. I can just align it back by aiming where the gun is and holding a button but I thought this was a bit cumbersome and change this button in a toggle button. It works perfectly but the problem is that sometimes the aim is out of my view, and that makes it quite annoying when I have to search where my gun is.

What I would want is that when I press a button the aim moves to the centre, since you mostly aim where you looking, I know what you're thinking, why not align the headset with the crosshair, but the thing is, if you want to aim at something you will look at it first but the finer aiming you do with your eyeballs. It also isn't as fun as aiming with gun 🙂

So I thought it would work quite well, and then changed my code so when I press a button the mouse goes to the center of the screen. This is the code (it also has some other code to map buttons)

def update(): #define globals #define constants mag = 1000 dz = 0.005 i=0 j=0 #bind left mouse to trigger button #Right mouse to circle #Middle mouse to triangle #up arrow key to square #down arrow key to cross #B Key to select ps button #N key to select button #Esc key to start button mouse.leftButton = joystick[j].getDown(20) mouse.rightButton = joystick[j].getDown(13) mouse.middleButton = joystick[j].getDown(12) keyboard.setKey(Key.UpArrow, joystick[j].getDown(15)) keyboard.setKey(Key.DownArrow, joystick[j].getDown(14)) keyboard.setKey(Key.B, joystick[j].getDown(16)) keyboard.setKey(Key.N, joystick[j].getDown(0)) keyboard.setKey(Key.Escape, joystick[j].getDown(3)) #Mouse movement using Gryoscope # move button centers aim mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag mouse.deltaX = mdX mouse.deltaY = mdY if joystick[j].getDown(19): import ctypes ctypes.windll.user32.SetCursorPos(1000, 500) if starting: freePieIO[0].update += update 

Now the command uses to set the mouse to the center of the screen is the setcursor command, which works perfectly, only it doesn't work in game.

With doing some research I realized games don't use the mouse position of windows but rather use the raw data from the mouse driver, or something like that anyway.

So I think I can only solve this problem by using a code that remembers the mouse position when I press a button and then goes back to that position when I press another button. I can figure out the button mapping, the code for remembering and going back to a certain position I cannot.

It's either that or communicating with one of the drivers (mouse driver, directinput) which is even harder.

So if anyone would have any idea where I need to start I would be very happy 🙂

Submitted July 14, 2017 at 09:36AM by Masspoint
via reddit http://ift.tt/2uhnjMZ

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s