MacBookでマウスカーソルがループするアプリを製作(ソース)
1ファイルです(苦笑)。Apple社が、がんばってくれています(苦笑)
/* * LoopCursor_mini.c * * Created by NF on 2006/12/16. */ #include/* handler for MouseMoved event. for MacOS X 10.2 and later */ static OSStatus MouseMovedHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon ) { HIPoint ScreenMax; // MainScreen's bottom-right Position HIPoint MouseLocation, MouseDelta; // get ScreenMax CGRect mainscreen = CGDisplayBounds(CGMainDisplayID()); ScreenMax = CGPointMake(mainscreen.size.width -1, mainscreen.size.height -1); // get MouseLocation GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &MouseLocation); // Nothing is done. if( (MouseLocation.x == 0 && MouseLocation.y == 0 ) || (MouseLocation.x == 0 && MouseLocation.y == ScreenMax.y ) || (MouseLocation.x == ScreenMax.x && MouseLocation.y == 0 ) || (MouseLocation.x == ScreenMax.x && MouseLocation.y == ScreenMax.y ) || (MouseLocation.x > 0 && MouseLocation.x < ScreenMax.x) ) { return noErr; } // get MouseDelta GetEventParameter(inEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(HIPoint), NULL, &MouseDelta); // Set MouseLocation.x if ( MouseLocation.x == 0){ // left edge MouseLocation.x = ScreenMax.x + MouseDelta.x; }else if(MouseLocation.x == ScreenMax.x ){ // right edge MouseLocation.x = MouseDelta.x; } // Set MouseLocation.y if ( atan2(fabs(MouseDelta.y),fabs(MouseDelta.x)) > 0.388 ){ // IncidenceAngle is larger than 70 degrees MouseLocation.y = ScreenMax.y - MouseLocation.y; } // move MouseCursor Position CGWarpMouseCursorPosition(MouseLocation); return noErr; } /* main function. for MacOS X 10.3 and later */ int main (int argc, const char * argv) { // install Handler for kEventMouseMoved event EventTypeSpec kEvent={ {kEventClassMouse, kEventMouseMoved}, {kEventClassMouse, kEventMouseMoved} }; InstallEventHandler(GetEventMonitorTarget(), MouseMovedHandler, GetEventTypeCount(kEvent), kEvent, 0, NULL); // run EventLoop RunApplicationEventLoop(); return 0; }