Utility to identify what mouse buttons are being pressed?

Is there a utility for mac to show what mouse buttons are being pressed?

Similar utilities for Windows are: Spy++ and WindowSpy from AutoHotKey.

For Linux I have used: xinput --query-state


Solution 1:

Hammerspoon can be scripted to do this.

  • Install Hammerspoon and run it.
  • Open System Preferences, go to Security & Privacy and enable Hammerspoon.app under Accessibility.
  • Click the Hammerspoon menu icon and select Open Config. Your default code/text editor will open to ~/.hammerspoon/init.lua.
  • Enter something like the following text which uses the Hammerspoon hs.eventtap.new API to listen for events.
detectMouseDown = hs.eventtap.new({ 
  hs.eventtap.event.types.otherMouseDown,
  hs.eventtap.event.types.leftMouseDown,
  hs.eventtap.event.types.rightMouseDown
}, function(e)
  local button = e:getProperty(
      hs.eventtap.event.properties['mouseEventButtonNumber']
  )
  print(string.format("Clicked Mouse Button: %i", button))
end)

detectMouseDown:start()

  • Save the file.
  • Click the Hammerspoon menu icon, select Console... and click Reload config on the console window.
  • Now, whenever you click anywhere you'll see a log entry in the Hammerspoon Console!

(So far, this works for any type of touchpad click/tap or external mouse click.)

Solution 2:

Karabiner-EventViewer is another option that can log the information you are looking for. Although it comes as part of Karabiner-Elements you can use it independently to monitor keystrokes and mouse button presses.

You can examine keyboard and mouse events by using EventViewer. Launch Karabiner-EventViewer from Launchpad.

Input events will be shown when you type keyboard on EventViewer or press pointing buttons on Mouse Area.

--source Karabiner-EventViewer manual

In practice I find it logs keys and clicks made any where whilst it is running.

screenshot of the Karabiner-Event viewer interface