Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/dfmoore/ on line 14
Notes: Posting Mouse Events



Posting Mouse Events

Feb 28, 11:07 AM

No idea how fast it is, but I’m going to try it with my touch table tomorrow.


// altermouse.c
// Complile using the following command line:
// gcc -Wall -o altermouse altermouse.c -framework ApplicationServices


static CGRect screenBounds;

// This callback will be invoked every time the mouse moves.
myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{ // Do some sanity check. if (type != kCGEventMouseMoved) return event;

// The incoming mouse position. CGPoint location = CGEventGetLocation(event); // We can change aspects of the mouse event. // For example, we can use CGEventSetLoction(event, newLocation). // Here, we just print the location. printf(”(%f, %f)\n”, location.x, location.y); // We must return the event for it to be useful. return event; }

{ CFMachPortRef eventTap; CGEventMask eventMask; CFRunLoopSourceRef runLoopSource;

// The screen size of the primary display. screenBounds = CGDisplayBounds(CGMainDisplayID()); printf(“The main screen is %dx%d\n”, (int)screenBounds.size.width, (int)screenBounds.size.height); // Create an event tap. We are interested in mouse movements. eventMask = (1 << kCGEventMouseMoved); eventTap = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, myCGEventCallback, NULL); if (!eventTap) { fprintf(stderr, “failed to create event tap\n”); exit(1); } // Create a run loop source. runLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, eventTap, 0); // Add to the current run loop. CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); // Enable the event tap. CGEventTapEnable(eventTap, true); // Set it all running. CFRunLoopRun(); // In a real program, one would have arranged for cleaning up. exit(0); }