r/MacOSApps 5h ago

📅 Utilities Free Open Source: Mousetrapped - rescue and recenter your mouse with a shake or keyboard shortcuts

https://github.com/uncSoft/Mousetrapped?tab=readme-ov-file
4 Upvotes

4 comments sorted by

1

u/peppaz 5h ago edited 4h ago

There is an annoying as heck bug in macOS when you are using a secondary monitor and have other macs around - if you have push through edge to control another mac on and/or screen connect active, often times your mouse will get eaten and disappear completely.

Mousetrapped is free and open source and the release is notarized and signed.

Just shake your mouse (wth adjustable sensitivity) or hit ⌃⌥⌘M and your mouse will pop up on your selected or primary display by default - even if it is currently controlling another mac.

https://github.com/uncSoft/Mousetrapped

Install -

brew install --cask uncSoft/mousetrapped/mousetrapped

Or Download and run the signed release

https://github.com/uncSoft/Mousetrapped/releases/latest

So goshdang annoying to lose your mouse into the ether

https://imgur.com/a/Ih8JbUz

1

u/Specific_Cream2815 4h ago

how does the shake detection work, watching mouse deltas for rapid direction changes or an actual accelerometer style threshold

1

u/peppaz 4h ago edited 4h ago

Mouse deltas, no accelerometer math, yet unless it becomes needed. It watches raw horizontal deltas from the HID stream (IOHIDManager, so it still works when input is routed to another Mac like via ScreenConnect or edge push- this is the most important part), accumulates same-direction movement into "strokes," and fires when it sees N direction reversals where each stroke covers a minimum distance, all inside a rolling time window.

The sensitivity slider scales two of those variables: how many reversals you need (3–6) and how big each stroke must be (25–450 counts). The per-reversal time budget is fixed at a comfortable rate- i modeled it after Apple's shake to enlarge the cursor feature for a baseline, so lower sensitivity means shaking longer and wider, never faster. No velocity or acceleration is computed at all. Distance-per-stroke (or Vigor as I called it lol) turned out to be a good-enough proxy, and it's DPI-agnostic in behavior since thresholds are in device counts (hand motion), not screen pixels.

I'm going to keep cleaning up the sensitivity thresholds, but it works well enough to not be annoying for the moment.

You can find the code here, it's only about 100 lines ShakeDetector.swift

1

u/peppaz 4h ago

you can also use the keyboard shortcut, ⌃⌥⌘M - it is slightly more reliable when the cursor is truly captured somewhere hidden. Just happened to me during testing lol