Simulated MouseEvent not working properly OSX

In 2010, Pierre asked this question (his accepted answer does not work for me).

I have the same problem: I can successfully move the mouse (and turn off!?!) On the screen programmatically from my Cocoa application, however moving the mouse to the location of my dock does not show it (and some other applications do not register the mouse move event, for example, games that remove the mouse)

Method used:

void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point) { CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button); CGEventSetType(theEvent, type); CGEventPost(kCGSessionEventTap, theEvent); CFRelease(theEvent); } 

And then when I want to move the mouse, I run:

 PostMouseEvent(0, kCGEventMouseMoved, mouseLocation); 

Note that this code generates mouseover events for things like links.

Now that in 2013, is it possible to fix this problem?

Thank you for your time!

+6
source share
2 answers

OK, so obviously MacOSX needs the mouse to be exactly on the edge of the screen for the dock. Since I keep my docking station on the left side of the screen (due to the fact that many programs save vital buttons at the bottom of their windows), all I had to do was say

 if (mouseLocation.x < 0) { mouseLocation.x = 0; } 

And it worked!

I also use the KenThomases idea to warp the cursor.

(This answer is marked as correct, as it allows me to show the docking station - however, there are still some applications that do not respond to mouse input)

0
source

I would distort the cursor and generate a mouse move event. I know from experience, for example, that warping the cursor while it does not generate the event itself changes the subsequent mouse move event to include the moved distance in the mouse delta. I don't know if your synthesized move event will include the correct delta values ​​on its own.

+3
source

All Articles