gpt4 book ai didi

Android:以编程方式检测设备是否连接了硬件触摸屏

转载 作者:IT老高 更新时间:2023-10-28 23:07:08 27 4
gpt4 key购买 nike

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

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

如果我没记错的话,event0 标识了触摸屏,但无论是否连接触摸屏,它都是可见的。
有没有办法检测触摸屏是否连接到设备?

提前致谢。

最佳答案

您可以阅读 /proc/bus/input/devicesget details of your existing input devices .

根据您的硬件名称,您可以执行类似操作并检查是否有任何输出:

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

这是/proc/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)

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 of the device (struct input_id)
    • Bus → id.bustype
    • Vendor → id.vendor
    • Product → id.product
    • Version → id.version
  • N → name of the device
  • P → physical path to the device in the system hierarchy
  • S → sysfs path
  • U → unique identification code for the device (if device has it)
  • H → list of input handles associated with the device
  • B → bitmaps
    • 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 comes with an input command-line tool that can simulate miscellaneous input events.

  • input → The command line tool to send events
    • tap → the action
    • [x] → X coordinate on the screen
    • [y] → Y coordinate on the screen

关于Android:以编程方式检测设备是否连接了硬件触摸屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39232709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com