What do you need help with?

Controlling Input Mode programmatically in Unity Applications

Follow

[This article is a legacy article, left here for reference. Please see this article for details on a Unity plugin needed for handling input events and controlling input mode in Unity versions 2017 and later].

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

There are two modes of the Track Pad input. To switch modes, either press the multi-function button to toggle modes (See Main Controls, User's Guide, Page 8-9). If the multi-function button has been re-assigned press Menu once to display the System Menu, then select Input Mode.

Selector Mode:

Swiping the Track Pad up, down, left, or right functions in the same manner as standard 4-way arrow keys on a keyboard, allowing the user to select items, navigate through the interface, or scroll.

Cursor Mode:

Swiping the Track Pad allows free movement of the cursor in any direction in the same manner as a computer mouse.

 

We created a sample Unity project that can switch between these 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="true" />
 <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 if you find unexpected behavior, it must be one of your other plugins. Some plugins however require modifications to the Manifest to run, so they provide their own manifest.

You may need to review Unity's documentation on how to call native Java code from C# to get this to work.  See this reference: https://docs.unity3d.com/Manual/PluginsForAndroid.html

As long as input mode is checked that when going to background and coming back to app the status has to be checked and changed again to true (Other ways it will fail).

Background:

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://library.vuforia.com/articles/Solution/Extending-Unity-Activity-in-Android-Studio

Have more questions? Submit a request

Comments

Powered by Zendesk