Hi Tom,
the best way to do this would be to (ab)use KbQueues, which can record mouse axis motion, and sometimes as a 3rd axis also mouse wheel motion. This should work on Linux and Windows, but not macOS.
See MouseMotionRecordingDemo.m for a starter:
http://psychtoolbox.org/docs/MouseMotionRecordingDemo
-mario