Android USB 鼠标右键单击正确的行为 (ICS)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10041295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:17:24  来源:igfitidea点击:

Android usb mouse right click correct behaviour (ICS)

androidclickusbmouse

提问by Krzysztof Stankiewicz

Is right click of a USB mouse plugged into android (ics) always designated as the 'back' button? I have one tablet where it isn't.

插入 android (ics) 的 USB 鼠标右键单击是否始终指定为“后退”按钮?我有一台平板电脑,但没有。

I want to remove the status bar, and still be able to use the tablet with USB mouse.

我想删除状态栏,并且仍然可以使用带有 USB 鼠标的平板电脑。

Does anyone know where/how to configure the behavior in android?

有谁知道在哪里/如何在android中配置行为?

回答by Aaron Gillion

Late answer, but the answer is yes. I am going to provide some more detail on this topic as it is the onlytopic on the Internet of this type.

迟到的答案,但答案是肯定的。我将提供有关此主题的更多详细信息,因为它是Internet 上唯一的此类主题。

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

默认行为:Android 将此视为后退按钮,没有可见的异常。

This is a pretty nice feature for phonesand normal apps. However, two types of people would like this feature to be implemented differently. Modders, and app developers.

对于手机和普通应用程序来说,这是一个非常不错的功能。但是,有两种类型的人希望以不同的方式实现此功能。Modders 和应用程序开发人员。

Modders' Fix:On a rooted device (and potentially unrooted for quite a few underdog devices with unlocked adb), observe Generic.klunder /system/usr/keylayout. Search for the flag KEY_BACK, there may be multiple keycodes on multiple lines linked to it. For me it was key 158with the WAKE_DROPPEDflag. For a generic "right-click" function you'll want to swap the number codes for the back key and the menu key, so when the mouse sends a back-key command the system will actually fire a menu key command, while maintaining some hardware key (labeled menu key) on the device for going back. Yes, this will reverse the hardware keys on your phone, but it is the easiest solution, without rebuilding the entire ROM. If this is for a corporate or professional cause, maybe see this article: Overriding Mouse Events Kernel-Level. I would actually recommend creating an Xposed module that overrides the procedure they referenced. Otherwise, look up how to remap keycodes, sorry I could not find a straight-forward article here.

Modders 的修复:在有根设备上(对于很多具有解锁 adb 的失败设备可能没有根),Generic.kl/system/usr/keylayout. 搜索 flag KEY_BACK,链接到它的多行上可能有多个键码。对我来说,这key 158WAKE_DROPPED国旗有关。对于通用的“右键单击”功能,您需要交换后退键和菜单键的数字代码,因此当鼠标发送后退键命令时,系统实际上会触发菜单键命令,同时保持一些设备上用于返回的硬件键(标记为菜单键)。是的,这将反转您手机上的硬件密钥,但这是最简单的解决方案,无需重建整个 ROM。如果这是出于公司或专业原因,请参阅这篇文章:覆盖鼠标事件内核级。我实际上建议创建一个 Xposed 模块来覆盖他们引用的过程。否则,请查看如何重新映射键码,抱歉我在这里找不到直接的文章。

App-developers' Fix: Non-root:Override back key in your application and return true. In your onBackPressed()override, perform any right-click function necessary. Simple! Since you're most likely wanting a PC-like context menu functionality, you'll also need to track where the mouse is at, via a MotionEvent listener applied to the root view with an event.getRawX()and RawY() calls storing values to a global variable. You can then place your context menu (sized ListView or VerticalLinearLayout) under the cursor by setting top and left margins and set it visible. If you want to perform a secondary function on a hovered object in your layout via right-click, such as delete or copy, you will have to manually figure out what object the stored mouse coordinates are hovering over. You'll probably have to add MotionEvent.ACTION_HOVER_ENTERlisteners on every affected object and store the object ID in a global variable for use when the onBackPressed() function is called. (I will provide code when I have time!)

应用程序开发人员的修复:非 root:覆盖应用程序中的返回键并返回 true。在您的onBackPressed()覆盖中,执行任何必要的右键单击功能。简单的!由于您很可能需要类似 PC 的上下文菜单功能,因此您还需要通过应用到根视图的event.getRawX()MotionEvent侦听器和 RawY() 调用将值存储到全局变量来跟踪鼠标所在的位置. 然后,您可以通过设置顶部和左边距并将其设置为可见,将上下文菜单(大小为 ListView 或 VerticalLinearLayout)置于光标下方。如果您想通过右键单击对布局中悬停的对象执行辅助功能,例如删除或复制,则必须手动确定存储的鼠标坐标悬停在哪个对象上。你可能需要添加MotionEvent.ACTION_HOVER_ENTER每个受影响对象上的侦听器,并将对象 ID 存储在全局变量中,以便在调用 onBackPressed() 函数时使用。(有时间我会提供代码!)

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

希望这可以帮助任何人探索这样一个特定的主题!:)