# \[PATCH\] More than 3 mouse buttons in MacOS X

**URL:** <https://discourse.libsdl.org/t/patch-more-than-3-mouse-buttons-in-macos-x/8801>\
**Category:** SDL Development\
**Created:** [May 25, 2003, 2:06am UTC](https://discourse.libsdl.org/t/patch-more-than-3-mouse-buttons-in-macos-x/8801 "2003-05-25T02:06:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [May 25, 2003, 2:06am UTC](https://discourse.libsdl.org/t/patch-more-than-3-mouse-buttons-in-macos-x/8801/1 "2003-05-25T02:06:03Z")

</div>

Without this patch, SDL recognizes the left and right mouse buttons, but  
every other button is considered the “middle” button.

Here is a patch to fix that. It does some tapdancing to convert between  
Cocoa’s button numbers and SDL’s, respecting that SDL reserves button 4  
and 5 for the mousewheel. So on this MS Intellimouse Explorer device, the  
buttons are reported through SDL as:

Left: button #1 (SDL\_BUTTON\_LEFT)  
Wheel button: button #2 (SDL\_BUTTON\_MIDDLE)  
Right: button #3 (SDL\_BUTTON\_RIGHT)  
Wheelup: button #4 (SDL\_BUTTON\_WHEELUP)  
Wheeldown: button #5 (SDL\_BUTTON\_WHEELDOWN)  
Lower thumb: button #6  
Upper thumb: button #7

Attached in unified diff format. If there aren’t objections, I’ll commit  
this to CVS.

–ryan.

-------------- next part --------------  
Index: src/video/quartz/SDL\_QuartzEvents.m===================================================================  
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/quartz/SDL\_QuartzEvents.m,v  
retrieving revision 1.22  
diff -u -r1.22 SDL\_QuartzEvents.m  
— src/video/quartz/SDL\_QuartzEvents.m 22 May 2003 06:28:40 -0000 1.22  
+++ src/video/quartz/SDL\_QuartzEvents.m 25 May 2003 08:55:44 -0000  
@@ -378,6 +378,25 @@  
CFRelease (rls);  
}

- 

+// Try to map Quartz mouse buttons to SDL’s lingo…  
+static int QZ\_OtherMouseButtonToSDL(int button)  
+{

- switch (button)
- {
- 

```
   case 0:

```

- 

```
       return(SDL_BUTTON_LEFT); // 1

```

- 

```
   case 1:

```

- 

```
       return(SDL_BUTTON_RIGHT); // 3

```

- 

```
   case 2:

```

- 

```
       return(SDL_BUTTON_MIDDLE); // 2

```

- }
- 
- // \>= 3: skip 4 & 5, since those are the SDL mousewheel buttons.
- return(button + 3);  
+}
- 
- 

static void QZ\_PumpEvents (\_THIS)  
{  
int firstMouseEvent;  
@@ -420,6 +439,7 @@  
inMode: NSDefaultRunLoopMode dequeue:YES ];  
if (event != nil) {

- 

```
       int button;
       unsigned int type;
       BOOL isForGameWin;
       BOOL isInGameWin;

```

@@ -466,8 +486,7 @@  
}  
}  
break;

- 

```
           case NSOtherMouseDown: DO_MOUSE_DOWN (SDL_BUTTON_MIDDLE); break;

```

- 

```
           case NSRightMouseDown: DO_MOUSE_DOWN (SDL_BUTTON_RIGHT); break;

```

- 

```
           case NSLeftMouseUp:
               if ( last_virtual_button != 0 ) {
                   DO_MOUSE_UP (last_virtual_button);

```

@@ -477,8 +496,19 @@  
DO\_MOUSE\_UP (SDL\_BUTTON\_LEFT);  
}  
break;

- 

```
           case NSOtherMouseUp: DO_MOUSE_UP (SDL_BUTTON_MIDDLE); break;

```

- 

```
           case NSRightMouseUp: DO_MOUSE_UP (SDL_BUTTON_RIGHT); break;

```

- 
- 

```
           case NSOtherMouseDown:

```

- 

```
           case NSRightMouseDown:

```

- 

```
               button = QZ_OtherMouseButtonToSDL([event buttonNumber]);

```

- 

```
               DO_MOUSE_DOWN (button);

```

- 

```
               break;

```

- 
- 

```
           case NSOtherMouseUp:

```

- 

```
           case NSRightMouseUp:

```

- 

```
               button = QZ_OtherMouseButtonToSDL([event buttonNumber]);

```

- 

```
               DO_MOUSE_UP (button);

```

- 

```
               break;

```

- 

```
           case NSSystemDefined:
               /*
                   Future: up to 32 "mouse" buttons can be handled.
```

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [May 26, 2003, 1:08pm UTC](https://discourse.libsdl.org/t/patch-more-than-3-mouse-buttons-in-macos-x/8801/2 "2003-05-26T13:08:01Z")

</div>

> Attached in unified diff format. If there aren’t objections, I’ll commit  
> this to CVS.

Sounds good, thanks! 🙂

See ya,  
-Sam Lantinga, Software Engineer, Blizzard Entertainment
