Skip to content

feat: Add mouse gesture feature#974

Open
xtxo wants to merge 1 commit into
Caldis:masterfrom
xtxo:feature/mouse-gesture
Open

feat: Add mouse gesture feature#974
xtxo wants to merge 1 commit into
Caldis:masterfrom
xtxo:feature/mouse-gesture

Conversation

@xtxo

@xtxo xtxo commented Jun 12, 2026

Copy link
Copy Markdown

Summary

This PR adds a mouse gesture feature to Mos, allowing users to trigger keyboard shortcuts by holding the right mouse button and moving in specific directions.

Motivation / Why This Feature

使用场景

很多用户习惯用鼠标右键长按来触发 ESC 键(比如关闭弹窗、退出全屏、取消操作等)。但现有的 Mos 功能只能绑定单个按键,无法实现"按住右键 + 移动方向"这种更直观的手势操作。

痛点

  1. 长按右键触发 ESC 需要一直按着,手指容易疲劳
  2. 无法同时触发多个快捷键(比如 ESC 和刷新)
  3. 没有方向感,操作不够直觉

解决方案
通过鼠标手势,用户可以:

  • 按住右键 → 向左上方移动 → 触发 ESC(退出/取消)
  • 按住右键 → 向上移动 → 触发 Cmd+R(刷新页面)

这样更符合直觉,也更高效。未来可以扩展更多方向和功能。

Changes

  • New file: Mos/ButtonCore/MouseGestureTracker.swift - Core gesture tracking logic
  • Modified: Mos/ButtonCore/ButtonCore.swift - Integration with existing event tap system

Feature Details

How it works

  1. Hold the right mouse button
  2. Move the mouse in a direction (minimum 30px distance)
  3. Release the right button

Default gestures

Direction Action Use Case
Up-Left (↖) ESC key 关闭弹窗、退出全屏、取消操作
Up (↑) Cmd+R 刷新页面、重新加载

Technical implementation

  • Uses CGEventTap to monitor mouse movement while right button is held
  • Calculates direction based on movement angle
  • Supports 8 directions (up, down, left, right, and 4 diagonals)
  • Minimum distance threshold prevents accidental triggers
  • Integrates with existing ButtonCore and InputProcessor architecture

Testing

  • Verified gesture tracking starts on right mouse down
  • Verified gesture tracking stops on right mouse up
  • Verified ESC key is triggered for up-left direction
  • Verified Cmd+R is triggered for up direction
  • Verified minimum distance threshold works correctly

Notes

This is a basic implementation. Future enhancements could include:

  • User-configurable gesture directions and actions
  • More gesture directions (down, left, right, diagonals)
  • Visual feedback during gesture recognition
  • Gesture recording UI
  • Support for other mouse buttons (middle, back, forward)

…er keyboard shortcuts

- Add MouseGestureTracker to track mouse movement while holding right button
- Support 8 directions (up, down, left, right, and 4 diagonals)
- Default gestures:
  - Up-Left: ESC key
  - Up: Cmd+R (Refresh)
- Minimum distance threshold (30px) to prevent accidental triggers
- Integrates with existing ButtonCore event tap system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant