在处理Android的所有鼠标事件 [英] Handle all mouse events in Android

查看:616
本文介绍了在处理Android的所有鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,这个问题很简单 - (!),怎么能我处理左/右/中键单击,滚轮和悬停移动机器人2/3/4

Well, the question is rather simple - how can i handle left/right/middle click, wheel and (!)hover move in android 2/3/4.

我一直在挖这个话题,发现如下

I've been digging on this topic and found the following

  • 在14 API,我们可以处理几乎与花哨的新MotionEvent
  • 什么
  • 我们也必须打开附件,这似乎是确定与自API 12(人仍下落不明蓝牙),USB鼠标(UPD OA回迁到2.3.4)
  • 在鼠标的实际工作以及与ICS和蜂窝氰2.3.7平板电脑,但像每button.I难怪只是单点触摸,有没有办法拦截鼠标消息。

请帮助我了解如何我可以处理蓝牙和USB鼠标最简单,最正确的方式在每个版本的Andr​​oid。或者说,它是不可能的。

Help me please to understand how i can handle bluetooth and usb mouse in most simple and right way in each version of android. Or say its impossible.

UPD2:好像USB主机仅在3.1以上版本,而USB配件没用这个任务

UPD2: seems like USB Host only in 3.1+, while USB Accessory useless for this task

推荐答案

这些是我的发现:

有关API级< 9:

For Api Level < 9:

  • 在外接鼠标主要按钮的处理只是作为一个正常的手指触摸。似乎有没有办法检测鼠标。
  • 辅助按钮被分派槽一个的KeyEvent KeyEvent.KEY code_BACK 。没办法,实际的后退presses和辅助按钮presses区分。
  • External mouse primary button is handled just as a normal finger touch. There seems to be no way to detect the mouse.
  • Secondary button is dispatched trough a KeyEvent with KeyEvent.KEYCODE_BACK. No way to distinguish between actual "Back" presses and secondary button presses.

有关API级别9 +:

For Api Level 9+:

  • 的新方法已经被添加 MotionEvent.getSource()。我用这个来检测,如果输入的是鼠标。
  • 辅助按钮仍然通过的KeyEvent 派与 KeyEvent.KEY code_BACK 。在某些设备上的 KeyEvent.getSource()返回 InputDevice.SOURCE_MOUSE ,所以辅助按钮检测工作在某些情况下。
  • A new method has been added MotionEvent.getSource(). I use this one to detect if input is from mouse.
  • Secondary button is still dispatched through a KeyEvent with KeyEvent.KEYCODE_BACK. On some devices the KeyEvent.getSource() returns InputDevice.SOURCE_MOUSE, so secondary button detection works in some cases.

有关API级别12 +:

For Api Level 12+:

  • OnGenericMotionListener <$ C C $>已被添加。我用这个来检测鼠标的移动与 ACTION_HOVER_MOVE ACTION_SCROLL 轮变化。
  • OnGenericMotionListener has been added. I use this one to detect mouse moves with ACTION_HOVER_MOVE and wheel changes with ACTION_SCROLL.

有关API级别14 +:

For Api Level 14+:

  • 新方法 MotionEvent.getButtonState()。我跟踪这个来区分,如果一级,二级,三级鼠标按键时pressed当 MotionEvent.getActionMasked() ACTION_MOVE ACTION_DOWN ACTION_UP
  • New method MotionEvent.getButtonState(). I track this one to distinguish if a primary, secondary, tertiary mouse button is pressed when the MotionEvent.getActionMasked() is ACTION_MOVE, ACTION_DOWN or ACTION_UP.

我还没有研究过API级别15/16或刀具类型,因为我能够用我上面描述什么跟踪所有鼠标事件。如果任何人有更多的信息将是有趣的,或者如果我错过了15/16 / tooltypes。

I haven't looked into Api Level 15/16 or the tool type, because I'm able to track all mouse events with what I described above. Would be interesting if anybody has additional information or if I' missing out with 15/16/tooltypes.

这篇关于在处理Android的所有鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆