title: How to trick an OS X app into thinking the mouse is a finger?
body: <p>I'm writing a Mac app that contains a collection view. This app is to be run on a large touchscreen display (<a href="http://www.planar.com/products/large-format-displays/ep/" rel="noreferrer">55" EP series</a> from Planar). Due to hardware limitation, the touchscreen doesn't send scroll events (or even any multitouch events). <strong>How can I go about tricking the app into thinking a "mousedown+drag" is the same as a "mousescroll"?</strong></p>
  
  <p>I got it working halfway by subclassing NSCollectionView and implementing my own NSPanGestureRecognizer handler in it. Unfortunately the result is clunky and doesn't have the feeling of a normal OS X scroll (i.e., the velocity effect at the end of a scroll, or scroll bounce at the ends of the content).</p>
  
  <pre><code>@implementation UCTouchScrollCollectionView
  ...
  - (IBAction)showGestureForScrollGestureRecognizer:(NSPanGestureRecognizer *)recognizer
  {
      CGPoint location = [recognizer locationInView:self];
  
      if (recognizer.state == NSGestureRecognizerStateBegan) {
  
          touchStartPt = location;
          startOrigin = [(NSClipView*)[self superview] documentVisibleRect].origin;
  
      } else if (recognizer.state == NSGestureRecognizerStateEnded) {
  
          /* Some notes here about a future feature: the Scroll Bounce
             I don't want to have to reinvent the wheel here, but it
             appears I already am. Crud.
  
             1. when the touch ends, get the velocity in view
             2. Using the velocity and a constant "deceleration" factor, you can determine
                 a. The time taken to decelerate to 0 velocity
                 b. the distance travelled in that time
             3. If the final scroll point is out of bounds, update it.
             4. set up an animation block to scroll the document to that point. Make sure it uses the proper easing to feel "natural".
             5. make sure you retain a pointer or something to that animation so that a touch DURING the animation will cancel it (is this even possible?)
          */
  
          [self.scrollDelegate.pointSmoother clearPoints];
          refreshDelegateTriggered = NO;
  
      } else  if (recognizer.state == NSGestureRecognizerStateChanged) {
  
          CGFloat dx = 0;
          CGFloat dy = (startOrigin.y - self.scrollDelegate.scrollScaling * (location.y - touchStartPt.y));
          NSPoint scrollPt = NSMakePoint(dx, dy);
  
          [self.scrollDelegate.pointSmoother addPoint:scrollPt];
          NSPoint smoothedPoint = [self.scrollDelegate.pointSmoother getSmoothedPoint];
          [self scrollPoint:smoothedPoint];
  
          CGFloat end = self.frame.size.height - self.superview.frame.size.height;
          CGFloat threshold = self.superview.frame.size.height * kUCPullToRefreshScreenFactor;
          if (smoothedPoint.y + threshold &gt;= end &amp;&amp;
              !refreshDelegateTriggered) {
              NSLog(@"trigger pull to refresh");
              refreshDelegateTriggered = YES;
              [self.refreshDelegate scrollViewReachedBottom:self];
          }
      }
  }
  </code></pre>
  
  <p>A note about this implementation: I put together <code>scrollScaling</code> and <code>pointSmoother</code> to try and improve the scroll UX. The touchscreen I'm using is IR-based and gets very jittery (especially when the sun is out).</p>
  
  <p>In case it's relevant: I'm using Xcode 6 beta 6 (6A280e) on Yosemite beta (14A329r), and my build target is 10.10.</p>
  
  <p>Thanks!</p>