2

This might be kind of a strange question, but how does the software for a mouse work? (specifically on OSX)

If I want to move the mouse around on OSX, I've been using this code:

CGAssociateMouseAndMouseCursorPosition(0); CGWarpMouseCursorPosition(point); // point is of type NSPoint CGAssociateMouseAndMouseCursorPosition (1); 

But this causes the cursor to jump (and even lag occasionally). How does a mouse (or trackpad) make it so fluid? What APIs do they use?

Likewise, if I use this code to move the cursor over the dock, for example, the dock doesn't magnify (magnification is turned on), even though moving the cursor there normally using the trackpad works just fine. Why?

2
  • Do you want to simulate user mouse movements (with all effects on the UI this might trigger) or do you want to know how the OS actually tracks, handles and dispatches mouse events? Commented Jan 11, 2013 at 5:45
  • @Thilo I'd like to simulate it, but as you said, with all the UI effects and changes it triggers, as the code I posted above simulates it, but only works sometimes and doesn't trigger all the UI changes. Commented Jan 11, 2013 at 6:01

1 Answer 1

3

Your question should really be "How does a mouse device driver work?"

You should take a look at IOKit, especially the HID family.

If you just want to simulate a mouse movement, you could also try creating a mouse event with CGEventCreateMouseEvent, then posting it with CGEventPost.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.