Skip to content

Mouse_README

SweerItTer edited this page Feb 21, 2026 · 5 revisions

Mouse 模块 API 文档

概述

Mouse 模块提供 Linux 输入设备的鼠标事件监控功能,支持鼠标移动、点击和滚轮事件。

模块组成

核心类

文档 说明
MouseWatcher MouseWatcher 鼠标事件监控器

功能特性

鼠标事件监控

  • 鼠标移动事件
  • 鼠标按键事件(左键、中键、右键)
  • 鼠标滚轮事件
  • 事件坐标和状态

回调机制

  • 事件回调函数
  • 实时事件通知
  • 事件过滤

使用示例

基本监控

MouseWatcher watcher;

// 注册鼠标移动事件回调
watcher.registerHandler(
    {MouseEventType::AxisX, MouseEventType::AxisY},
    [](MouseEventType type, uint8_t value) {
        if (type == MouseEventType::AxisX) {
            printf("Mouse X movement: %d\n", static_cast<int8_t>(value));
        } else if (type == MouseEventType::AxisY) {
            printf("Mouse Y movement: %d\n", static_cast<int8_t>(value));
        }
    }
);

watcher.start();

鼠标点击

MouseWatcher watcher;

// 注册鼠标按键事件回调
watcher.registerHandler(
    {MouseEventType::ButtonLeft, MouseEventType::ButtonRight},
    [](MouseEventType type, uint8_t value) {
        if (type == MouseEventType::ButtonLeft) {
            printf("Left button: %s\n", value ? "pressed" : "released");
        } else if (type == MouseEventType::ButtonRight) {
            printf("Right button: %s\n", value ? "pressed" : "released");
        }
    }
);

watcher.start();

滚轮事件

MouseWatcher watcher;

// 注册滚轮事件回调
watcher.registerHandler(
    {MouseEventType::WheelVertical},
    [](MouseEventType type, uint8_t value) {
        printf("Wheel scroll: %d\n", static_cast<int8_t>(value));
    }
);

watcher.start();

数据流

输入设备 → MouseWatcher → 回调 → 上层处理

线程安全

  • MouseWatcher 内部使用独立监控线程
  • 回调函数在监控线程中调用
  • 使用队列传递事件到其他线程

性能优化

  • 使用事件队列减少回调阻塞
  • 过滤不需要的事件
  • 批量处理事件

错误处理

  • 检查设备打开是否成功
  • 处理设备权限错误
  • 记录错误日志

相关模块

参考资料

注意事项

  1. 设备权限: 确保有访问输入设备的权限
  2. 设备路径: 确保输入设备路径正确
  3. 回调阻塞: 不要在回调中执行耗时操作
  4. 线程安全: 回调函数应该是线程安全的
  5. 资源清理: 使用完毕后调用 stop() 清理资源

版本历史

  • v1.0 - 初始版本,支持基本鼠标事件监控

主页

API 文档

DMA 模块

DRM 模块

NET 模块

V4L2 模块

V4L2Param 模块

RGA 模块

MPP 模块

Sys 模块

Mouse 模块

Utils 模块

Clone this wiki locally