Skip to content

Allow middle mouse button mapping without modifier keys#817

Merged
Caldis merged 1 commit intoCaldis:masterfrom
GonzFC:fix/allow-middle-button-without-modifiers
Dec 18, 2025
Merged

Allow middle mouse button mapping without modifier keys#817
Caldis merged 1 commit intoCaldis:masterfrom
GonzFC:fix/allow-middle-button-without-modifiers

Conversation

@GonzFC
Copy link
Copy Markdown
Contributor

@GonzFC GonzFC commented Dec 6, 2025

Problem

Currently, the middle mouse button (button 2) cannot be mapped to shortcuts without holding modifier keys (Cmd, Ctrl, Option, Shift). When users try to record the middle button alone, the UI shows an orange shake and rejects the input.

This happens because button 2 is classified as a "main key" in KeyCode.mouseMainKeys alongside left (0) and right (1) clicks, and the validation in CGEvent+Extensions.swift requires modifier keys for all main keys.

Solution

Remove button 2 from the mouseMainKeys array, allowing users to map their middle mouse button without holding modifiers, while still protecting left and right clicks from accidental remapping.

Changed:

// Before
static let mouseMainKeys: [UInt16] = [0,1,2]

// After  
static let mouseMainKeys: [UInt16] = [0,1]  // Only protect left/right clicks, allow middle button without modifiers

Use Case

Mapping the middle mouse button to Mission Control (or App Exposé, Show Desktop, etc.) is a very common mouse customization pattern. This is a primary use case mentioned in issue #695 and is supported by other mouse customization tools.

Testing

  • ✅ Middle button can now be recorded without modifiers
  • ✅ Successfully maps to Mission Control and other shortcuts
  • ✅ Left and right clicks still require modifiers (protected)
  • ✅ Other mouse buttons (3+) work as before

Related Issues

🤖 Generated with Claude Code

Previously, the middle mouse button (button 2) was classified as a
"main key" alongside left and right clicks, requiring modifier keys
(Cmd, Ctrl, etc.) to be held during button mapping. This restriction
made it impossible to map the middle button alone to actions like
Mission Control.

This change removes button 2 from the mouseMainKeys array, allowing
users to map their middle mouse button without holding modifiers,
while still protecting left (0) and right (1) clicks from accidental
remapping.

Fixes user workflow where middle button + Mission Control is a common
and expected mouse customization pattern.
@Caldis
Copy link
Copy Markdown
Owner

Caldis commented Dec 18, 2025

thanks @GonzFC, I initially set Buttons 1, 2, 3 as mainKeys to prevent users from accidentally binding them and losing their mouse controlls 😂 but it seems that using the middle button for binding operations is also acceptable.

@Caldis Caldis merged commit 2459435 into Caldis:master Dec 18, 2025
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.

2 participants