Android:以编程方式检测设备是否已连接硬件触摸屏 [英] Android: Programmatically detect if device has hardware touchscreen connected

查看:120
本文介绍了Android:以编程方式检测设备是否已连接硬件触摸屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本来检测引导时物理触摸屏是否已连接到我的Android设备.我试图通过adb列出文件夹/dev/input 的内容,并获得以下输出:

I need to write a script to detect if the physical touchscreen is connected to my Android device at boot time. I tried to list the content of the folder /dev/input via adb and I obtain the following output:

root@q88:/dev/input # ls
event0
event1
event2
event3
event4
mice

如果我没记错的话, event0 可以识别触摸屏,但是无论是否连接触摸屏,都可以看到它.
有没有办法检测触摸屏是否已连接到设备?

If I am not mistaken, event0 identifies the touchscreen, but it is visible in both case the touchscreen is connected or not.
Is there a way to detect if the touchscreen is connected to the device?

谢谢.

推荐答案

您可以将/proc/bus/bus/input/devices 读取到根据您的硬件名称,您可以执行类似的操作并检查是否有任何输出:

Depending on your hardware's name, you could do something like that and check if there is any output:

cat /proc/bus/input/devices | grep "Name=" | grep "Touch"

这是/proc/bus/bus/input/devices 的完整输出:

I: Bus=0011 Vendor=0002 Product=0008 Version=2222
N: Name="AlpsPS/2 ALPS DualPoint TouchPad"
P: Phys=isa0060/serio1/input0
S: Sysfs=/class/input/input2
H: Handlers=mouse1 event2 ts1
B: EV=f
B: KEY=420 0 70000 0 0 0 0 0 0 0 0
B: REL=3
B: ABS=1000003

[...] (blank line, next device)

前面的B代表位图,N,P,S,U,H只是第一个字母对应的名称值,而我代表ID.在有序时尚:

The B in front stands for bitmap, N, P, S, U, H are simply first letter in corresponding name value and I is for ID. In ordered fashion:

  • I →@id:设备的ID(结构input_id)
    • 公共汽车→id.bustype
    • 供应商→id.vendor
    • 产品→id.product
    • 版本→id.version
    • I → @id: id of the device (struct input_id)
      • Bus → id.bustype
      • Vendor → id.vendor
      • Product → id.product
      • Version → id.version
      • PROP →设备属性和怪癖
      • EV →设备支持的事件类型
      • KEY →该设备具有的键/按钮
      • MSC →设备支持的其他事件
      • LED →设备上的leds
      • REL →相对地址
      • ABS →绝对地址
      • PROP → device properties and quirks
      • EV → types of events supported by the device
      • KEY → keys/buttons this device has
      • MSC → miscellaneous events supported by the device
      • LED → leds present on the device
      • REL → relative address
      • ABS → absolute address

      要测试设备是否已实际连接,您可以尝试模拟事件并查看是否出现任何错误:

      input tap [x] [y]
      

      Android附带了一个输入命令行工具,可以模拟其他输入事件.

      Android comes with an input command-line tool that can simulate miscellaneous input events.

      • 输入→用于发送事件的命令行工具
        • 点击→动作
        • [x]→屏幕上的X坐标
        • [y]→屏幕上的Y坐标
        • input → The command line tool to send events
          • tap → the action
          • [x] → X coordinate on the screen
          • [y] → Y coordinate on the screen

          这篇关于Android:以编程方式检测设备是否已连接硬件触摸屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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