What do you need help with?

Controlling Input Mode programmatically in Unity Applications

Follow

ReticleOS supports 2 screen input modes. They are described on page 10 of R-7 User Guide.

We created a sample project that can switch between 2 input modes - selector or cursor - by pressing the multi-function key on the temple (page 9 of user guide).  This example shows how to intercept that button and programmatically change input mode states.

It also starts the activity in Mouse mode; The developer must add:

   <meta-data
       android:name="com.osterhoutgroup.input_mode"
       android:value="Mouse" />

 <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
 <meta-data android:name="unityplayer.UnityActivity" android:value="true" />

to the activity tag in AndroidManifest.

There is entire Unity project attached to this article.

Please review it to see how it handles events, and note that some projects, or plugins, override the AndroidManifest. The developer must look at what plugins are being used. For example if you are using Vuforia, you have to look for the Vuforia Android Manifest and modify that instead.

Some other plugins override the default manifest provided by Unity. It is up to the developer that uses the plugin to read the docs of what the plugins do; they have to make sure they are modifying the correct manifest. Unity never strips out anything in the AndroidManifest, so it must be something else. Some plugins however require modifications to the Manifest to run, so they provide their own manifest.

We have always had theReticleOS feature of the two input modes. We added it because we don't have a touch screen, and felt that having only cursor (mouse) mode was not acceptable; selecting objects via swiping is much superior/easier. But, many UIs are not designed that way, and only support touch. We've used the manifest method for allowing the developer to decide. This is pretty standard. And, the multi-function button should toggle between modes, as long as the App is not eating all the button events.

One final note; If input event collection is in dpad mode, unity will not get swipes, it will be a dpad event like a up/down/left/right digital button. You will have to override the Java class to propagate the trackball events from android to Unity so the App will get a swipe without the cursor. Unity documentation shows how to create interfaces between Android to unity.

BTW, note Unity's Input.mousePresent property--doesn't directly answer the question what mode the device is in. For example, if there's an external Bluetooth mouse attached to the system, then you will get a different result. You should use the odghardware.getTrackpadMode().

If you are using Vuforia and creating the key logging app with Vuforia installed, then you have to override the Vuforia Activity instead of UnityPlayerNativeActivity. If you have issues, you should try again by creating a clean Unity Android project without Vuforia. Or follow the guide to override Vuforia and print out the keys without sending it to Unity:

https://developer.vuforia.com/library/articles/Solution/How-To-Extend-the-Unity-Android-Activity

Have more questions? Submit a request

Comments

Powered by Zendesk