What do you need help with?

Intercepting Menu, Back, Multi-Function Buttons, and Controlling input mode

Follow

An App can intercept the Menu, Back and/or the Multi-Function Spare button, which by default toggles the input mode between selector and cursor modes.  Here is some additional detail on this topic:

Note that the key code for theMulti-Function spare button is 500.  If an App wants to ignore that and block changes to the input mode, one can intercept that onKeyDown and return false to not handle it then put in logic to get the trackpad mode based on the below details:

 

In the manifest of your application add:

<uses-library android:name="com.osterhoutgroup.api.ext" android:required="false" />

 

If you want the application to default as mouse you can add the following meta tag in the application tag in the manifest:

<meta-data

          android:name="com.osterhoutgroup.input_mode"

          android:value="Mouse" />

 

Attached is a jar file that includes the OdgHardwareExt functions, and a sample App, both zips.

 

In the sample application's DroidzActivity.java file you can change the input modes in code using the following example:

  public void buttonSwapInput(View v) {

      OdgHardwareExt odghardware = new OdgHardwareExt(this);

      int input = odghardware.getTrackpadMode();

      if (input == InputDevice.SOURCE_TRACKBALL) {

          odghardware.setTrackpadMode(InputDevice.SOURCE_MOUSE);

      } else {

          odghardware.setTrackpadMode(InputDevice.SOURCE_TRACKBALL);

      }

  }

 

 

A long back button is turned into a home event.  

The App can NOT intercept it the same way as back button by looking for this : KeyEvent.KEYCODE_HOME

unless the App designates itself as a Launcher type Application.

There are  4 buttons on the RSM speed mouse can also be intercepted by the App and remapped to other functions.

 

 

Here's some very simple Android source. You just need to create a regular android project and add the following

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   Log.v("KeyTest", "onKeyDown KEY code " + keyCode);

   if (keyCode == KeyEvent.KEYCODE_BACK) {
       Log.v("KeyTest", "KEY_BACK down pressed!");
       return true;

   } else if (keyCode == KeyEvent.KEYCODE_MENU) {
       Log.v("KeyTest", "KEY_MENU down pressed");
       return true;

   } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
       Log.v("KeyTest", "KEY_ENTER down pressed");
       return true;

   } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
       Log.v("KeyTest", "CENTER down pressed");
       return true;
   }

   return super.onKeyDown(keyCode, event);
}

 

to log these various keys.

 

You will need to update to release 3.4.5 to detect the spare button (right temple in the back), but the others you should be able to detect.

Have more questions? Submit a request

Comments

Powered by Zendesk