Proper Android usb (ICS) mouse button behavior

Correct click of the USB mouse connected to the android (ics) is always indicated as a back button? I have one tablet where it is not.

I want to delete the status bar and still use the tablet with a USB mouse.

Does anyone know where / how to configure behavior in Android?

+6
source share
1 answer

The late answer, but the answer is yes. I will tell you more about this topic, since this topic is only on the Internet of this type.

Default behavior: Android treats this as a back button, with no visible exceptions.

This is a pretty nice feature for phones and regular apps. However, two types of people would like this function to be performed differently. Modders and application developers.

Modders fix: On the root device (and maybe not loaded for several weak devices with unlocked adb), pay attention to Generic.kl under /system/usr/keylayout . Find the KEY_BACK flag, there may be several key codes on several lines associated with it. For me, it was key 158 with the WAKE_DROPPED flag. For the general right-click function, you will want to change the numeric codes for the back key and menu key, so when the mouse sends a back-key command, the system will actually start the menu command, saving some hardware key (indicated by the menu key) on the device to return. Yes, this will change the hardware keys on your phone, but this is the easiest solution without rebuilding the entire ROM. If this is for a corporate or professional reason, perhaps check out this article: Overriding the cell level of event cells . I would recommend creating an Xposed module that overrides the procedure they refer to. Otherwise, see how to reassign key codes, it is a pity that I could not find a direct article here.

App developers fix: Non-root: Cancel the return key in the application and return true. In your onBackPressed() override, execute any right-click function. Simply! Since you most likely want the context menu functionality on the PC, you will also need to track where the mouse is with the MotionEvent listener applied to the root view, with calls to event.getRawX() and RawY () storing the values ​​for the global variable . Then you can put your context menu (ListView or VerticalLinearLayout size) under the cursor, setting the top and left margins and making it visible. If you want to perform a secondary function on a hovering object in your layout, by right-clicking, for example, delete or copy, you will have to manually determine on which object the stored mouse coordinates are stored. You will probably have to add MotionEvent.ACTION_HOVER_ENTER listeners to each affected object and store the object identifier in a global variable that will be used when the onBackPressed () function is called. (I will give the code when I have time!)

Hope this helps anyone exploring such a specific topic! :)

+9
source

Source: https://habr.com/ru/post/912578/


All Articles