# Getting event when mouse moves outside window?

**URL:** <https://discourse.libsdl.org/t/getting-event-when-mouse-moves-outside-window/17692>\
**Category:** SDL Development\
**Created:** [October 19, 2010, 4:44am UTC](https://discourse.libsdl.org/t/getting-event-when-mouse-moves-outside-window/17692 "2010-10-19T04:44:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VernJensen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@VernJensen](https://discourse.libsdl.org/u/VernJensen)\
**Post date:** [October 19, 2010, 4:44am UTC](https://discourse.libsdl.org/t/getting-event-when-mouse-moves-outside-window/17692/1 "2010-10-19T04:44:01Z")

</div>

I’d like to have the cursor be hidden when it’s moved inside the window’s bounds, and reappear when its is moved outside. (Similar to the old Mac function ShieldCursor() )

However, it seems I only get mouse-moved events while the cursor is moved _within_ the window’s bounds, so there is no way of knowing when it has moved outside the window. Is this the case, or am I missing something?

This is for SDL 1.3.

---

<div class="post-metadata">

**Author:** ![VernJensen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/v/58956e/32.png) [@VernJensen](https://discourse.libsdl.org/u/VernJensen)\
**Post date:** [October 22, 2010, 12:37am UTC](https://discourse.libsdl.org/t/getting-event-when-mouse-moves-outside-window/17692/2 "2010-10-22T00:37:29Z")

</div>

Okay, so I discovered: SDL\_WINDOWEVENT\_ENTER and SDL\_WINDOWEVENT\_LEAVE. Which in theory, according to the Wiki docs, should provide what I’m looking for. But with a simple test program, I get mouse enter/leave events _every single time I move the cursor_. It just spams the window with output when I move the mouse. This is on MacOS X. Is this a bug on this platform?

Can anyone test these events on Windows, and see if they work as expected? (i.e. only a single event when the mouse moves outside the window, and a single event when it comes back inside.)

void MyHandleSDLEvent(SDL\_Event \* event, int \*done)  
{  
switch (event-\>type)  
{

```
	case SDL_WINDOWEVENT:
	switch (event->window.event) 
	{
		case SDL_WINDOWEVENT_CLOSE:
			*done = 1;
			break;
			
		case SDL_WINDOWEVENT_ENTER:
			printf("Mouse entered our window! windowID = %d \n", event->window.windowID);
			break;
		
		case SDL_WINDOWEVENT_LEAVE:
			printf("Mouuse left the window! windowID = %d \n", event->window.windowID);
			break;

	}
	break;

```

[SNIP]

-Vern
