From 27726c5b014fe6d489b12da98f6cdc33d4932835 Mon Sep 17 00:00:00 2001 From: Sean Blackburn Date: Sun, 22 Feb 2015 14:14:29 +0100 Subject: [PATCH] We can now capture keypress events again, if we have accessibility enabled in the system preferences for the app --- .gitignore | 3 +++ .../contents.xcworkspacedata | 7 +++++++ CocoaActivityCounter/DBAppDelegate.m | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 CocoaActivityCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68904c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.Trashes +xcuserdata \ No newline at end of file diff --git a/CocoaActivityCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/CocoaActivityCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..5352419 --- /dev/null +++ b/CocoaActivityCounter.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/CocoaActivityCounter/DBAppDelegate.m b/CocoaActivityCounter/DBAppDelegate.m index 436a8de..e3ed59f 100644 --- a/CocoaActivityCounter/DBAppDelegate.m +++ b/CocoaActivityCounter/DBAppDelegate.m @@ -37,7 +37,7 @@ - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theAppl return YES; } --(void)logMessageToLogView:(NSString*)message { +- (void)logMessageToLogView:(NSString*)message { [logView setString: [[logView string] stringByAppendingFormat:@"%@: %@\n", [self.logDateFormatter stringFromDate:[NSDate date]], message]]; } @@ -56,6 +56,15 @@ - (IBAction)startButtonPressed:(id)sender { if (self.loggingEnabled) { return; } + + + if (checkAccessibility()) { + [self logMessageToLogView:@"Accessibility Enabled"]; + } + else { + [self logMessageToLogView:@"Accessibility Disabled"]; + } + self.loggingEnabled = true; monitorLeftMouseDown = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask handler:^(NSEvent *evt) { [self logMessageToLogView:[NSString stringWithFormat:@"Left mouse down!"]]; @@ -91,4 +100,11 @@ - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem { return YES; } + +BOOL checkAccessibility() +{ + NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES}; + return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts); +} + @end