# Swift macOS MouseMove

**URL:** <https://ifnotnil.com/t/swift-macos-mousemove/4149>\
**Category:** Swift\
**Created:** [19 October 2024 22:37 UTC](https://ifnotnil.com/t/swift-macos-mousemove/4149 "2024-10-19T22:37:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [19 October 2024 22:37 UTC](https://ifnotnil.com/t/swift-macos-mousemove/4149/1 "2024-10-19T22:37:51Z")

</div>

I have a Swift project with a NSWindow with an NSVIew in the center  
each has a MouseMove event connect to it

However the event SHOULD fire for which ever object the mouse is over (View or Window) but doesn’t, unless the object is CLICK on first. So for MouseDrag this is ok, since you have to click for that event anyways, but not mouseMove.

Any ideas?

---

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [20 October 2024 17:10 UTC](https://ifnotnil.com/t/swift-macos-mousemove/4149/2 "2024-10-20T17:10:55Z")

</div>

did finally fix it… but went thru so many “Hail Mary” attempts I’m not sure what actually did the trick.

I did have to add “acceptsMouseMoves” to the MouseEnter/Exit of NSView amongs a few other tweaks.

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [21 October 2024 05:01 UTC](https://ifnotnil.com/t/swift-macos-mousemove/4149/3 "2024-10-21T05:01:38Z")

</div>

> [@DaveS](#):
>
> I did have to add “acceptsMouseMoves” to the MouseEnter/Exit of NSView amongs a few other tweaks.

That sounds about right. It’s funny coming from Xojo as they do quite a bit of setting up for you. It’s just a shame that can’t be smarter about it.

---

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [22 October 2024 16:11 UTC](https://ifnotnil.com/t/swift-macos-mousemove/4149/4 "2024-10-22T16:11:08Z")

</div>

well that kind of works…

NSView on NSWINDOW, I can limit mousemove to the view if the mouse is inside it

but go to next level

NSBUTTON → NSVIEW → NSWINDOW a mouse move on the Button appears on BOTH button and View

expanding on MouseEnter/Exit means I may have to manaage an entire heiarchy of contols which seems AppKit should already do
