Last active
August 29, 2015 14:06
-
-
Save elpsk/638f086bf42049a2137d to your computer and use it in GitHub Desktop.
Returns a list of mouse coordinate for moving and/or clicking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// APAppDelegate.m | |
// TestMouse | |
// | |
// Created by alberto pasca on 04/09/14. | |
// Copyright (c) 2014 albertopasca.it. All rights reserved. | |
// | |
#import "APAppDelegate.h" | |
CGEventRef mouseCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) | |
{ | |
CGPoint location = CGEventGetLocation(event); | |
NSLog(@"location: (%f, %f) - %@\n", location.x, location.y, type == kCGEventMouseMoved ? @"move" : @"tap"); | |
return event; | |
} | |
@implementation APAppDelegate | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
CFMachPortRef mouseEvent; | |
CGEventMask eventMask; | |
CFRunLoopSourceRef runLoopSource; | |
eventMask = (1 << kCGEventMouseMoved) | (1 << kCGEventLeftMouseDown); | |
mouseEvent = CGEventTapCreate(kCGSessionEventTap, kCGTailAppendEventTap, 0, eventMask, mouseCGEventCallback, NULL); | |
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, mouseEvent, 0); | |
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); | |
CGEventTapEnable(mouseEvent, true); | |
CFRunLoopRun(); | |
} | |
@end | |
/* | |
2014-09-04 00:15:46.084 TestLock[717:303] location: (115.722656, 277.917969) - move | |
2014-09-04 00:15:46.116 TestLock[717:303] location: (115.722656, 277.222656) - move | |
2014-09-04 00:15:46.268 TestLock[717:303] location: (115.722656, 278.222656) - move | |
2014-09-04 00:15:46.812 TestLock[717:303] location: (115.722656, 278.222656) - tap | |
2014-09-04 00:15:47.060 TestLock[717:303] location: (115.722656, 278.222656) - tap | |
2014-09-04 00:15:47.299 TestLock[717:303] location: (115.722656, 278.222656) - tap | |
2014-09-04 00:15:49.861 TestLock[717:303] location: (249.425781, 731.292969) - move | |
2014-09-04 00:15:49.879 TestLock[717:303] location: (254.632812, 719.832031) - move | |
2014-09-04 00:15:49.896 TestLock[717:303] location: (262.968750, 702.121094) - move | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment