Posts

Post not yet marked as solved
6 Replies
8.8k Views
I always find it instructive to start from the commandline. When I subsequently migrate to IDE, my feet are on the ground.I've been trying with a basic "hello world" style Swift snippet: the challenge is to draw a window on the screen without using Xcode.Now Swift has a compiler and an interpreter. So the challenge bifurcates -- to get it running on each.Could someone provide a set of instructions for each, together with an explanation of what's going on?π
Posted
by p-i-.
Last updated
.
Post marked as solved
4 Replies
1.6k Views
I am experiencing frustration.I have posted a couple of times on the Swift forum.Every now and again I go back to the forum to see whether there is any new related activity. But the forum receives over a page of posts in a day, so it quickly becomes awkward to find my original posts.Is there some way I can list my posts chronologically? And maybe even see whether any of them has received new activity?On Stack Overflow I just click on my username and can instantly view all of my posts. It makes it extremely easy to subsequently retrieve information -- even a year later!π
Posted
by p-i-.
Last updated
.
Post not yet marked as solved
1 Replies
518 Views
I am developing an assistive MacOS app in XCode / ObjC.It intercepts keystrokes using event-taps.When I run it from Xcode, I get: 2019-07-05 06:20:32.423783+0300 mapper[8108:1191874] unable to create event tap. must run as root or add privileges for assistive devices to this app. 2019-07-05 06:20:32.423809+0300 mapper[8108:1191874] No Event tap in place! You will need to call listen after tapEvents to get events.I have to go to: System Preferences -> security & privacy -> privacy -> {unlock the padlock putting my admin password} -> "Allow the apps below to control your computer" -> {locate, uncheck and recheck my executable from the list}Every time I modify a line of code and run again I have to go through this process of checking and unchecking.It is a very clumsy development cycle.Is there any way to avoid this?https://stackoverflow.com/questions/56896203/automatically-allow-app-built-run-by-xcode-to-control-your-computer
Posted
by p-i-.
Last updated
.
Post not yet marked as solved
0 Replies
414 Views
I'm attempting to remap my LeftMouse to CTRL using: CGPoint mouseFlip( CGPoint pt ) { return CGPointMake(pt.x, [NSScreen mainScreen].frame.size.height - pt.y); } _eventTap = CGEventTapCreate( kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, CGEventMaskBit(NSEventTypeMouseMoved) | CGEventMaskBit(NSEventTypeFlagsChanged), (CGEventTapCallBack)_tapCallback, (__bridge void *)(self) ); : CGEventRef _tapCallback( CGEventTapProxy proxy, CGEventType type, CGEventRef event, Intercept* listener ) { //Do not make the NSEvent here. //NSEvent will throw an exception if we try to make an event from the tap timout type @autoreleasepool { if( type == kCGEventTapDisabledByTimeout ) { NSLog(@"event tap has timed out, re-enabling tap"); [listener tapEvents]; return nil; } if( type != kCGEventTapDisabledByUserInput ) { return [listener processEvent:event]; } } return event; }- (CGEventRef)processEvent:(CGEventRef)cgEvent{ NSEvent* event = [NSEvent eventWithCGEvent:cgEvent]; switch( event.type ) { case NSEventTypeMouseMoved: CGPoint prev_mouse = [NSEvent mouseLocation]; int64_t dx = CGEventGetIntegerValueField(cgEvent, kCGMouseEventDeltaX); int64_t dy = CGEventGetIntegerValueField(cgEvent, kCGMouseEventDeltaY); CGPoint new_mouse = { prev_mouse.x + dx, prev_mouse.y - dy }; : /* awkward multi-screen bounds checking here */ : CGEventRef dragEvent = CGEventCreateMouseEvent( NULL, kCGEventLeftMouseDragged, mouseFlip(new_mouse), 0 ); CGEventPost(kCGHIDEventTap, dragEvent); CFRelease(dragEvent); break; :For the most part this works. However often I notice the mouse slips/glides, like walking on ice. There is some subtle deterioration in performance.Would anyone be willing to critique this approach?I wonder if there is some subtle round-to-int issue in dx,dy. Or if events are getting lost somehow.Maybe it's not safe to get `prev_mouse` from `[NSEvent mouseLocation]`?It's kind of annoying that I can't get the CURRENT mouse location. I'm guessing `[NSEvent mouseLocation]` only get updated AFTER the `NSEventTypeMouseMoved` event completes. If I could only access the new current location, I could dispense with the /* awkward multi-screen bounds checking here */.An alternative approach would be a periodic timer that does:```timer = [NSTimer scheduledTimerWithTimeInterval: .01f repeats: YES block: ^(NSTimer *timer) { if( ! self->ctrl_is_down ) return; CGEventRef dragEvent = CGEventCreateMouseEvent( NULL, kCGEventLeftMouseDragged, mouseFlip( [NSEvent mouseLocation] ), 0 ); CGEventPost(kCGHIDEventTap, dragEvent); CFRelease(dragEvent); }];```Can this approach be refined into something usable?What's the right way to do this?
Posted
by p-i-.
Last updated
.