I've received my Gear VR last week and found out that most of the better app in Oculus Home require a gamepad. So I've had this crazy idea of trying to use one of my four xbox 360 controllers, that are connect to my PC, to send commands to the Gear Vr over WiFi as a fake gamepad.
Now i'm far from a real programmer and most of my coding experience comes from teaching myself how to work with unity, but I've some progress (albeit a hacky one) - I wrote a script in unity to read the input from my gamepad and send it via wireless ABD terminal to the app.
using UnityEngine;
using System;
using System.Collections;
using System.Diagnostics;
using XInputDotNetPure;
using System.IO;
public class Datagetter : MonoBehaviour {
public Process process;
public StreamWriter mySW;
public StreamReader mySR;
public bool left = false;
public bool right = false;
public bool up = false;
public bool down = false;
public bool start = false;
public bool xbtn = false;
// Use this for initialization
void Start () {
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WorkingDirectory = "C:\\Windows\\System32";
process.StartInfo.FileName = "cmd.exe";
// Redirects the standard input so that commands can be sent to the shell.
process.StartInfo.RedirectStandardInput = true;
// Runs the specified command and exits the shell immediately.
//process.StartInfo.Arguments = @"/c ""dir""";
process.Start();
mySW = process.StandardInput;
mySW.WriteLine ("cd /d C:\\Users\\user");
mySW.WriteLine ("adb tcpip 5555");/////////////
mySW.WriteLine ("adb connect 10.0.0.11");/////////////////
}
IEnumerator timer(){
yield return new WaitForSeconds (3f);
connect ();
}
public void connect(){
mySW.WriteLine ("adb connect 10.0.0.3");
}
// Update is called once per frame
void Update () {
if (GamePad.GetState (PlayerIndex.One).DPad.Left == ButtonState.Pressed) {
if(!left){
left = true;
mySW.WriteLine ("adb shell input keyevent 21");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).Buttons.X == ButtonState.Pressed) {
if (!right) {
xbtn = true;
mySW.WriteLine ("adb shell input keyevent 188");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Right == ButtonState.Pressed) {
if (!right) {
right = true;
mySW.WriteLine ("adb shell input keyevent 22");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Up == ButtonState.Pressed) {
if (!up) {
up = true;
mySW.WriteLine ("adb shell input keyevent 19");
mySW.Flush ();
}
// UnityEngine.Debug.Log (mySR.ReadLine());
}
if (GamePad.GetState (PlayerIndex.One).DPad.Down == ButtonState.Pressed) {
if (!down) {
down = true;
mySW.WriteLine ("adb shell input keyevent 20");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).Buttons.Start == ButtonState.Pressed) {
if (!start) {
start = true;
mySW.WriteLine ("control");
mySW.Flush ();
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Down == ButtonState.Released) {
if (down) {
down = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Up == ButtonState.Released) {
if (up) {
up = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Right == ButtonState.Released) {
if (right) {
right = false;
}
}
if (GamePad.GetState (PlayerIndex.One).DPad.Left == ButtonState.Released) {
if (left) {
left = false;
}
}
if (GamePad.GetState (PlayerIndex.One).Buttons.Start == ButtonState.Released) {
if (start) {
start = false;
}
}
}
}
Using this code i'm able to move around in nonVR apps and system menus using the gamepad just fine but for some reason none of the keyEvents work inside the gearVr, with the only exception I've found so far being keyevent 3 which simulates the Back button.
I know this code is pretty horrible and i'll try to rewrite it properly once i get the basics working but for now i'm pretty stuck. Anyone has an idea on how to solve this? This could be a pretty useful solution for people with gearVR who don't want to replace their current gamepad with an overpriced, less comfortable one.