当前位置: 首页 > news >正文

Android 使用python统计getevent按键

1、连接ADB
2、开启脚本

作用:
统计时间内相应的event数量

python代码:

import subprocess
import redef parse_getevent_output():# 启动getevent进程getevent_process = subprocess.Popen(['adb', 'shell', 'getevent', '-t', '-l'], stdout=subprocess.PIPE,stderr=subprocess.PIPE, text=True)event_count = 0  # 事件计数器start_time = 0  # 记录开始时间last_timestamp = 0  # 用于存储上一个事件的时间戳targetnum = 110try:while True:line = getevent_process.stdout.readline()if not line:break  # 如果没有输出了,跳出循环# 使用正则表达式匹配事件的时间戳、类型、代码和值match = re.match( r'\[(\d+\.\d+)\] (\S+): (\w+) +(\w+) +([0-9A-Fa-f]+)', re.sub(r'\[\s+', '[', line).strip())if match:timestamp = match.group(1)device_path = match.group(2)event_type = match.group(3)event_code = match.group(4)event_value = match.group(5)# print(f"Timestamp: {timestamp}")# print(f"Device Path: {device_path}")# print(f"Event Type: {event_type}")# print(f"Event Code: {event_code}")# print(f"Event Value: {event_value}")if start_time == 0 :start_time = float(timestamp)# 检查是否已经过了一秒钟if float(timestamp) - start_time >= 1.0:# 打印一秒钟内的事件数量print(f"your printl data")event_count = 0  # 重置事件计数器start_time = float(timestamp)  # 重置开始时间if event_code == "SYN_REPORT" :event_count += 1  # 增加事件计数# else:#     print(f"{line.strip()}")except KeyboardInterrupt:print("\nScript terminated by user.")  # 用户中断脚本finally:getevent_process.terminate()  # 确保进程被终止print("Getevent process terminated.")if __name__ == "__main__":parse_getevent_output()
http://www.lryc.cn/news/484182.html

相关文章:

  • NVIDIA jetson查看资源占用情况,打印/保存资源使用情况日志
  • ssm102“魅力”繁峙宣传网站的设计与实现+vue(论文+源码)_kaic
  • 逐行加载 HTML 内容并实时显示效果:使用 wxPython 的实现
  • UE4 Cook 从UAT传递参数给UE4Editor
  • 【学习日记】notebook添加JAVA支持
  • 以太坊系地址衍生算法分层确定性生成逻辑
  • 【Unity】ScriptableObject的应用:利用配方合成新物体
  • 31DNS设置
  • 使用Docker快速部署FastAPI Web应用
  • 全面掌握Spring Boot异常处理:策略与实践
  • 【LeetCode】【算法】11. 盛最多水的容器
  • ES6代理和反射新特性,详细讲解
  • vue计算属性 初步使用案例
  • 大模型时代,呼叫中心部门如何建设一套呼出机器人系统?
  • 使用Java绘制图片边框,解决微信小程序map组件中marker与label层级关系问题,label增加外边框后显示不能置与marker上面
  • 力扣 LeetCode 142. 环形链表II(Day2:链表)
  • 用MVVM设计模式提升WPF开发体验:分层架构与绑定实例解析
  • C++中的动态断言和静态断言
  • 运算放大器的学习(一)输入阻抗
  • Rust枚举之卧龙凤雏(Rust Option枚举、Rust Result枚举)(Rust Enum、Some(T)、Ok(T)、Err(E))链式操作
  • TCP/IP协议,TCP和UDP区别
  • 【go从零单排】Timer、Epoch 时间函数
  • 壁仞科技上市前最后一波 校招 社招 内推
  • 【微软报告:多模态基础模型】(2)视觉理解
  • Linux 驱动
  • 【数学二】线性代数-线性方程组-齐次线性方程组、非齐次线性方程组
  • Git别名设置
  • 算法基础 -- 红黑树原理与插入伪代码
  • 力扣 LeetCode 27. 移除元素(Day1:数组)
  • 微服务链路追踪skywalking安装